Thread: OpenGL - look trough surface -nehe lesson

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110

    OpenGL - look trough surface -nehe lesson

    Hey,

    Im following the Nehe lessons and I'm currently at lesson 06. Since the lesson where he started drawing 3d shapes ( pyramid , cube ) I've experienced some weird things.

    It seems that if I draw a pyramid, cube or whatever, I can look trough the surface of some quads or triangles. I though that working with textures would resolve this, but it didn't, in fact its when I began working with textures I really saw what was going wrong.

    Here you can see some screenshots of what is happening. Apart from the texture being a yellow car, and its getting displayed as a blue one, you can see that you can look trough the surfaces .... As you can see it seems as if some quads are not being drawn, although I draw them in my renderScene function...

    I first though that maybe I should change the point of view ( as in change the z-position, since maybe I might be viewing trough the cube ) but that didnt do anything.

    This is how I setup the window ( I start from a console window ):

    Code:
    void initWindow(int * argc,char *argv[]) {
        glutInit(argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);                    
    
        glutCreateWindow("Lesson06");
        glutFullScreen();    
    }
    I've taken alot of things out, and tried to apply one by one the functions that were used in nehe's tutorial to set up the window but that didnt change anything as well.

    This is how I draw the cube along with it's textures:

    Code:
    void renderScene(void) {    
        
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
           
        glLoadIdentity();   
        
        glTranslatef(0.0,0.0,0.0);    
    
        glRotatef(xrot,1.0,1.0,0.0);
        glRotatef(yrot,0.0,1.0,0.0);
        glRotatef(zrot,0.0,0.0,1.0);
        
        glEnable(GL_TEXTURE_2D);    
        /*selecteer ons geladen texture , dit kan niet tussen glBegin en glEnd */
        glBindTexture(GL_TEXTURE_2D, 13);
    
        /*start render code*/
        glBegin(GL_QUADS);
            // Front Face
            glNormal3f( 0.0f, 0.0f, 1.0f);    
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f,  0.5f);    // Bottom Left Of The Texture and Quad
            glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, -0.5f,  0.5f);    // Bottom Right Of The Texture and Quad
            glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f,  0.5f,  0.5f);    // Top Right Of The Texture and Quad
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f,  0.5f,  0.5f);    // Top Left Of The Texture and Quad
            // Back Face
            glNormal3f( 0.0f, 0.0f,-1.0f);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f);    // Bottom Right Of The Texture and Quad
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f,  0.5f, -0.5f);    // Top Right Of The Texture and Quad
            glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f,  0.5f, -0.5f);    // Top Left Of The Texture and Quad
            glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f);    // Bottom Left Of The Texture and Quad
            // Top Face
            glNormal3f( 0.0f, 1.0f, 0.0f);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f,  0.5f, -0.5f);    // Top Left Of The Texture and Quad
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f,  0.5f,  0.5f);    // Bottom Left Of The Texture and Quad
            glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f,  0.5f,  0.5f);    // Bottom Right Of The Texture and Quad
            glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f,  0.5f, -0.5f);    // Top Right Of The Texture and Quad
            // Bottom Face
            glNormal3f( 0.0f,-1.0f, 0.0f);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, -0.5f, -0.5f);    // Top Right Of The Texture and Quad
            glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, -0.5f, -0.5f);    // Top Left Of The Texture and Quad
            glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f,  0.5f);    // Bottom Left Of The Texture and Quad
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f,  0.5f);    // Bottom Right Of The Texture and Quad
            // Right face
            glNormal3f( 1.0f, 0.0f, 0.0f);
            glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f);    // Bottom Right Of The Texture and Quad
            glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f,  0.5f, -0.5f);    // Top Right Of The Texture and Quad
            glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f,  0.5f,  0.5f);    // Top Left Of The Texture and Quad
            glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f,  0.5f);    // Bottom Left Of The Texture and Quad
            // Left Face
            glNormal3f(-1.0f, 0.0f, 0.0f);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f);    // Bottom Left Of The Texture and Quad
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f,  0.5f);    // Bottom Right Of The Texture and Quad
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f,  0.5f,  0.5f);    // Top Right Of The Texture and Quad
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f,  0.5f, -0.5f);    // Top Left Of The Texture and Quad
    
        glEnd();
    
        /*einde render code */
        glutSwapBuffers();
    }
    And finally this is how I load the textures, although I dont think anything is wrong with it, since I had the same problem when I was coloring the QUADS using glColor3f() .

    Code:
    int loadGLTextures(const char *textureFileName) {
        
        bitmap bmp;        
        if(loadBmp(textureFileName,&bmp)==0) {        
            return 0;
        }
        glBindTexture(GL_TEXTURE_2D, 13);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    
        glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, bmp.width, bmp.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bmp.imageData);
    
        free(bmp.imageData);
        return 1; 
    }
    The whole project can be found here ( it's a Dev-C/C++ project ).

    Any help is really appreciated, its probably something stupid but I just don't find the problem.

    Thanks in advance,

    Ganglylamb.
    Last edited by Ken Fitlike; 08-24-2006 at 04:29 AM. Reason: fixed project link

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL: How to make surface shiny
    By ting in forum Game Programming
    Replies: 6
    Last Post: 06-18-2008, 05:09 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. OpenGL Lesson 3
    By Gonavitch in forum C++ Programming
    Replies: 8
    Last Post: 08-09-2004, 09:31 PM
  4. NeHe OpenGL Tut Dont Compile.
    By oobootsy1 in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2004, 10:21 PM
  5. Game update...
    By jdinger in forum Game Programming
    Replies: 14
    Last Post: 11-08-2002, 07:10 AM