PDA

View Full Version : Some glTexParameters() being ignored.



allenmoatallen
09-11-2011, 04:12 PM
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


Is being ignored in our code. Basically we have a grid of cubes of different heights. Each face has its own texture and we are trying to prevent that texture from stretching or squishing depending on the Y-coordinate. They are set to cover the entire face at the moment.

We do use MipMaps but I am unaware of anything that would cause the above 2 commands to be ignored and literally have no effect on rendering.

Full function is below:


void TestState::drawHeightCube(int height)
{
float w = 0.5f;
float h = 0.25f * (height + 1);
float l = 0.5;

// This can be done in a Cube object primitive.
GLfloat vertices[] = { w,h,l, -w,h,l, -w,0,l, w,0,l, // v0-v1-v2-v3 > FRONT
w,h,l, w,0,l, w,0,-l, w,h,-l, // v0-v3-v4-v5 > RIGHT
w,h,l, w,h,-l, -w,h,-l, -w,h,l, // v0-v5-v6-v1 > TOP
-w,h,l, -w,h,-l, -w,0,-l, -w,0,l, // v1-v6-v7-v2
-w,0,-l, w,0,-l, w,0,l, -w,0,l, // v7-v4-v3-v2
w,0,-l, -w,0,-l, -w,h,-l, w,h,-l}; // v4-v7-v6-v5

GLfloat texcoords[] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // FRONT
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // RIGHT
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // TOP
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f};

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, mTexture.textureId());

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);


glNormalPointer(GL_FLOAT, 0, cube_normals);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);

glDrawArrays(GL_QUADS, 0, 24);


glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays
glDisableClientState(GL_NORMAL_ARRAY);

glDisable(GL_TEXTURE_2D);
}

Alfonse Reinheart
09-11-2011, 04:36 PM
Is being ignored in our code.

No, they are not. OpenGL is doing exactly what you told it to do.

The WRAP modes affect how OpenGL handles texture coordinates outside the [0, 1] range. All of your texture coordinates are within the [0, 1] range (unless you're doing some glTexGen stuff that you haven't shown), so therefore, they will have no visible effect.

allenmoatallen
09-11-2011, 05:48 PM
Oh... I had a feeling that was it. What should I be looking at then to keep a texture from stretching within the [0, 1] range? Is that a matter of normalizing the size of the quad against the texture size?

BionicBytes
09-12-2011, 06:51 AM
Either specify different texture coords range or use a texture matrix to scale the texture coords.