Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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[] = {

    //FIRST QUAD
    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

1 Answer 1

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). –  Jimmy Shelter Mar 30 '12 at 20:21

Your Answer

 
discard

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.