Dear all,
I’m encountering an issue when scaling a shape where a texture is applied. Using the following primitives to set up my texture:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
And my code to draw a cube by faces:
void drawBox(GLfloat size, GLenum type)
{
static GLfloat n[6][3] =
{
{ -1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 1.0, 0.0, 0.0 },
{ 0.0, -1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 0.0, 0.0, -1.0 }
};
static GLint faces[6][4] =
{
{ 0, 1, 2, 3 },
{ 3, 2, 6, 7 },
{ 7, 6, 5, 4 },
{ 4, 5, 1, 0 },
{ 5, 6, 2, 1 },
{ 7, 4, 0, 3 }
};
GLfloat v[8][3];
GLint i;
v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2;
v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2;
v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2;
v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2;
v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2;
v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;
for (i = 5; i >= 0; i--) {
glBegin(type);
glNormal3fv(&n[i][0]);
glTexCoord2f(size, size); glVertex3fv(&v[faces[i][0]][0]);
glTexCoord2f(0, size); glVertex3fv(&v[faces[i][1]][0]);
glTexCoord2f(0, 0); glVertex3fv(&v[faces[i][2]][0]);
glTexCoord2f(size, 0); glVertex3fv(&v[faces[i][3]][0]);
glEnd();
}
}
glBindTexture(GL_TEXTURE_2D, BRICK_TEXTURE);
// Load texture with primitives above and gluBuild2DMipmaps...
drawBox(2, GL_POLYGON);
[ATTACH=CONFIG]1456[/ATTACH]
Nevertheless, as soon as I apply a scaling, such as glScalef(0.5, 3, 1);, the result is the following:
[ATTACH=CONFIG]1457[/ATTACH]
I was expecting that the texture ratio would stay the same or cropped, in order to prevent any distortion of the texture. Do you have any idea on how I can prevent the distortion ?
Many thanks !
James