Jump to content
  • Advertisement
Sign in to follow this  
daniel_i_l

tileing textures

This topic is 4493 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
Advertisement
Use x.0f where x is the number of times you want to tile. So if you want to tile twice, use 2.0f.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!