Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:12:24+00:00 2026-06-08T05:12:24+00:00

I spend almost whole day trying to render simple polygon using opengl 1.1 and

  • 0

I spend almost whole day trying to render simple polygon using opengl 1.1 and vertex buffers, but no luck. I searched and searched, but I haven’t found much.

This is what i have so far:

public class Polygon {

    int bufferId = 0;

    private FloatBuffer vertexBuffer;  // Buffer for vertex-array

    private float[] vertices = {  // Vertices for the square
            -1.0f, -1.0f, 0.0f,  // 0. left-bottom
            1.0f, -1.0f, 0.0f,  // 1. right-bottom
            -1.0f, 1.0f, 0.0f,  // 2. left-top
            1.0f, 1.0f, 0.0f   // 3. right-top
    };

    private ByteBuffer indexBuffer;

    private byte[] indices = {0, 1, 2, 3}; // Indices to above vertices (in CCW)


    // Constructor - Setup the vertex buffer
    public Polygon() {
        // Setup vertex array buffer. Vertices in float. A float has 4 bytes
        ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
        vbb.order(ByteOrder.nativeOrder()); // Use native byte order
        vertexBuffer = vbb.asFloatBuffer(); // Convert from byte to float
        vertexBuffer.put(vertices);         // Copy data into buffer
        vertexBuffer.position(0);           // Rewind


        indexBuffer = ByteBuffer.allocateDirect(indices.length);
        indexBuffer.put(indices);
        indexBuffer.position(0);


        int[] buffers = new int[1];
        GLES11.glGenBuffers(1, buffers, 0);
        bufferId = buffers[0];

        GLES11.glBindBuffer(GLES11.GL_ARRAY_BUFFER, bufferId);
        GLES11.glBufferData(GLES11.GL_ARRAY_BUFFER, vertices.length, vertexBuffer, GLES11.GL_STATIC_DRAW);
        GLES11.glBindBuffer(GLES11.GL_ARRAY_BUFFER, 0);
    }


    // Render the shape
    public void draw(GL10 gl) {

        GLES11.glBindBuffer(GLES11.GL_ARRAY_BUFFER, bufferId);

        GLES11.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        GLES11.glVertexPointer(3, GLES11.GL_FLOAT, 0, 0);
        GLES11.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length);
        GLES11.glDisableClientState(GL10.GL_VERTEX_ARRAY);

        GLES11.glBindBuffer(GLES11.GL_ARRAY_BUFFER, 0);
    }
}

It doesn’t render anything and there is no relevant error in android logcat.
I ommited rest of the code. The problem is obviously in this class, since it works fine when I change draw method to this:

public void draw(GL10 gl) {

            GLES11.glEnableClientState(GL10.GL_VERTEX_ARRAY);
            GLES11.glVertexPointer(3, GLES11.GL_FLOAT, 0, vertexBuffer);
            GLES11.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length);
            GLES11.glDisableClientState(GL10.GL_VERTEX_ARRAY);

        }

So, what am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:12:27+00:00Added an answer on June 8, 2026 at 5:12 am
    1. Don’t look in the logCat for errors, you want to check for OpenGL errors with glGetError(), and check that the return value is zero (no error), or nonzero (error).

    2. vertices.length is the wrong argument to glDrawArrays. You want to supply the number of vertices, not the number of floats. It should be vertices.length/3 (3 floats per vertex).
      You’re currently drawing way past your array into some garbage data, so I’m not sure what kind of consequences that could have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a fishy error when using glDrawElements(). I'm trying to render simple primitives
well I have been trying to get Nivo Slider to work almost all day.
About a month a go I spent almost an entire week trying to figure
I spend most of my time plotting data, but unfortunately I haven't found a
I spend most of my time in C# and am trying to figure out
I spend quite some hours banging my head against the wall trying to set
I feel like I spend a lot of time writing code in Python, but
We're currently using Salesforce for our sales process, which involve trying to get people
I would really appreciate some help. I spent almost the whole morning on it.
I have searched almost a month everyday for this. In some cases they use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.