OpenGL - look trough surface -nehe lesson

This is a discussion on OpenGL - look trough surface -nehe lesson within the Game Programming forums, part of the General Programming Boards category; Hey, Im following the Nehe lessons and I'm currently at lesson 06. Since the lesson where he started drawing 3d ...

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

    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

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    maybe enable depth testing
    glEnable( GL_DEPTH_TEST );
    signature under construction

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Bleh, I saw nehe using that function as well, when it just didnt want to work i removed all the unnecesary things imo.

    Although before when I used it I called that function before I called createWindow and glutFullScreen...

    By placing glEnable(GL_DEPTH_TEST); after those two it works perfect .

    Thanks alot.

    * nehe's tuts are good, but they lack too much information imo on what each function does exactly and when/ in which order you should call them *

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    thats why there are opengl references which explain every function in detail
    signature under construction

  5. #5
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    True like http://www.mevis.de/opengl/glEnable.html

    But for someone that is just starting out with anything graphics related, 3d graphics ( although I have worked with 3dmax etc but that is completely different ), the following does not makes too much sense:

    GL_DEPTH_TEST If enabled, do depth comparisons and update the depth buffer. See glDepthFunc and glDepthRange.
    And with error reports like:

    ERRORS

    GL_INVALID_ENUM is generated if cap is not one of the values listed above. GL_INVALID_OPERATION is generated if glEnable is called between a call to glBegin and the corresponding call to glEnd.


    One has a hard time tracking down an error like this, if one does not know the call should be made before a call to some other function, and it is not reported as an error when one does.. the only thing one can do is guess ...



    Maybe I should just get myself a book, internet tutorials are great, but maybe a book will go about it step by step , instead of jumping into the coding without even having a fair background of the graphics library or 3d graphics using the library...

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    hm i guess the red book should be enough to understand the basics of 3d graphics.

    http://fly.srk.fer.hr/~unreal/theredbook/
    Last edited by Raven Arkadon; 08-24-2006 at 06:14 PM.
    signature under construction

  7. #7
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    You also may want to have a look at Beginning OpenGL Game Programming.
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  8. #8
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    psychopath: That was exactly the book I had in mind, after looking at the sticky at the top of this board and some amazon searching.

    Raven: I've already bookmarked it, thanks . ( although I still prefer a book over a html version of a book, I like the smell of a fresh book )

    Thanks everyone in my quest to understand openGL .

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Or you can submit to the forces of evil and succumb to the dark side of DX.



    Bill is Palpatine.

    I should get paid to be a DX tech evangelist.

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, 09:21 PM
  5. Game update...
    By jdinger in forum Game Programming
    Replies: 14
    Last Post: 11-08-2002, 06:10 AM

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