How to apply texture to QUAD_STRIP in opengl?

Well, I'm trying to apply texture to 2 squares, but I can only apply to the first one.

I am using primitive QUAD__STRIP to draw squares. The code:  

glBegin(GL_QUAD_STRIP);
            glTexCoord2f(0.0,1.0);  glVertex3f(-1.0f * size, -1.0f* size, 0);    //1
            glTexCoord2f(0.0,0.0);  glVertex3f(-1.0f* size,  1.0f* size, 0);   //2
            glTexCoord2f(1.0,1.0);  glVertex3f(1.0f* size, -1.0f* size, 0);   //3
            glTexCoord2f(1.0,0.0);  glVertex3f(1.0f* size,  1.0f* size, 0);//4
                                    glVertex3f(3.0f* size,  -1.0f* size, 0);//5
                                    glVertex3f(3.0f* size,  1.0f* size, 0);//6


      

    glEnd();

      









+1


a source to share


2 answers


When you see this line of code:

glTexCoord2f(0.0,1.0);  glVertex3f(-1.0f * size, -1.0f* size, 0);    //1

      

the first statement glTexCoord2f () indicates which point in the texture is connected to the specified vertex (glVertex3f ()). For each vertex, you need to specify at which point in the texture it will be displayed.



You might find it helpful to look here: GameDev.NET - OpenGL Texture Mapping: An Introduction This is especially true for "Texture Coordinate Systems".

Hope this helps!

* edit, try http://nehe.gamedev.net/ ! lots of OpenGL tutorials / articles, tutorial. Lesson 6 has texture mapping in it. :) (Although not a very good example of good coding practice)

+2


a source


You are not setting texture coordinates for the last 2 vertices (5 and 6) in the second quadrant.



0


a source







All Articles