textures in tirangle_strip and triangle_fan

Started by
2 comments, last by naher 21 years, 6 months ago
i want to know if i can map a texture to a tiangle_strip or a triangle_fan at the same way that another poligon. in this case, what happend with the triangle_fan? all triangles, for example, take the (0,0) of the texture? thanks, and sorry for my english, i hope you can understand it // naher
Advertisement
Firstly: you don''t apply textures to triangle fans. Think of "triangle fan" as a method of drawing vertexes (check it out on the Web) - it is a special case of drawing vertices if you, for example, have the texture and vertice coordinates stored in an array. And no, the triangles aren''t applied with (0, 0) texture coordinate - you can use glTexCoordx to specify your own texture coordinates.

I''m sorry if I misunderstood your post,
hope this helps,
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
thanks, but let me try to explain better

for example with this code

glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0.5,0.0); glVertex3f( 0,0,1 );
glTexCoord2f(0.0,1.0); glVertex3f( 1,0,0 );
glTexCoord2f(0.25,1.0); glVertex3f( 0,1,0 );
glTexCoord2f(0.5,1.0); glVertex3f( -1,0,0 );
glTexCoord2f(0.75,1.0); glVertex3f( 0,-1,0 );
glTexCoord2f(1.0,1.0); glVertex3f( 1,0,0 );
glEnd();

we create four triangles:

( (0,0,1),(1,0,0),(0,1,0) )
( (0,0,1),(0,1,0),(-1,0,0) )
( (0,0,1),(-1,0,0),(0,-1,0) )
( (0,0,1),(0,-1,0),(1,0,0) )

and the point (0,0,1) always have the same coordinate in the texture. right?

do it can be bad for the resulting image?

but it doesnt care, i have another problem, if i have more than one texture, do i have to create the triangles individually? this case occur when the texture is biggest than 256 texels and i have to create various textures
this problems occur with quad_strips too, and i cant find another solution that make the poligons individually

do you understandme? do i am right?

thanks again

// naher
quote:and the point (0,0,1) always have the same coordinate in the texture. right?

Right


quote:do it can be bad for the resulting image?

Definately, no problem.


quote:but it doesnt care, i have another problem, if i have more than one texture, do i have to create the triangles individually?

If you have multiple texture, I roughly see 3 solutions :

1- render polygons separately, and bind a (different) texture for each (different) set of polygons. Say you want to render a house as four walls and a roof, do soimething like :

  glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, wall_texture);glBegin(GL_TRIANGLES);// call glVertex and glTexCoord for wall coordinatesglEnd();glBindTexture(GL_TEXTURE_2D, roof_texture);glBegin(GL_TRIANGLES);// call glVertex and glTexCoord for roof coordinatesglEnd();  

This method #1 is available since OpenGL1.1 (or OpenGL1.0 is you call glTexImage2D instead of glBindTexture !)
Advantage :
- you can use an unlimited number of textures
Disadvantage :
- if some polygons use more than one texture, you''re going to perform multipass which is not the fastest method (moreover it ''eats'' the blending functionality).

2- render all polygons in a single pass, with multitexturing. Say you want to render a wooden door with some painting on it, assuming that you have one texture for the wood and one texture for the painting, you can do something like :

  glActiveTexture(GL_TEXTURE0);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, wood_texture);glActiveTexture(GL_TEXTURE1);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, paint_texture);glBegin(GL_TRIANGLES);// call glVertex and glMultiTexCoord for door coordinatesglEnd();  

This method #2 is available since OpenGL1.3 (or OpenGL1.2.1 using GL_ARB_multitexture extension)
Advantage :
- Do it all in single pass, which is faster than multipass
Disadvantage :
- The number of texture is limited by your graphics card, usually you can count on two textures (from TNT2 to GeForce2) and better cards support 4 textures (GeForce3+) or 8 textures (latest Radeons).

3- build a custom texture based on the combination of all your textures. Say you want to render a human, assuming there is a different texture for the skin and for the clothes, you can *append* both textures into a single texture and then use *precise* texture coordinates, just like most Quake-like games do. If you don''t know what I''m talking about, go to www.polycount.com and download some models and look at what the textures look like.
This method #3 is available since OpenGL1.0.
Advantage :
- use a single texture, thus reduce the number of "texture swaps" (because each call to glBindTexture is pretty slow)
Disadvantages :
- the merged texture may be big because it combines lots of textures, and some OpenGL implementations either do not support big textures, or support them but with a big performance hit. Fortunately, most todays graphics card support without problem textures up to 512x512 (and GeForce2+ cards support up to the ridiculous size of 4096x4096)
- you may not repeat the texture (fortunately, it''s rarely annoying for rendering models like humans) unless you use a few tricks hanging around (each having their own limitations)

As you can see, every method has his own advantages and disadvantages, being performance or programming limitations. Use whatever you like depending on your application and depending on the targeted hardware.

This topic is closed to new replies.

Advertisement