PDA

View Full Version : Texture matrix weirdness



huntc
07-12-2005, 12:53 AM
Hi there,

I've determined a matrix that incorporates a scale and translation for my texture. This enables me to place a texture of varying sizes on to an object. All good.

The problem is that periodically, my texture is moved somewhere else... it is almost like my texture coordinates are being scaled/translated by something else.

I'm *reasonably* confident that I'm calling glMatrixMode appropriately. In fact, here's the code that I'm using to set up my texture coords:



// Set our texture matrix

glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadMatrixf(mTextureMatrixP);
glMatrixMode(GL_MODELVIEW);

// Draw the world
...
// Restore our texture matrix

glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);I'm pretty sure that mTextureMatrixP does not get mutated elsewhere in the proggy.

I've got this feeling that something else is effecting my texture's world...

Here's an image of my world when all is well (most of the time):

http://www.classactionpl.com/ok.jpg

...and then when things go crazy:

http://www.classactionpl.com/notok.jpg

There are other things going on like changing the raster position, drawing bitmaps etc., but this is all done when I'm in the model view matrix. I don't jump out of the model view matrix anywhere else.

Any help appreciated as I'm going nuts.

Cheers,
-C

T101
07-12-2005, 01:53 AM
1. Are you using a single texture the whole time or is it with different textures?

2. Why do you need to scale and translate the texture? Why not just use standard texture coordinates? You may well have a valid reason for this, but I don't think varying texture sizes should be one.

3. In the bottom picture it looks like you might be getting some sort of clamping. Maybe you should try setting the wrapping mode for the texture.

4. If the matrix itself is as fault, that can only be caused by corruption of your mTextureMatrixP array, since you're doing a glLoadMatrix, not a mult.

5. Are you using TexGen? If so, are you moving the object or the camera in any way?

huntc
07-12-2005, 02:06 AM
Originally posted by T101:
1. Are you using a single texture the whole time or is it with different textures?
One texture.

2. Why do you need to scale and translate the texture? Why not just use standard texture coordinates? You may well have a valid reason for this, but I don't think varying texture sizes should be one.
As I zoom in on the world, I want to pull in portions of bitmaps with higher resolutions. The portions equate to the dimensions of the viewport so my memory allocation for the texture remains static. Having the higher resolution bitmaps around in memory is not feasible.

3. In the bottom picture it looks like you might be getting some sort of clamping. Maybe you should try setting the wrapping mode for the texture.
I've done this:


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);I did the above for debugging purposes. I will comment out the two lines just in case that's what's causing my problems... why would this be a problem though?

4. If the matrix itself is as fault, that can only be caused by corruption of your mTextureMatrixP array, since you're doing a glLoadMatrix, not a mult.
That's what I thought. I'm pretty sure mTextureMatrixP isn't getting corrupted though. I'll check again.

5. Are you using TexGen? If so, are you moving the object or the camera in any way?
I'm not using TexGen.
That's for your prompt reply. Any other ideas?

T101
07-12-2005, 02:43 AM
Not yet.

The clamping would come in play if you're using translation to rotate the world (you didn't specify if you're doing that). If you hit an edge, the texture just stops instead of wrapping around. And clamp-to-edge results in lines outside [0,1].

huntc
07-12-2005, 07:50 PM
Thanks for this. I'm performing a glRotate while in my modelview matrix mode. Are you stating that this could have caused my issue?

I've presently disabled clamping to see if the problem manifests itself again.

I'll add to this post in a week or so to confirm whether the problem went away.

Thanks for your help.

Cheers,
-C

T101
07-12-2005, 10:35 PM
No. The glRotate would not have anything to do with it (I think it probably wouldn't even have mattered if you were using texgen).

What I meant was: if you're scrolling the texture left or right instead of rotating the geometry, you'll run into problems when clamping is turned on.

Overmind
07-13-2005, 01:32 AM
Have you tried glGetting the texture matrix and logging it somewhere? Then you could verify if it's really the same or if it's different when the error appears.

Once you know that the texture matrix is different, you can do the same for your mTextureMatrixP variable, and so on, slowly tracking back to the point that caused the modification...

If it stays the same, you must have some corruption of the texture coordinates...

Perhaps you have some memory corruption like an array overflow, that alters your matrix by accident.

jide
07-13-2005, 01:42 AM
Try something like that:


glMatrixMode(GL_MODELVIEW);
// some code on modelview

glMatrixMode(GL_TEXTURE);
glLoadMatrixf(mTextureMatrixP);

glMatrixMode(GL_MODELVIEW);
// Draw the worldYour push/pop on the texture matrices are doing nothing as you're loading a matrix and not multiplying one with the current.

Hope that helps.

huntc
07-13-2005, 02:18 AM
OK, big confession time.

mTextureMatrixP was being corrupted.

:(

I'm such an idiot.

Thanks to both of you for sending in your replies.

Cheers,
-C