Skip to main content
GameDev.net gamedev.net
🔒 Locked

tileing textures

Started by daniel_i_l Apr 2, 2006 at 3:13 AM 4 replies 450+ views
Original Post
daniel_i_l
daniel_i_l
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.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Daaark
Daaark
Use x.0f where x is the number of times you want to tile. So if you want to tile twice, use 2.0f.
daniel_i_l
daniel_i_l
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.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Daaark
Daaark
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
Nitrogen
Nitrogen
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.
Delphi C++ OpenGL Development: www.nitrogen.za.org
daniel_i_l
daniel_i_l
Thanks, it worked!
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.