Results 1 to 3 of 3

Thread: VBO code problems

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2002
    Location
    Nashville, TN
    Posts
    9

    VBO code problems

    Anyone see any errors in this very simple test VBO code? It looks correct to me, but I'm not seeing any evidence of drawing. My immediate mode code does draw however.

    Code :
    struct vert3d_struct
    {
    	GLfloat x;
    	GLfloat y;
    	GLfloat z;
    };
     
    typedef struct vert3d_struct vert3d;
     
     
    	vert3d *vertices;
    	GLushort *indices;
    	GLuint	vboBuffers[2];
     
    	vertices[0].x = -20.0;
    	vertices[0].y = -20.0;
    	vertices[0].z = 0;
     
    	vertices[1].x = 20.0;
    	vertices[1].y = -20.0;
    	vertices[1].z = 0;
     
    	vertices[2].x = 20.0;
    	vertices[2].y = 20.0;
    	vertices[2].z = 0;
     
    	vertices[3].x = -20.0;
    	vertices[3].y = 20.0;
    	vertices[3].z = 0;
     
     
    	verticesCount = 4;
     
    	indices[0]=0;
    	indices[1]=1;
    	indices[2]=2;
    	indices[3]=3;
     
    	vertices = (vert3d *) malloc ( 4 * (sizeof(vert3d)));
     
    	indices = (GLushort *) malloc( 4 * sizeof(GLushort) );
     
    	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboBuffers[0]); //vertex data
    	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vboBuffers[1]); //indicies
     
    	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4 * (sizeof(vert3d)), vertices, GL_STATIC_DRAW_ARB);
    	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 4 * sizeof(GLushort), indices, GL_STATIC_DRAW_ARB);
     
    	glEnableClientState(GL_VERTEX_ARRAY);
    		glColor3f(0.0, 0.0, 1.0);
    		glDrawElements(GL_QUADS, verticesCount, GL_UNSIGNED_SHORT, 0);
    	glDisableClientState(GL_VERTEX_ARRAY);

    Thanks for any thoughts.

  2. #2
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: VBO code problems

    I can't see you generating the buffers anywhere. Have these been allocated before?

    Also I always enable the vertex array before I set the Vertex Pointer. I can't see you doing the latter anywhere.. The Vertex Pointer is pretty crucial to any drawing!

    I always found this web page a useful resource when I was learning VBOs.

    http://www.songho.ca/opengl/gl_vbo.html

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2002
    Location
    Nashville, TN
    Posts
    9

    Re: VBO code problems


    I can't see you generating the buffers anywhere. Have these been allocated before?

    Also I always enable the vertex array before I set the Vertex Pointer. I can't see you doing the latter anywhere.. The Vertex Pointer is pretty crucial to any drawing!
    For the benefit of others, I'll have to embarrass myself and admit my mistakes:

    Yes, both of these things were done. They were simply omissions to my cut-and-paste.

    The problem actually turned out to be that as I rewrote things in an effort to get VBO's working, somehow I managed to move my buffer initialization function call to a point after the glBufferDataARB call. Thus, I was copying an empty array.

    That's not apparent from the code above though, because as I was cutting and pasting the code into the message board, I placed it in the correct order, but somehow still failed to see it in my original code.

    Anyhow, thanks for the help. Problem solved.

Similar Threads

  1. Compilation problems of trivial code on Windows 7
    By alihelmy in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-18-2012, 04:13 PM
  2. Problems with normalization code
    By _new_horizon in forum OpenGL: General
    Replies: 6
    Last Post: 05-30-2007, 01:44 AM
  3. Problems with the simplest code with opengl
    By tiregarfio in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-25-2006, 04:25 AM
  4. problems while compiling Vincent code
    By mssrihari in forum OpenGL ES
    Replies: 1
    Last Post: 05-04-2005, 07:08 PM
  5. Problems with code from 3D Exploration
    By Alload in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-16-2001, 06:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean