Results 1 to 3 of 3

Thread: Skybox help needed

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    2

    Skybox help needed

    Hi, I am pretty new to OpenGL and only really feel like I am beginning to understand what is going on. I am trying to get a basic sky box to appear around a previously finished project/lesson however it is the first thing that I have done that I have not had a good tutorial for. This may be completely the wrong way to go about doing this but here is the code I have so far to create the skybox:

    Code :
    void skybox(void) {
     
       glPushMatrix();
       glClear(GL_DEPTH_BUFFER_BIT);
       glLoadIdentity();
     
       gluLookAt( 0.0, 0.0, 0.0,
    	      1.0, 0.0, 0.0,
    	      0.0, 1.0, 0.0); 
     
        glPushAttrib(GL_ENABLE_BIT);
        glEnable(GL_TEXTURE_2D);
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glDisable(GL_BLEND);
        glDepthMask(0);
     
       glColor4f(1.0, 1.0, 1.0, 1.0);
     
       glBegin(GL_QUADS);        					//FRONT
          glVertex3f(-1,  1, 1);  
          glVertex3f( 1,  1, 1);   
          glVertex3f( 1, -1, 1);  
          glVertex3f(-1, -1, 1);      
       glEnd();  
     
       glBegin(GL_QUADS);        					//BACK
          glVertex3f(-1,  1, -1);  
          glVertex3f( 1,  1, -1);   
          glVertex3f( 1, -1, -1);  
          glVertex3f(-1, -1, -1);  
       glEnd(); 
     
       glBegin(GL_QUADS);        					//TOP
          glVertex3f(-1,  1,  1);    
          glVertex3f(-1,  1, -1);  
          glVertex3f( 1,  1, -1);   
          glVertex3f( 1,  1,  1); 
       glEnd();  
     
       glBegin(GL_QUADS);        					//BOTTOM
          glVertex3f(-1, -1,  1);  
          glVertex3f( 1, -1,  1);   
          glVertex3f( 1, -1, -1); 
          glVertex3f(-1, -1, -1);    
       glEnd();    
     
       glBegin(GL_QUADS);        					//RIGHT SIDE
          glVertex3f( 1,  1,  1);  
          glVertex3f( 1, -1,  1);   
          glVertex3f( 1, -1, -1);  
          glVertex3f( 1,  1, -1);   
       glEnd();  
     
       glBegin(GL_QUADS);        					//LEFT SIDE
          glVertex3f(-1,  1,  1);  
          glVertex3f(-1, -1,  1);   
          glVertex3f(-1, -1, -1);  
          glVertex3f(-1,  1, -1);   
       glEnd();    
     
      glPopAttrib();
      glDepthMask(1);
      glPopMatrix();
    }

    At the moment it clears the buffer bit, resets the camera, disables a bunch of stuff including the depth buffer, draws a 2 unit white cube about the origin (the background of the project is currently black so I should be able to tell when I get it working), and then reverts back to old attrib settings.

    I am calling this at the beginning of my display function before anything else is rendered. Currently all that happens is that a white square appears behind everything else I am drawing which I think must mean that at least one of the faces of the cube is being drawn but no others.

    If anyone could help me out and point me in the right direction I would be very grateful. Also if anyone knows of a good tutorial to achieve a skybox which they think would be good for a beginner please send me the link.

    Thanks

    Edit:

    I thought it might be useful to include the display code:

    glutDisplayFunc(display);

    Code :
    void display(){
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();
     
      skybox();
     
      gluLookAt( 0.0, 10.0, 20.0,
    	     0.0, 10.0, 0.0,
    	     0.0, 1.0, 0.0);
     
      init_lights();
      glCallList(ground);
      render_windmill(0.0, 0.0);
     
      glFlush();
      glutSwapBuffers();
      return;
    }

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Skybox help needed

    well your on the right track, the reason why only one quad shows up could be that your z.near could be set at 1 in which case anything but the front most quad could get culled which is why i use glVertex3f(-10, 10, 10); instead of glVertex3f(-1, 1, 1);.

    The second problem that it could be is that they are all facing away from the camera try glDisable(GL_CULL_FACE); and if all goes white then that's your problem, just flip the faces inwards as needed, it's easier if you color each face with a different color.

    Then just give them some texture coordinates(+textures) and that should be it

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    2

    Re: Skybox help needed

    Hi, the z.near was set to one so I did as you suggested and changed the cube edge length to 10.

    Thanks alot for the help.

Similar Threads

  1. Skybox
    By Quaver in forum OpenGL: Basic Coding
    Replies: 16
    Last Post: 07-29-2013, 11:13 AM
  2. UT Skybox, how is it done!?!?
    By GL_ZERO in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 09-10-2003, 02:16 PM
  3. skybox
    By incus in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 09-17-2002, 01:33 PM
  4. Skybox
    By Phoenix in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 08-07-2002, 01:21 PM
  5. SkyBox
    By Leyder Dylan in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-19-2002, 05:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean