mapping a rectangular map on a triangle

Started by
10 comments, last by Yel 21 years, 7 months ago
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
Advertisement
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
"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
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.
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
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.
Thx a lot everybody but I think I need another graphics card or whatever, since no solution seems to work with my setup
Yel
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 ?
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

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.
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
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

This topic is closed to new replies.

Advertisement