?
Solved

Opengl skybox

Posted on 2011-03-12
3
Medium Priority
?
1,440 Views
Last Modified: 2012-05-11
I am creating a skybox for my game. I have drawn a simple cube that will surround the game level. The question I have though is how to I draw the box so that it will keep its distance from the camera. This is so the player will not be able to walk through the background.

I have just drawn a very simple cube. Will this be sufficient.


void skybox(void)
{

  glNormal3f( 0.0f, 0.0f, 0.5f);                              
             glVertex3f(-300.0f, -300.0f,  300.0f);
             glVertex3f( 300.0f, -300.0f,  300.0f);
         glVertex3f( 300.0f,  300.0f,  300.0f);
             glVertex3f(-300.0f,  300.0f,  300.0f);
            // Back Face
            glNormal3f( 0.0f, 0.0f,-0.5f);                              
          glVertex3f(-300.0f, -300.0f, -300.0f);
          glVertex3f(-300.0f,  300.0f, -300.0f);
          glVertex3f( 300.0f,  300.0f, -300.0f);
          glVertex3f( 300.0f, -300.0f, -300.0f);
            // Top Face
            glNormal3f( 0.0f, 0.5f, 0.0f);                              
          glVertex3f(-300.0f,  300.0f, -300.0f);
          glVertex3f(-300.0f,  300.0f,  300.0f);
          glVertex3f( 300.0f,  300.0f,  300.0f);
          glVertex3f( 300.0f,  300.0f, -300.0f);
            // Bottom Face
            glNormal3f( 0.0f,-0.5f, 0.0f);                              
          glVertex3f(-300.0f, -300.0f, -300.0f);
          glVertex3f( 300.0f, -300.0f, -300.0f);
          glVertex3f( 300.0f, -300.0f,  300.0f);
          glVertex3f(-300.0f, -300.0f,  300.0f);
            // Right Face
            glNormal3f( 0.5f, 0.0f, 0.0f);                              
          glVertex3f( 300.0f, -300.0f, -300.0f);
          glVertex3f( 300.0f,  300.0f, -300.0f);
          glVertex3f( 300.0f,  300.0f,  300.0f);
          glVertex3f( 300.0f, -300.0f,  300.0f);
            // Left Face
            glNormal3f(-0.5f, 0.0f, 0.0f);                              
          glVertex3f(-300.0f, -300.0f, -300.0f);
          glVertex3f(-300.0f, -300.0f,  300.0f);
          glVertex3f(-300.0f,  300.0f,  300.0f);
          glVertex3f(-300.0f,  300.0f, -300.0f);


}
0
Comment
Question by:tango2009
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
SunnyDark earned 1000 total points
ID: 35133317
The trick is to draw the skydome BEFORE any camera transformation is made.
So you set your projection ,  and view matrix to identity, then set a view matrix taking into the account ONLY the rotation of the camera.
Now draw he sky,
Now set the projection and view matrix as usual and draw the scene.

The way I set the view matrix for the sky is take your regular view matrix (LookAt of some sort for example) then clear the translation part of the matrix (usually 41,42,43 elements of the matrix) and use this as the view matrix.
0
 
LVL 3

Assisted Solution

by:xelous
xelous earned 1000 total points
ID: 35400409
Sunny (above) is correct, however, you also need to translate the skybox so that it is centred over your camera position each time you render the frame.

There's a rather good tutorial on here: http://www.morrowland.com/apron/tut_gl.php
0
 
LVL 8

Expert Comment

by:SunnyDark
ID: 35407383
If you only considering the view rotation part , then you dont need to reposition the skybox, as you are already at the center anyhow...
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question