PDA

View Full Version : [OpenGL] Help me with texture mapping please.



wodzu
15-02-2011, 02:30 PM
Hello folks.

I wanted to ask you how to map texture onto triangle like in the provided image:

http://img546.imageshack.us/img546/3681/texturing.png (http://img546.imageshack.us/i/texturing.png/)

Uploaded with ImageShack.us (http://imageshack.us)

So, I have one triangle and two different textures which parts I would like to have mapped on the triangle. The problem is that I could not find example for this on the Web. (There is a lot of examples for quads and triangles but not in this specific case).

I don't know if it is possible to map the red texture with specifying 4 different points for mapping.
And I don't know if it is possible to map more than one texture onto triangle in a different part of that triangle.

Thanks for your time :)

Darthman
15-02-2011, 02:37 PM
Hi there.

You must need too set textures to CLAMP mode and enable 2 texture stages for 2 different textures.
Then you must just set UV for every vertex like this (clockwise from top):
1st texture:
0.5 0.0
1.5 1.0
0.5 1.0

2nd texture:
-0.5 0
0.5 1.0
-0.5 1.0

Something like that. Or you can try different way by deviding your triangle with 3. And put first texture into 2 triangles and a second ine on third triangle.

wodzu
15-02-2011, 02:47 PM
Hi there.

You must need too set textures to CLAMP mode and enable 2 texture stages for 2 different textures.
Then you must just set UV for every vertex like this (clockwise from top):
1st texture:
0.5 0.0
1.5 1.0
0.5 1.0



Thank you for answer:)

I guess you meant for the first texture those coordinates?

0.5 0.0
0.5 1.0
1.0 1.0

User137
15-02-2011, 03:42 PM
Red texture:
up vertex 0.5 0.0 0
down vertex 0.5 1.0
down right vertex 1.5 1.0

Thing is, you can't stop texture drawing midway of a triangle. Red part texture will show under that green one, and green will be drawn on top of whole of red. What prevents this is alpha channel of texture. (Only green texture in this case needs alpha if it is drawn after the red one)

Green texture coordinates:
up -0.5 0.0
down -0.5 1.0
down right 0.5 1.0

wodzu
15-02-2011, 04:37 PM
Thank you User123.

If I understand you correctly, both of the textures must be in GL_REPEAT mode, right?

User137
15-02-2011, 10:12 PM
GL_REPEAT is on by default, and ye that is the most useful one. If you try to draw with texture coordinates outside 0..1 (in this case you have coordinates to -0.5 and 1.5) then the rendering takes rules of what clamp is set to.

wodzu
16-02-2011, 07:20 AM
Thanks for your time :)