Results 1 to 3 of 3

Thread: Learning VBOs

  1. #1

    Learning VBOs

    I am trying to learn VBOs and I have them sort of working but I wanted to get some clarification regarding glVertexPointers and glTexCoordPointers.

    Code :
    bool OGL_Renderer::drawImage(Image *image, int x, int y, float scale = 1.0f)
    		GLfloat vertices[8] = {
    			x, y,
    			x + image->getWidth(), y,
    			x + image->getWidth(), y + image->getHeight(),
    			x, y + image->getHeight()
    		GLfloat texture[8] = {
    			0.0f, 0.0f,
    			1.0f, 0.0f,
    			1.0f, 1.0f,
    			0.0f, 1.0f
    		glColor4ub(255, 255, 255, 255);
    		glBindBuffer(GL_ARRAY_BUFFER, mVertexBufferObject);
    		glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) + sizeof(texture), NULL, GL_STATIC_DRAW);
    		glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
    		glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(texture), texture);
    		glBindBuffer(GL_ARRAY_BUFFER, mVertexBufferObject);
    		glBindTexture(mTextureTarget, getTextureId(image));
    		glVertexPointer(2, GL_FLOAT, 0, vertices);
    		glTexCoordPointer(2, GL_FLOAT, 0, texture);
    		glDrawArrays(GL_QUADS, 0, 4);
    		glBindBuffer(GL_ARRAY_BUFFER, 0);
    		return true;
    	return false;

    The last parameter of both should be the arrays that the coords are stored into right? I seem to have some confusion in this area.

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015

    Re: Learning VBOs

    Code :
    		glVertexPointer(2, GL_FLOAT, 0, vertices);
    		glTexCoordPointer(2, GL_FLOAT, 0, texture);

    This makes no sense.

    When a buffer object is bound to GL_ARRAY_BUFFER, the "pointer" functions no longer refer to client memory (ie: actual pointers). They now refer to byte offsets into the buffer object bound to GL_ARRAY_BUFFER.

    The first byte of your buffer object stores your position data, so the byte offset should be 0. The same as how you uploaded it. The first byte where your texture coordinate data is is at "sizeof(vertices)". Again, just as how you uploaded it.

  3. #3

    Re: Learning VBOs

    Ahhhh that makes sense then. It should look like:
    Code :
    		glVertexPointer(2, GL_FLOAT, 0, 0);
    		glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*)(sizeof(vertices)));

    That is what threw me off then, the fact it isn't talking about client-side at that point.

Similar Threads

  1. Learning OpenGL
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-27-2004, 10:14 AM
  2. learning OpenGL???
    By vme09 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-27-2004, 08:31 AM
  3. Learning OpenGL
    By Amir in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-06-2003, 01:16 PM
  4. Learning OpenGL
    By bilalfaruk in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-02-2002, 02:51 AM
  5. learning
    By X-51Designer in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-10-2002, 05:21 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