PDA

View Full Version : Non-scalable texture?



luc_pop
11-13-2001, 11:36 PM
I have a texturemap with some text which I assign to a quad. After that I want to scale the quad but the text (in the texture) should remain the same. Is there some functions in OpenGL that allows you to do that or you have to recalculate the value "a" and "b" in glTexCoord2f(a, b).
exampel:



+------+
| text |
+------+

after scaling the quad the result should be:
+------------+
| |
| text |
| |
+------------+



Thank you.

Bob
11-14-2001, 01:14 AM
If you use glScale to scale your quad, you can use glScale with the same parapeters to scale the texture matrix aswell.

Example.



glScalef(2,3,4); // scale your object
glMatrixMode(GL_TEXTURE);
glScalef(2,3,4); // scale texture
glMatrixMode(GL_MODELVIEW);
DrawYourQuad();

If you scale the coordinates yourself, like glVertex3(x*scale, y*scale, z*scale), then scale the texture cordinates in the same way, glTexCoord2(s*scale, t*scale).

luc_pop
11-14-2001, 02:40 AM
I understand what you mean but it is not quite what I was searching for. The results of your solution is like this:



******
*TEXT*
******
("*" = is a color)
after scale the quad and texture with 2:
************
*******TEXT*
************
************
*TEXT*******
************

But what I would like to achieve is this:
after scale the quad and texture with 2:
************
************
****TEXT****
************
************
************



sorry that I was unclear before.

thanx

Bob
11-14-2001, 02:49 AM
Unclear, no, a bit confusing, perhaps http://www.opengl.org/discussion_boards/ubb/smile.gif

So, say you scale the quad with a factor two, do you want the text to be scaled aswell, with a factor two, or do you want the text to have the same size as on the original quad (and therefore cover less area of the quad)?

luc_pop
11-14-2001, 04:55 AM
I want the same size as on the original quad (and therefore cover less area of the quad). Is it possible?

thank you...

Bob
11-14-2001, 05:15 AM
OK, then you must scale the texture matrix as I mentioned in my first post. I now think I forgot some things in my first post, so that's you you didn't get the result you wanted. You also need to translate the texture matrix to move the texture to the middle of the quad. I'm not entirely sure this is correct, but you should be able to get it working by tweaking the numbers. And you might have to call glScale before glTranslate, just swap the two lines.



glMatrixMode(GL_TEXTURE);
glTranslatef((scale-1)*0.5, (scale-1)*0.5, 0);
glScalef(scale, scale, 1);

Did some drawings on a paper, and it should move the texture to the middle of the quad, leaving the size unchanged.

Also remember to set wrapmodes to GL_CLAMP instead of GL_REPEAT.

And of course you can replace scale with scaleX/scaleY to scale the quad differently along the two axes. Just remember that the first scale in glScale is the same scale as the first scale in glTranslate.

luc_pop
11-14-2001, 08:32 AM
Yes it worked very good!

THANK YOU....