Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Some glTexParameters() being ignored.

  1. #1

    Some glTexParameters() being ignored.

    Code :
    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:
    Code :
    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);
    }

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,726

    Re: Some glTexParameters() being ignored.

    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.

  3. #3

    Re: Some glTexParameters() being ignored.

    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?

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Some glTexParameters() being ignored.

    Either specify different texture coords range or use a texture matrix to scale the texture coords.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •