Sign in to follow this  

tileing textures

This topic is 4277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to draw a sky with a cloud texture tiled a few time, to do that I tried multiplying the texture coords like this:
void CreateSkyReflection(float x, float y, float z, float width, float height, float length)
{
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    //glDisable(GL_DEPTH_TEST);
    float tex=2;
    x = x - width  / 2;
    y = y - height / 2;
    z = z - length / 2;
    
    glBindTexture(GL_TEXTURE_2D, g_Texture[BOTTOM_ID]);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    // Start drawing the side as a QUAD
    glBegin(GL_QUADS);      
    
        // Assign the texture coordinates and vertices for the BOTTOM Side
        glTexCoord2f(tex, 0.0f);     glVertex3f(x,         y,          z);
        glTexCoord2f(tex, tex);      glVertex3f(x,         y,          z + length);
        glTexCoord2f(0.0f, tex);     glVertex3f(x + width, y,          z + length); 
        glTexCoord2f(0.0f, 0.0f);    glVertex3f(x + width, y,          z);
    glEnd();
    //glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
}

But the texture didn't tile, it just smeared out? What did I do wrong? Thanks.

Share this post


Link to post
Share on other sites
I did tex=2.0f but it still didn't work?
What happenes if I set tex to 2 is that the BL corner is textered with the whole texture, the BR corner is smeared to the right, the TL is smeared to the top, and the TR corner iis totally smeared!?
Thanks.

Share this post


Link to post
Share on other sites
Your program has been set to clamp the texture instead of tiling it.

Uncomment these lines:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);


And set GL_CLAMP to GL_REPEAT.

But it's best to move them out of your main rendering loop, rather put them straight after loading the picture into opengl.

Share this post


Link to post
Share on other sites

This topic is 4277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this