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 having a problem for displaying a single quad, here is how i do :

enter image description here

//note: this code is only for 2 triangles, while on picture there is 4 triangles
float tex_coord[] =
{
   0.0, 0.0, //3
   0.0, 1.0, //2
   1.0, 1.0, //0
   1.0, 1.0, //0
   1.0, 0.0, //1
   0.0, 0.0  //3
}; 

int indexes[] = 
{
    3, 2, 0, 0, 1, 3
}

 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 glEnableClientState(GL_VERTEX_ARRAY);
   glVertexPointer(3, GL_FLOAT, 0, vertexes);
   glTexCoordPointer(2, GL_FLOAT, 0, tex_coord);
   glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, indices);
 glDisableClientState(GL_VERTEX_ARRAY);
 glDisableClientState(GL_TEXTURE_COORD_ARRAY);

The result :

enter image description here

share|improve this question
    
Your first image has 4 triangles but the second one has only 2 –  msell Nov 10 '12 at 20:38
    
Yes you are right but problem is the same with 2 or 4. I updated picture. –  tigrou Nov 10 '12 at 20:47
add comment

1 Answer

up vote 2 down vote accepted

In your code you need 4 texture coords; one for each position in vertices.

tex_coord[2] & text_coord[3] are the same, even though they are for different vertices.

Change text_coord[2] to 1.0,0 ; should fix the problem.

share|improve this answer
    
I tried what you said and it worked! My mistake was to think i have to provide a pair of texture coords every time a vertex is used in a triangle, while I should only give one texture coord per vertex (no mater how much times the vertex is used ) –  tigrou Nov 11 '12 at 19:47
add comment

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.