Textured polygons not obscuring ones behind.

This is a discussion on Textured polygons not obscuring ones behind. within the Game Programming forums, part of the General Programming Boards category; I basically have a simple textured box program that draws a box with textured faces. The box comes out fine ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    Textured polygons not obscuring ones behind.

    I basically have a simple textured box program that draws a box with textured faces. The box comes out fine but when it comes to depth, certain faces do not obscure the ones that are drawn behind it. Here is a sample of the code that handles the texturing.

    Code:
    #include "scenes.h"
    
    //Box Scene================================================================
    GLuint WallTex;
    
    void Box::setupBoxScene()
    {
        CTargaImage rustWall;
    
        //load the Wall Texture
        rustWall.Load("Data/RustyWall.tga");
    
        //Get Texture Object
        glGenTextures(1, &WallTex);
    
        glBindTexture(GL_TEXTURE_2D, WallTex);
    
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
                     rustWall.GetWidth(), rustWall.GetHeight(), 0,
                     GL_RGB, GL_UNSIGNED_BYTE, rustWall.GetImage());
    
    
        rustWall.Release();
    }
    
    void Box::renderBox()
    {
            glBindTexture(GL_TEXTURE_2D, WallTex);
        	glBegin(GL_QUADS);
    
    		// Front Face
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    
    		// Back Face
    		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    
    		// Top Face
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    
    		// Bottom Face
    		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    
    		// Right face
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    
    		// Left Face
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    	glEnd();
    }
    Attached Images Attached Images   

  2. #2
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    Is your projection matrix set up correctly? I had a similar problem in another thread.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I did a bitwise OR in the glEnable function for depth and stneil test, I seperated them and it seemed to work out nicely.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    It appears to me that this is a problem with backface culling.

  5. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Well I solved it. I guess you can't OR things in glEnable(). It was the way I enabled depth and stencil testing.
    Last edited by indigo0086; 05-13-2007 at 05:11 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating Scenes with many 1,000s of Polygons
    By thetinman in forum Game Programming
    Replies: 5
    Last Post: 12-25-2008, 09:14 PM
  2. Textured plane suggestions
    By VirtualAce in forum Game Programming
    Replies: 9
    Last Post: 04-20-2004, 09:28 PM
  3. OpenGL Polygons...
    By PsychoBrat in forum Game Programming
    Replies: 0
    Last Post: 01-01-2004, 02:35 AM
  4. polygons vs. 3d models
    By Unregistered in forum Game Programming
    Replies: 5
    Last Post: 07-27-2002, 03:39 PM
  5. Drawing polygons?
    By dark_fusion in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 07-18-2002, 05:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21