#### Archived

This topic is now archived and is closed to further replies.

# mapping a rectangular map on a triangle

This topic is 5802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''d like to map a rectangular texture with parallel lines on a triangle in a way that the parallel lines meet in one corner of the triangle. is that possible and if yes how ?? any suggested will be very much appreciated ! Thanks Yel

##### Share on other sites
glTexCoord2f(0, 0);
glTexCoord2f(0.5, 1);
glTexCoord2f(0.5, 1);
glTexCoord2f(1, 1);

?

the parallel lines should now converge in the top corner. or did I misunderstand your question?

Crispy

##### Share on other sites
Crispy: I think you''re mapping a triangular map on a rectangle, which is the opposite of what Yel wants.

Yel: yes you can do it but that depends on you texture. in a particular case, you can do it in one triangle otherwise you have to split your geometry in multiple triangles to reduce the approximation error.

Otherwise you could render a degenrated quad, but it will not map the texture properly, not even on professional cards I think.

##### Share on other sites
vincoof !
thanks for your suggestion. Could you please tell which would be that particular case, and what is a degenerated quad ?

here is what I tried:

gl.glRotatef(this.angle, 0.0f, 0.0f, -8.0f);
gl.glBegin(GL_TRIANGLES);

gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex2f(-2.0f, 0.0f); //lower left

gl.glTexCoord2f(0.5f, 1.0f);
gl.glTexCoord2f(0.5f, 1.0f);
gl.glVertex2f(0.0f, 2.0f); // center up

gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex2f(2.0f, 0.0f); // lower right

gl.glEnd();

which obviously didn''t work

btw: as you can see I want to map a texture and not a map sorry for not being precise
Thx Yel

##### Share on other sites
The particular case is the case where you texture is 1 texel wide or 1 texel high only. That is, you can repeat seemlesly your texture in one direction without having to take care of any stretch factor. But I don''t think your case fits that.

A degenerated quad is a quad where two vertices join, so that it resembles to a triangle.

You could try that :
gl.glRotatef(this.angle, 0.0f, 0.0f, -8.0f);

gl.glTexCoord2f(0.0f, 0.0f); // lower left texel
gl.glVertex2f(-2.0f, 0.0f); //lower left vertex

gl.glTexCoord2f(0.0f, 1.0f); // upper left texel
gl.glVertex2f(0.0f, 2.0f); // center up vertex

gl.glTexCoord2f(1.0f, 1.0f); // upper right texel
gl.glVertex2f(0.0f, 2.0f); // center up vertex

gl.glTexCoord2f(1.0f, 0.0f); // lower right texel
gl.glVertex2f(2.0f, 0.0f); // lower right vertex

gl.glEnd();

The key vertices are the two middle ones.
But I don''t think it will give the results you want.
With an ideal OpenGL implementation it should work, but with current implementations, your graphics card will simply split your quad in two triangles ans so forth you won''t see any difference than if you simply rendered two separate triangles.

##### Share on other sites
Thx a lot everybody but I think I need another graphics card or whatever, since no solution seems to work with my setup
Yel

##### Share on other sites
Well I don''t mean you need another graphics card. First of all I''m not even sure that professional cards would correct this problems, and secondly that''s something you have to deal against OpenGL specifications anyway.

What is the purpose of this special mapping. Do you want to map two texture coordinates on two adjacent quad corners, and then map a single texture coordinate on the two other quad corners ?

##### Share on other sites
it''s very hard to tell you what I am trying to do. I think the closest comparison I found up to now would be visualizing a radar. In our problem we also have data that represent kind of a ray and they have to be mapped on the screen like a turning radar beam. It also has to be fast and accurate and like a radar also has lots of redundant information the closer you get to the centerr. I''m not sure if I made myself understood but it''s the closest I could get. (actually trying to put a texture on one line as described in my new post refers to the same problem, trying another solution !

THX Yel

##### Share on other sites
I think a good approwimation would be to split your triangle into several adjacent triangles, sharing the same vertex coordinate for the "center of the radar", but using a different texture coordinate every time for this center.

##### Share on other sites
possibly a 1d-tex could solve the problem.. but i don''t tell how, HEHE.. too difficult to type..:D

"take a look around" - limp bizkit

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002291
×