Archived

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

Yel

mapping a rectangular map on a triangle

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.glBegin(GL_QUADS);

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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
www.google.com

Share this post


Link to post
Share on other sites
1D textures ? don''t you think you''ll lose 1 dimension ?

Instead I was thinking of 4D textures (in fact, 2D textures plus Q coordinate) but I''m having problems imagining what it could do since todays graphics card don''t interpolate correctly (errors like perspective non-correction, ugly!).

Share this post


Link to post
Share on other sites
One (ugly) solution I''m thinking of is simply pre-processing the texture.
You have to stretch the texture to fit into a triangle.
That is, for each line of the texture you have to stretch it so that the first line is stretched to 1 texel, and the last line is not stretched at all, and the other lines are stretched relatively to their height (that is, the lowest lines become really small and the last lines have almost their original size).

I don''t know if I''m clear enough. I can write a little scheme if you need.

Share this post


Link to post
Share on other sites