Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Help with texture rotation

  1. #1
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Help with texture rotation

    I'm trying to rotate a texture and apply it to an object. The code is the following:

    Code :
    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.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Re: Help with texture rotation

    I made some improvements but i really need some help. Here is the code:

    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) . I don't know how to solve this, so any help is GREATLY appreciated.

  3. #3
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    883

    Re: Help with texture rotation

    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:

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

  4. #4
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Re: Help with texture rotation

    Thanks yooyo, but i don't know how to retrieve thex texture matrix. Any idea ?

  5. #5
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    NI, Germany
    Posts
    114

    Re: Help with texture rotation

    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

  6. #6
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Re: Help with texture rotation

    I got it working in the following way.

    After setting up two texture units

    Code :
    		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:

    Code :
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glRotatef(((3+0)*elevator_X35_engine*180/M_PI), 0, 0, 1);
    glMatrixMode(GL_MODELVIEW);
    cgGLSetStateMatrixParameter(g_CGparam_TextureViewProj,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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •