Texturing triangles

My scene has an object , which is made from lots triangles. How can i apply texture on object?

thanks!

1.) Load an image to use for a texture.
2.) Bind that texture.
3.) Give the vertices of your triangles tex coords when rendering.

For 1, you can find lots of info on how to do that by searching the forms. For 2 & 3, you can also find info from any good OpenGL source. (RedBook, Nehe’s Tutorials, etc.)

i have no problem with first 2. I binded that texture, and i got textures on each object’s triangle. Is it posible to apply one texture on multiple triangles?

If I understand you correctly, you want to have a texture spread across multiple triangles? This is easy if you make your texture co-ords correctly. For example, a single Quad made of two triangles will have the following texture co-ordinates for the first triangle:

0.0, 0.0
0.0, 1.0
1.0, 1.0

and the following for the second:

0.0, 0.0
1.0, 0.0
1.0, 1.0

thanks, but i think you don’t understood me corectly. Imagine you have cylinder. I wanna wrap all cylinder’s triangles with one texture. I dont want to see my cylinder, which is wraped with lots of textures on each triangle…

I think you’re not understanding Robbo. The technique he describes above is pretty much the same thing you would do for a cylinder.

For simplicity sake, let’s “unroll” the cylinder so that it is a rectangle. Also for simplicity sake, let’s also say that this rectangle is made up of 10 columns, and 4 rows.

Lower left vertice would have a texcoord of 0, 0. The next vertice to the right would have a tex coord of 0.1, 0. Next one 0.2, 0, and so on and so on… next row up to the far left would have the texcoords 0, 0.25. Then 0.1, 0.25, and so on and so on…

All that is done using a single texture, and each triangle will only use a portion of the texture because you gave them the appropriate texcoords.