Thread: Textures Screwing Up

  1. #1
    People Love Me
    Join Date
    Jan 2003
    Posts
    412

    Textures Screwing Up

    I'm trying to make a bit of a background scene in OpenGL. The first rectangle is the ground rectangle with a grass texture, and the second is a rectangle placed behind it, which is supposed to be the sky.

    The code compiles just fine, but when I run it, I get unexpected results. The texture in front disappears, and the texture behind it doesn't even show up.

    When I remove the second rectangle, the first one shows up just fine, texture and all. But adding the second rectangle screws everything up.
    Code:
    //Ground Rectangle{
    glTexCoord2f(0.0f,0.0f);
    glVertex3f(-9.0f,0.0f,0.0f);	//Bottom Left
    glTexCoord2f(1.0f,0.0f);
    glVertex3f(9.0f,0.0f,0.0f);	//Bottom Right
    glTexCoord2f(1.0f,1.0f);
    glVertex3f(9.0f,9.0f,0.0f);	//Top Right
    glTexCoord2f(0.0f,1.0f);
    glVertex3f(-9.0f,9.0f,0.0f);	//Top Left
    //}
    
    //Sky Rectangle{
    glColor3f(0.1f,0.2f,1.1f);	//Blue-ish Sky
    glTranslatef(0.0f,0.0f,-1.0f);	//Placed Behind Ground
    glVertex3f(-9.0f,0.0f,0.0f);	//Bottom Left
    glVertex3f(9.0f,0.0f,0.0f);	//Bottom Right
    glVertex3f(9.0f,9.0f,0.0f);	//Top Right
    glVertex3f(-9.0f,9.0f,0.0f);	//Top Left
    //}
    I really have no idea how to make different layers of textured polygons work, nor do I know how to add more than one texture my program. Can anyone help?
    Last edited by Krak; 07-10-2003 at 07:59 PM.

  2. #2
    When you are in texture mode everything needs a texture (from my experiences, I'm new at OpenGL as well). So you need to make a texture for the sky. A good way to do this if you only want one color is to just make a 1D texture with one pixel that is the color you want, and bind it to the sky.

    edit: Oh, and to make the ground on the bottom of the screen like real life, you need to tip your quad over.

    edit 2: The easiest way to do a sky if it is one color is to set the clear color to blue. Than just render all your polygons, and it'll look right.
    Last edited by frenchfry164; 07-10-2003 at 08:09 PM.

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Ok, the following is the code for textures.h, which has my LoadGLTextures() function.
    Please bear with me, because I really don't have much of an idea how to do this right at all:
    Code:
    AUX_RGBImageRec *LoadBMP(char *Filename);
    
    int LoadGLTextures() // Load Bitmaps And Convert To Textures
    {
    int Status=FALSE; // Status Indicator, Nothing's Happened Yet.
    AUX_RGBImageRec *TextureImage[2]; // Create Storage Space For The Texture
    memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL, Clear Image Record
    
    
    // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    if (TextureImage[0]=LoadBMP("C:/Documents and Settings/Dean/My Documents/My Pictures/gamesprites/tilegrass.bmp"))
    {
    Status=TRUE; // Set The Status To TRUE
    
    glGenTextures(1, &texture[0]); // Create The Texture
    
    // Typical Texture Generation Using Data From The Bitmap
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    
    // Generate The Texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
    }
    
    if (TextureImage[0]) // If Texture Exists
    {
    if (TextureImage[0]->data) // If Texture Image Exists
    {
    free(TextureImage[0]->data); // Free The Texture Image Memory
    }
    
    free(TextureImage[0]); // Free The Image Structure
    }
    
    if (TextureImage[1]=LoadBMP("C:/Documents and Settings/Dean/My Documents/My Pictures/gamesprites/s1.bmp"))
    {
    Status=TRUE; // Set The Status To TRUE
    
    glGenTextures(1, &texture[1]); // Create The Texture
    
    // Typical Texture Generation Using Data From The Bitmap
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    
    // Generate The Texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);
    
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
    }
    
    if (TextureImage[1]) // If Texture Exists
    {
    if (TextureImage[1]->data) // If Texture Image Exists
    {
    free(TextureImage[1]->data); // Free The Texture Image Memory
    }
    
    free(TextureImage[1]); // Free The Image Structure
    }
    return Status; // Return The Status
    }
    ...and this is the code for my function that draws polygons:
    Code:
    glLoadIdentity();
    glTranslatef(0.0f,-12.0f,-15.0f);
    
    glBegin(GL_QUADS);
    
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    //Ground Rectangle{
    glTexCoord2f(0.0f,0.0f);
    glVertex3f(-9.0f,0.0f,0.0f); //Bottom Left
    glTexCoord2f(1.0f,0.0f);
    glVertex3f(9.0f,0.0f,0.0f); //Bottom Right
    glTexCoord2f(1.0f,1.0f);
    glVertex3f(9.0f,9.0f,0.0f); //Top Right
    glTexCoord2f(0.0f,1.0f);
    glVertex3f(-9.0f,9.0f,0.0f); //Top Left
    //}
    
    glTranslatef(0.0f,9.0f,-1.0f);
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glTexCoord2f(0.0f,0.0f);
    glVertex3f(-11.0f,0.0f,0.0f); //Bottom Left
    glTexCoord2f(1.0f,0.0f);
    glVertex3f(11.0f,0.0f,0.0f); //Bottom Right
    glTexCoord2f(1.0f,1.0f);
    glVertex3f(11.0f,9.0f,0.0f); //Top Right
    glTexCoord2f(0.0f,1.0f);
    glVertex3f(-11.0f,9.0f,0.0f); //Top Left
    I want there to be a rectangle on top, with "s1.bmp", and one below with "tilegrass.bmp".
    Only one rectangle shows up, though: the one that "tilegrass.bmp" is supposed to be on,
    but instead of that, "s1.bmp" is on it.

    I really need some help with this stuff. :\
    Last edited by Krak; 07-10-2003 at 10:32 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Textures
    By fighter92 in forum Game Programming
    Replies: 1
    Last Post: 03-21-2009, 10:57 AM
  2. loading textures from resources (dx8/9)
    By X PaYnE X in forum Game Programming
    Replies: 1
    Last Post: 12-25-2005, 04:44 PM
  3. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  4. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM
  5. Q3A textures
    By glUser3f in forum Game Programming
    Replies: 11
    Last Post: 09-04-2003, 03:40 AM