Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to work out how to use this function glTexCoordPointer.

The man page states that I must set a pointer to the first element of the array that uses the texture cordinate.

Here is my array:

static const GLfloat GUIVertices[] = {

    1.0f,  1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
   -1.0f,  1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
   -1.0f, 0.94f, 0.0f, 1.0f, 0.0f, 1.0f,
    1.0f, 0.94f, 0.0f, 1.0f, 1.0f, 1.0f,  

    //2ND QUAD
    // x     y      z    w      X    Y
    1.0f,  -1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
   -1.0f,  -1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
   -1.0f, -0.94f, 0.0f, 1.0f, 0.0f, 1.0f,
    1.0f, -0.94f, 0.0f, 1.0f, 1.0f,  1.0,

But how do I set the pointer correctly for the fifth element on the 2nd quad first row? I was thinking something like this:

glTexCoordPointer(1, GL_FLOAT, 6, reinterpret_cast<const GLvoid *>(29 * sizeof(float)));

share|improve this question

The call you're looking for is

glTexCoordPointer(2, GL_FLOAT, sizeof(float)*6, (GLvoid*)(sizeof(float)*4));

The first argument is the number of elements that need to be read per element (vertex), and it's two because texture coordinates are just u and v coordinates. The second argument describes the type of data being passed. In this case, they're floats.

The third argument is the stride, which is the byte offset between consecutive texture coordinates. In this case, it's simply the size of one of your vertex-texcoord pairs (if I'm understanding the way you packed the data correctly). In other words, there are 6 floats between the start of two texture coordinates and the start of the next two.

Finally, the buffer offset specifies how far into the structure OpenGL must look before it finds the first values. You set it to 4 because you have to instruct OpenGL to skip the first 4 float it reads, as they are the vertex coordinates. Also note that this last pointer is casted to a GLvoid*.

Edit: If you want to point only to the texture coordinates of only the second quad, then use:

glTexCoordPointer(2, GL_FLOAT, sizeof(float)*6, (GLvoid*)(sizeof(float)*28));
share|improve this answer
I think, that he wants second quad. So last parameter should be .....*28)); – zacharmarz Mar 30 '12 at 17:03
@zacharmarz Thanks. Updated the answer accordingly. – ktodisco Mar 30 '12 at 17:09
From the looks of it he's also not using VBOs (but is further confused by the documentation relating to them) so you should probably change your answer to reflect this too (or at least add an "if you are not using VBOs" version). – Le Comte du Merde-fou Mar 30 '12 at 20:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.