Sign in to follow this  
daniel_i_l

tileing textures

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
On the x coordinate it should look like this:


0.0-----2.0
|
|
|
0.0-----2.0

y will be the same 0.0 on the starting edge, 2.0 on the end edge/point.

2.0-----2.0
|
|
|
0.0-----0.0

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

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