Archived

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

Yel

adjusting the center of a texture

Recommended Posts

I''d like to map a texture on a rectangular shape (0,0 / 0,1 / 1,1 / 1,0) but I would like to move the center to the right, so that the texture is ''squeezed'' in that corner ? possible or not ? and how ? thanks a lot Yel

Share this post


Link to post
Share on other sites
afaik - you can''t partially map a texture to a surface - opengl automatically tiles the texture... can''t check righht now, so I could be wrong. If you wnat to sqeeze the texture in one corner, you''ll have to create another quad for the textured part...

hope this helps,
Crispy

Share this post


Link to post
Share on other sites
Please explain "squeeze".

If you shift your texture to the right, does that mean that the left part in transparent ? the left part is black ? the left part repeats the closest borders ?

and what happens to the right part ? does a part of it disappear ? do you want do stretch it near the border so that you have a ''cornered paper'' effect ?

Share this post


Link to post
Share on other sites
here''s what I would like to do :

given a texture let''s say 100 pixels high and 300 pixels wide and a quad with the same dimensions.

the texture should be placed on the quad in a way that # 150 of the texture lies on pixel 225 of the quad. the res of the texture should be stretched on the left and squeezed to the right so that #1 of texture matches #1 of quad and # 300 of texture matches # 300 of quad

does that make sense now ?

Thx Yel

Share this post


Link to post
Share on other sites
oh yes that makes sense. those very good explanations help alot. thanks !

obviously you can do it if you split your quad in several mini-quads and compute texture coordinates yourself.

unfortunately you can't *just* define one quad and let OpenGL interpolate for you because OpenGL only interpolates linearly which is not the effect you want, unless... unless you use the magic Q coordinate ! *Ouch* my head hurts, it's too much for me. I've never played with that Q coordinate but for sure it's the perfect solution.

I'll investigate and post here again later.

Edit : investigations
Ok it works ! you can stretch the s axis with a single quad thanks to the Q coordinate.
The thing is, now the t is stretched too and it looks ugly (just like good old missing perspective correction).

Does anybody know a way to apply the Q coordinate division in only S and not T ?

I'm continuing investigations anyway...


Edit : oh I forgot to post the sample code
In the meantime, try that :
glBegin(GL_QUADS);
glTexCoord4f(0.0f, 0.0f, 0, 1.0f);
glVertex2i(-1, -1);
glTexCoord4f(.25f, 0.0f, 0, .25f);
glVertex2i(+1, -1);
glTexCoord4f(.25f, .25f, 0, .25f);
glVertex2i(+1, +1);
glTexCoord4f(0.0f, 1.0f, 0, 1.0f);
glVertex2i(-1, +1);
glEnd();


Edit : I give up
All right I can't do anything about the "perspective correction" effect. It seems like it's a matter of drivers, which I can not deal with obviously.

Otherwise you can simulate perspective and then enable perspective correction, for sure it will work but you have to be sure that the quad doesn't interfere with depth buffer otherwise you have to use stencil buffer.

In which application is your quad intended to be rendered ?
If there's some useful conditions, for instance if the quad is always seen from a top view, then it is possible to optimize the algorithm.

[edited by - vincoof on August 30, 2002 8:42:22 PM]

Share this post


Link to post
Share on other sites