Skip to main content
gamedev.net
🔒 Locked

Project a Texture

Started by dasan11 Jun 3, 2006 at 9:27 AM 3 replies 1k views
Original Post
dasan11
dasan11
I use this method to project the texture.But the result wasn't right.where is wrong? glBindTexture(GL_TEXTURE_2D, texture[0]);//define the texture glTexGenfv( GL_S, GL_EYE_LINEAR, &Splane[0] );//{1.f, 0.f, 0.f, 0.f}; glTexGenfv( GL_T, GL_EYE_LINEAR, &Tplane[0] );// {0.f, 1.f, 0.f, 0.f}; glTexGenfv( GL_R, GL_EYE_LINEAR, &Rplane[0] );// {0.f, 0.f, 1.f, 0.f}; glTexGenfv( GL_Q, GL_EYE_LINEAR, &Qplane[0] );// {0.f, 0.f, 0.f, 1.f}; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glMatrixMode(GL_TEXTURE); glTranslatef( 0.5, 0.5, 0.0 ); glScalef( 0.5, 0.5, 1.0 ); gluPerspective(45,1,0.1,100); gluLookAt(-40,2,30,0,0,0,0,1,0); glPopMatrix(); glMatrixMode(GL_MODELVIEW); gluLookAt(0,0,30,0,0,0,0,1,0); glBegin(GL_QUADS); glVertex3f(-10,-10,-10); glVertex3f(10,-10,-10); glVertex3f(10,10,-10); glVertex3f(-10,10,-10); glEnd();
Eitsch
Eitsch
use something like this for all coords

glTexGenfv(GL_S,GL_EYE_PLANE,x);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_LINEAR);
glEnable(GL_TEXTURE_GEN_S);

dont forget to load identity to texture matrix otherwise your texturematrix will be updated every frame. (glPushMatrix will push the CURRENT MATRIX...so you first have to choose your matrix and then use glPushMatrix)
dasan11
dasan11
at last step,I need to invert the texture matrix.
use glMultMatrixf((GLfloat*)M_Inverse),
but I don't know how to get M_Inverse.
where can I find the M_Inverse value?

and I use the function to do this,but the result is wrong.

glGetFloatv( GL_TEXTURE_MATRIX, tmpMatrix ); //get the texture matrix
transposeMatrix( tmpMatrix ); //invert the matrix

glTexGenfv( GL_S, GL_OBJECT_PLANE, &tmpMatrix[0] );
glTexGenfv( GL_T, GL_OBJECT_PLANE, &tmpMatrix[4] );
glTexGenfv( GL_R, GL_OBJECT_PLANE, &tmpMatrix[8] );
glTexGenfv( GL_Q, GL_OBJECT_PLANE, &tmpMatrix[12] );
Basiror
Basiror
You matrix has to be orthogonal in order to get the inverse of it by simply transposing the original matrix.
http://www.8ung.at/basiror/theironcross.html
dasan11
dasan11
Quote:
Original post by Basiror
You matrix has to be orthogonal in order to get the inverse of it by simply transposing the original matrix.



the function transposeMatrix()inverses the matrix.
void transposeMatrix( GLfloat m[16] )
{
GLfloat tmp;
#define Swap( a, b ) tmp = a; a = b; b = tmp
Swap( m[1], m[4] );
Swap( m[2], m[8] );
Swap( m[3], m[12] );
Swap( m[6], m[9] );
Swap( m[7], m[13] );
Swap( m[11], m[14] );
#undef Swap
}

glGetFloatv( GL_TEXTURE_MATRIX, tmpMatrix ); //get the texture matrix
transposeMatrix( tmpMatrix ); //inverse the texture matrix
glLoadMatrixf(tmpMatrix);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.