PDA

View Full Version : gl_texture_1d [0 1]



guju
06-19-2002, 07:50 PM
Hi!
If i define a 1d texture, then my s-range is from 0 to 1. Can i specify the texture range also to a different range, say 0.5 to 0.7?

dorbie
06-19-2002, 07:55 PM
If I undestand your question, you can do this with the texture matrix.

guju
06-19-2002, 08:06 PM
You mean like:
glMatrixMode(GL_TEXTURE);
glScalef(0.1, 1, 1);
glTranslate(0.5,0,0)
and then my texture range is from 0.5-0.6. Does this slow down my performance, or is it only multiplied once with the texture matrix. If i specify i 1d texture, is then my matrix a vector?

[This message has been edited by guju (edited 06-19-2002).]

davepermen
06-19-2002, 09:43 PM
i bet normally your texcoords are multiplied by the texmatrix anyways. means normally, it is identity, and then its just a useless extra-operation. but as it is in the pipeline it doesn't slow down at all. at least, as long as you don't use projective texture matrices, as they are not fully hw on every hardware.. (<=gf2 i think)

guju
06-19-2002, 09:59 PM
Thank you davepermen. But did you have a look on my scale and translate? I am not shur if this is correct? My progi behaves strange!

Relic
06-20-2002, 04:14 AM
All matrices in OpenGL are 4x4.
You want to scale first and then translate, do this:
glMatrixMode(GL_TEXTURE);
glLoadIdentity()
glTranslatef(0.5f, 0.0f, 0.0f)
glScalef(0.1f, 1.0f, 1.0f);
glBegin(...);
glTexCoord1f(1.0f) // will become the vector (0.6, 0.0, 0.0, 1.0) then.

LordKronos
06-20-2002, 04:25 AM
Just to make sure you understand, while this will scale you [0,1] range to [0.5,0.6], it will not wrap or clamp to stay within this range. Thus, if you use texture wrapping and input a texture coord of 1.5, it will end up as 0.65, not 0.55

guju
06-20-2002, 10:47 AM
I defined wraping to clamp. I can not follow why a tex coord of 1.5 and scaling from [0 1] to [0.5 0.6] will end up as 0.65?
The next thing is, if i have a quad- element with four vertices. How is the interpolation in the inner reagion of the element done. I get strange color distributions if three of the nodes have the same tex color??

Nakoruru
06-20-2002, 12:22 PM
Would this not take a texture coordinate between 0 and 1 and scale it to be between .5 and .6?

glTranslatef(0.5f, 0.0f, 0.0f)
glScalef(0.1f, 1.0f, 1.0f);

But that is not what he is asking for! He wants to take .5 and .6 and scale it to between between 0 and 1.

smin = .5
smax = .6

It is actually this:
(smin * .1) + .5 = .55
(smax * .1) + .5 = .56

You need to do the inverse, multiply and subtract.

glTranslatef(-5f, 0.0f, 0.0f)
glScalef(10.0f, 1.0f, 1.0f);

(smin * 10) -5 = 0
(smax * 10) -5 = 1

Nakoruru
06-20-2002, 12:33 PM
For some reason I can't edit my own posts, so I'll just follow up with another reply.

There is something else there besides just inverting the operations, I guess its because of the nature of scale and translate. So you end up subtracting by 5 instead of .5f.

Most of the time you can think of operations on the texture matrix has having the opposite effect on texels as they would on points. i.e., a matrix that would shrink a 3D object will cause a texture image to grow. If it rotate an object right, it will rotate texels rotate left.

Bob
06-21-2002, 02:56 AM
I can not follow why a tex coord of 1.5 and scaling from [0 1] to [0.5 0.6] will end up as 0.65?

If 1.5 is the texture corodinate, it will be transformed by the texture matrix, just like any other texture coordinate. So with a scale of 0.1 and a translation of 0.5, you get this:

1.5 * 0.1 + 0.5 = 0.65

So there's your 0.65.

Clamping and wrapping is applied AFTER the texture matrix. 1.5 will not be wrapped/clapmed, since it's BEFORE the texture matrix.

Now, say the untransformed texture coordinate is 11 instead, you get this.

11 * 0.1 + 0.5 = 1.6

Since this is outside the range [0, 1], it will be transtaled into the texture coordinate 1.0 (clamped) or 0.6 (wrapped).

[This message has been edited by Bob (edited 06-21-2002).]