# 3D texture mapping

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_LINEAR);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);

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

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_LINEAR);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);

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

glMatrixMode(GL_TEXTURE);