3D Texture transformation

Started by
2 comments, last by Dave007as 15 years, 4 months ago
Hi everybody, I've been working on this problem for almost 2 weeks now and it's driving me crazy! Maybe you guys can help me. I have a 3D texture that I map to a series of quads and I manipulate the texture matrix in order to rotate the texture (instead of chaning the modelview matrix). So far so good. However, I realized that calling glRotate3f(90, 0.0, 0.0, 1.0) does not rotate my texture in counterclockwise direction around the z-axis, but in clockwise direction. The other two axis seem to be fine. I can't figure out what the problem is, but I wrote a little test program in which I apply exactly the same operations to a 3d vertex by manipulating the modelview matrix and everything works fine. I have a feeling that something is wrong with my way of mapping texel coords to quads... Here some part of my code

glMatrixMode ( GL_TEXTURE );
glLoadIdentity();
// shift origin to center of texture
glTranslatef ( 0.5, 0.5, 0.5 );
// apply transformation
glRotatef(90, 0.0, 0.0, 1.0);
// shift back
glTranslatef ( -0.5, -0.5, -0.5 );
   
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity();

float tex_z;
int num_quads = 200;

glBegin(GL_QUADS);
for(int z = num_quads - 1; z >= 0; z --)
{		
    tex_z = (GLfloat)z / (GLfloat) num_quads;		

    glTexCoord3f( (GLfloat) 0.0, (GLfloat) 0.0, tex_z );      		    
    glVertex3f( -win_w / 2.0, -win_h / 2.0, 0 );
    
    glTexCoord3f( (GLfloat) 1.0, (GLfloat) 0.0, tex_z );    
    glVertex3f(  win_w / 2.0, -win_h / 2.0, 0 );

    glTexCoord3f( (GLfloat) 1.0, (GLfloat) 1.0, tex_z );
    glVertex3f(  win_w / 2.0,  win_h / 2.0, 0 );

    glTexCoord3f( (GLfloat) 0.0, (GLfloat) 1.0, tex_z );
    glVertex3f( -win_w / 2.0,  win_h / 2.0, 0 );
}
glEnd();

Everything seems pretty straight forward, but it's the first time I work with 3D textures, so hopefully you guys can help me. Is it possible that the texture coordinate system is oriented differently? Thank, Dave
Advertisement
Ok,

let me explain it in a different and simpler way:

When using 3d textures, no matter how I map texel coords to quad vertices, one dimension always has the wrong orientation. In case of the code posted, it's the z axis, meaning that glRotate(20, 0.0, 0.0, 1.0) rotates in CLOCKWISE direction instead of counterclockwise. Rotations around the x and y axis are as expected.

Interestingly enough, when using 2D textures glRotate(20, 0.0, 0.0, 1.0) has the desired effect.

Could it be a bug in the openGL implementation (I know it's unlikely)=

Maybe this will help you guys helping me ;-)
Dave
Did you try using a negative angle?
------------George Gough
Yes I did. A negativ rotation has the disired effect, which makes me believe that the z axis isn't oriented corretly...maybe because I'm messing something up when mapping texture coordinates. I'm not sure. However, I can't just invert the rotation because I need the texture matrix as an input for some kind of clipping algorithm, which assumes that axis are oriented the way they are supposed to be.

Dave

This topic is closed to new replies.

Advertisement