Jump to content
  • Advertisement
Sign in to follow this  
pescador

1st time VBO - Whats wrong?

This topic is 3217 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, This is my first VBO experiment, just for performance test. I have been working on this code a long time but I cannot find the problem (the QUADS don't appear). Maybe you (experient guys) could help me! So, here it goes:
...

GLuint vertex_vbo;
GLuint texcoord_vbo;

GLfloat vertex_array[] = {-1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0};
GLfloat texcoord_array[] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0};

PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;

...

//Init function

glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress("glGenBuffersARB");
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress("glBindBufferARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress("glBufferDataARB");

glGenBuffersARB(1, &texcoord_vbo);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, texcoord_vbo);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(texcoord_array), texcoord_array, GL_DYNAMIC_DRAW_ARB);
    
glGenBuffersARB(1, &vertex_vbo);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_vbo);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertex_array), vertex_array, GL_DYNAMIC_DRAW_ARB);

...

//Render function

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnable(GL_TEXTURE_2D);
    
        glPushMatrix();
            glTranslatef(-0.5, 0, 0);
            glScalef(0.3, 0.3, 0);
            glRotatef(angle, 0, 0, 1);
            
            glBindTexture(GL_TEXTURE_2D, texture1);
            
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, texcoord_vbo);
            glTexCoordPointer(2, GL_FLOAT, 0, texcoord_array);
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_vbo);
            glVertexPointer(2, GL_FLOAT, 0, vertex_array);
            glDrawArrays(GL_QUADS, 0, 4);
        glPopMatrix();
    
        glPushMatrix();
            glTranslatef(0.5, 0, 0);
            glScalef(0.3, 0.3, 0);
            glRotatef(angle, 0, 0, 1);
            
            glBindTexture(GL_TEXTURE_2D, texture2);

            glBindBufferARB(GL_ARRAY_BUFFER_ARB, texcoord_vbo);
            glTexCoordPointer(2, GL_FLOAT, 0, texcoord_array);
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_vbo);
            glVertexPointer(2, GL_FLOAT, 0, vertex_array);
            glDrawArrays(GL_QUADS, 0, 4);
        glPopMatrix();
    
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Thankyou in advance!

Share this post


Link to post
Share on other sites
Advertisement
If you have a VBO bound when you call gl*Pointer, the pointer value is used as an offset inside the VBO data, so normally this pointer is set to NULL as the data starts where the VBO starts.

So, what's wrong? Change the pointer used in glVertexPointer and glTexCoordPointer for a NULL pointer and it will work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!