0

I've got a problem with Vertex Buffer Object, it seems it doesn't work properly. It doesn't show anything on screen.

Here is my Code:

void gl::glRecti(int x,int y,int w,int h,glColor *color)
{
    GLuint vbo = 0;

    GLfloat verts[] = 
    {
        x,y,
        x,y + h,
        x + w,y + h,
        x + w,y,
    };

    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glEnableClientState(GL_VERTEX_ARRAY);

        glBindBuffer(GL_ARRAY_BUFFER,vbo);
            glVertexPointer( 4 , GL_FLOAT , sizeof(float) * 8, NULL );
            glDrawArrays(GL_QUADS,0,4);
        glBindBuffer(GL_ARRAY_BUFFER, 0);


    glDisableClientState(GL_VERTEX_ARRAY);

}

PS: I'm very new in OpenGL programming. Any help would be appreciated.

1 Answer 1

1

Your vertex pointer does not make sense:

glVertexPointer( 4 , GL_FLOAT , sizeof(float) * 8, NULL );

You are telling the GL that each vertex position is specified as a 4-dimensional vector, and that the offset between two consecutive vertices is 8 floats.

What you supply is a tighlty packed array of 2-dimensional positions, so you should use 2 as the size parameter, and 2*sizeof(float) for the stride (or 0, which is a shortcut for thigly packed arrays).

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot but the problem persist. you can see more errors?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.