PDA

View Full Version : Texturing a wall



Dreuzzo
12-18-2012, 03:16 AM
Hi all,
I have a problem with texturing.
I draw a wall with a random hole at baseline. To do that, I use 3 cubes:
1) Before the hole (from [minX, minY] to [xHole, maxY]
2) Up to the hole (from [xHole, maxYHole] to [xHole+maxXHole, maxY]
3) After the hole

Then I have a wall texture and I want it is placed good over the 3 cubes: insted I get three distinct textures with not-continuity effect...
This is the code.



if (useEnvmap)
{
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_2D);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);


// when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST );
// when texture area is large, bilinear filter the first mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
//glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE);//combina texture cno luci
glBindTexture(GL_TEXTURE_2D, 3);
glDisable(GL_LIGHTING);

}
else
glColor3f(0,0,1);

glPushMatrix();
glTranslated((-myFloor->floorMaxX + xBuco)/2, maxY/2, pz+maxZ/2);
glScaled(abs(-myFloor->floorMaxX-xBuco)/2 , maxY/2 , maxZ);
drawCubeFill();
glPopMatrix();

glPushMatrix();
glTranslated(xBuco+bucoMaxX/2, (maxY-bucoMaxY)/2+bucoMaxY, pz+maxZ/2);
glScaled(bucoMaxX/2 , (maxY-bucoMaxY)/2 , maxZ);
drawCubeFill();
glPopMatrix();

glPushMatrix();
glTranslated((myFloor->floorMaxX + xBuco + bucoMaxX)/2, maxY/2, pz+maxZ/2);
glScaled(abs(myFloor->floorMaxX-(xBuco+bucoMaxX))/2 , maxY/2 , maxZ);
drawCubeFill();
glPopMatrix();


if (useEnvmap)
{
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
}


And this is the texture:

http://us.123rf.com/400wm/400/400/pakmor/pakmor0809/pakmor080900175/3606848-texture-mattoni.jpg

Thanks