PDA

View Full Version : GL_TRIANGLE_STRIP texturing



mnfisher
11-03-2007, 01:05 AM
Hi,

I am new to opengl programming, and as an experiment wrote a simple "map" drawing program. Originally I used GL_QUADS and draw each map square with the same texture in turn to avoid multiple calls to glBindTexture.
However as an experiment I try to use a triangle strip (to draw a layer of the same texture). I can only get the first square to texture correctly - the second has a mirror of the texture


glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.1, 0.9); glVertex2i(0,200); //v0
glTexCoord2f(0.1, 0.1); glVertex2i(0, 0); //v1
glTexCoord2f(0.9, 0.9); glVertex2i(200,200); ///v2
glTexCoord2f(0.9, 0.1); glVertex2i(200,0); //v3
glTexCoord2f(0.9, 0.9); glVertex2i(400,200); //v4
glTexCoord2f(0.9, 0.1); glVertex2i(400, 0); //v5
glEnd();


So what is the correct way to texture a triangle (or quad) strip?


I am using Borland's Turbo C++(the new one), does any one know where I can download a copy of freeglut that is compatible?? I couldn't get coff2omf to work on the version I have..

Many thanks for any tips

Martin

Trenki
11-03-2007, 04:12 AM
I suggest you look into the OpenGL specification to see how vertices for triangle or quad strips are specified and then it will hopefully be clear to you what is going on.
For example in your source code you have 6 glVertex calls for a triangle strip which will result in 4 triangles to be drawn.

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]

mnfisher
11-03-2007, 11:26 AM
Hi,

Yes, four triangles (two squares) are drawn as intended. What I don't see is how to texture these squares using the same (square) texture - I can only get a mirror image of the first square in the second..
ie v2 has texcoords of (0.9, 0.9) for the first texture, but needs to have texcoords of (0.1,0.1) (or (0, 0) - my texture wasn't nice at the edges)

Martin

Trenki
11-04-2007, 03:11 AM
v2 hat texcoords of (0.9, 0.9) because you specify them to be so. If you need them to be different you clearly have to specify different texture coordinates! Also note that the first triangle will be composed of v0, v1, v2 while the second triangle will have vertices v2, v1, v3 and the third will have v2, v3, v4 (Read page 17 of the OpenGL 2.1 spec).

If one vertex needs different texture coords for the first square and second square, then there is no way to do this with a triangle strip unless you use degenerate triangles.

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]