PDA

View Full Version : 3D texture mapping



krol
08-29-2002, 03:10 AM
Hello everyone

I have some problems with textures coordinate automatic generation. I've built 3D texture and I want to map it on box ( glutSolidBox ) 1:1. I set glTexGen like this:


float xPlane[] = {0.0f, 0.0f, 0.5f, .0f};
float yPlane[] = {0.0f, 0.5f, 0.0f, .0f};
float zPlane[] = {0.5f, 0.0f, 0.5f, .0f};


glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEA R);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEA R);
glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEA R);

glTexGenfv(GL_S,GL_OBJECT_PLANE,xPlane);
glTexGenfv(GL_T,GL_OBJECT_PLANE,yPlane);
glTexGenfv(GL_R,GL_OBJECT_PLANE,zPlane);


and after it, I draw cube

glutSolidCube(2.0);

Unfortunately the texture isn't mapped appropriately. Middle part of texture is mapped on the edge of solid and edges of the texture is mapped in the middle of the cube!!

Do You know what may be the reason of this effect and how to do it correctly ??

Best regards
Marcin

Humus
08-29-2002, 03:42 AM
I think you'll need a texture matrix, something like this:

float xPlane[] = {1.0f, 0.0f, 0.0f, 0.0f};
float yPlane[] = {0.0f, 1.0f, 0.0f, 0.0f};
float zPlane[] = {0.0f, 0.0f, 1.0f, 0.0f};


glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEA R);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEA R);
glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEA R);

glTexGenfv(GL_S,GL_OBJECT_PLANE,xPlane);
glTexGenfv(GL_T,GL_OBJECT_PLANE,yPlane);
glTexGenfv(GL_R,GL_OBJECT_PLANE,zPlane);


glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScale(0.5f,0.5f,0.5f);
glTranslate(0.5f,0.5f,0.5f);

glutSolidCube(2.0);