PDA

View Full Version : Help with texture rotation



Alessandro_dup1
05-31-2004, 05:17 AM
I'm trying to rotate a texture and apply it to an object. The code is the following:


cgGLEnableTextureParameter( g_CGparam_steam_animation );
cgGLSetTextureParameter( g_CGparam_steam_animation, heat_effect_textures.texID);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glRotatef(rot,0, 0, 1);
glMatrixMode(GL_MODELVIEW);
Draw_Object();
cgGLDisableTextureParameter( g_CGparam_steam_animation );Funny thing happens: ALL the textures rotate except the one that i want.

Alessandro_dup1
06-01-2004, 02:19 PM
I made some improvements but i really need some help. Here is the code:



glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[95].texID); // this is the first texture to rotate


glActiveTextureARB( GL_TEXTURE1_ARB );
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, heat_effect_textures[heat_texture_counter].texID); // this is the second one





cgGLBindProgram( g_CGprogram_vertex );
cgGLBindProgram( g_CGprogram_pixel );
cgGLEnableProfile( g_CGprofile_vertex );
cgGLEnableProfile( g_CGprofile_pixel );
cgGLEnableTextureParameter( g_CGparam_testTexture );
cgGLSetTextureParameter( g_CGparam_testTexture, VolumeTexture1 );
cgGLEnableTextureParameter( g_CGparam_testTexture2 );
cgGLSetTextureParameter( g_CGparam_testTexture2, BlurTexture);
cgGLEnableTextureParameter( g_CGparam_testTexture3 );
cgGLSetTextureParameter( g_CGparam_testTexture3, textures[30].texID);

glBegin(GL_TRIANGLE_STRIP);
glMultiTexCoord2fARB( GL_TEXTURE0_ARB,fTexMul4x * (x+ quad_ext)+x_tex,y_tex+ fTexMul4y * (y + quad_ext+quad_ext_sub)-.19);
glMultiTexCoord2fARB( GL_TEXTURE1_ARB,fTexMul4x * (x+ quad_ext)+x_tex,y_tex+ fTexMul4y * (y + quad_ext+quad_ext_sub)-.19);
glVertex2f(x, y+quad_ext_sub-82);
glMultiTexCoord2fARB( GL_TEXTURE0_ARB,fTexMul4x * (x+ quad_ext)+x_tex, y_tex+ fTexMul4y * (y+quad_ext)-.19);
glMultiTexCoord2fARB( GL_TEXTURE1_ARB,fTexMul4x * (x+ quad_ext)+x_tex, y_tex+ fTexMul4y * (y+quad_ext)-.19);
glVertex2f(x, y-82 );
glEnd();


glActiveTextureARB( GL_TEXTURE1_ARB );
glDisable(GL_TEXTURE_2D);
glActiveTextureARB( GL_TEXTURE0_ARB );
cgGLDisableTextureParameter( g_CGparam_testTexture );
cgGLDisableTextureParameter( g_CGparam_testTexture2 );
cgGLDisableTextureParameter( g_CGparam_testTexture3 );

All the textures are correctly rendered, but the ones binded through the glActiveTextureARB call are not rotated.
The problem seems to occur when i enable the vertex and fragment programs with cgGLEnableProfile. Otherwise, if i disable the shader, the two textures are correctly rotated (but of course the shader is off) :mad: . I don't know how to solve this, so any help is GREATLY appreciated.

yooyo
06-01-2004, 03:36 PM
Rotating texcoords using texture matrices are part of fixed function pipeline. Cg, VP, GLSL are programabile pipeline. This mean, its replaces fixed function pipeline. You have to "manualy" rotate texcoords in shader. Usualy, just multiply incoming texcoord by texture matrix:



GLSL example (vertes shader):
void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; // this is what you have to do
}

Alessandro_dup1
06-02-2004, 01:34 AM
Thanks yooyo, but i don't know how to retrieve thex texture matrix. Any idea ?

Jens Scheddin
06-02-2004, 03:13 AM
Originally posted by penetrator:
Thanks yooyo, but i don't know how to retrieve thex texture matrix. Any idea ?With ARB_fragment_program it's "state.matrix.texture[0]" for the matrix of the first ([0]) texture unit. For NV_vertex_program you have to take a look at the extension spec or wait for someone else to post who has more knowledge of this extenion :)

Alessandro_dup1
06-02-2004, 03:58 AM
I got it working in the following way.

After setting up two texture units



glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[95].texID);

glActiveTextureARB( GL_TEXTURE1_ARB );
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, heat_effect_textures[heat_texture_counter].texID);
I rotate the texture matrix and store it in a cg parameter:



glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glRotatef(((3+0)*elevator_X35_engine*180/M_PI), 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
cgGLSetStateMatrixParameter(g_CGparam_TextureViewP roj,CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_IDENTITY);
Then, in the vertex program, i multiplied the texture matrix by the output position, and it works just fine, i.e. the texture is rotated.

OUT.texcoord3 = mul(TextureMat, OUT.position);

I hope this can be helpful for other newbies like me. Any comment about the code posted is appreciated. Thanks