Jump to content
  • Advertisement
Sign in to follow this  
Andrew1979

OpenGL Creating a sky

This topic is 3764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All I'm wanting to create a sky for my gaming environment as everything other than the game scene itself is black :-) I've never created a sky before, how would I do this in OpenGL? Even if no exact solution is suggested, possible suggestions to look up in OpenGL would be grateful. I have the OpenGL super bible - just not sure which part to look at to tell me how to create a realistic sky affect. Any suggestions welcome. Thank you in advance. Andrew

Share this post


Link to post
Share on other sites
Advertisement
I think what you want, is a sky box or a sky dome. The idea is to have a box/sphere around the camera (user eye point) with sky texture to create an illusion that the sky is surrounding the user.

Share this post


Link to post
Share on other sites
Yeah, I use a sky box to add a sky around my entire world. It's made up 6 textures and makes a cube around the game, but it's so large that if the textures are made correct, it looks very real. When you move in the game, you can very slightly see the skybox move in the distance which adds a good little effect. just Google skybox textures and you will get a lot of good links. Skydomes are also a possibility, they are the same but use just 1 texture I think and make a sphere/hemisphere around your game. They use more poly's though I think and I've never had any problems with my sky box. The wiki link covers both types.

Share this post


Link to post
Share on other sites
Basically it will be a cube with a texture for each face. I use the following code when generating the texture:

glGenTextures(1, &m_pFront->texID);
glBindTexture(GL_TEXTURE_2D, m_pFront->texID);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_pFront->width, m_pFront->height, GL_RGB, GL_UNSIGNED_BYTE, m_pFront->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);




This is just one face, there will be 6 in total.

Then to render the code will be similiar to this with the texture coordinates specified:

	// Draw Front side
glBindTexture(GL_TEXTURE_2D, m_pFront->texID);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y, z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y, z);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z);
glEnd();




Render the skybox at the current camera position. You will have to offset it to get it rendering dead centre. Optional is to cull the front face.

Share this post


Link to post
Share on other sites
Remember: You don't have to make your skybox large enough to contain your world, just disable depthwrites and render it before anything else.
(glDepthMask(GL_FALSE);). (reenable depth writes before rendering the world)

Share this post


Link to post
Share on other sites
Quote:
Original post by SimonForsman
Remember: You don't have to make your skybox large enough to contain your world, just disable depthwrites and render it before anything else.
(glDepthMask(GL_FALSE);). (reenable depth writes before rendering the world)

According to some ATI paper (don't remember the title nor the link, but was something about efficient rendering) you should draw your skybox AFTER all opaque objects and before the transparent ones. This way you'll save a lot of overdraw and maybe shader work.

But as Simon said, disable depth writing when drawing the sky(box/dome).

Share this post


Link to post
Share on other sites
You could go for a system where the skybox is not totally stationary relative to the camera but rather each object moves around, but far more slowly than the camera is moving. This gives the appearence of further depth.

Share this post


Link to post
Share on other sites
what bout dynamic skies? clouds? etc. Are they the same or similar approach?

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
Quote:
Original post by SimonForsman
Remember: You don't have to make your skybox large enough to contain your world, just disable depthwrites and render it before anything else.
(glDepthMask(GL_FALSE);). (reenable depth writes before rendering the world)

According to some ATI paper (don't remember the title nor the link, but was something about efficient rendering) you should draw your skybox AFTER all opaque objects and before the transparent ones. This way you'll save a lot of overdraw and maybe shader work.


How?

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
Quote:
Original post by Lord_Evil
Quote:
Original post by SimonForsman
Remember: You don't have to make your skybox large enough to contain your world, just disable depthwrites and render it before anything else.
(glDepthMask(GL_FALSE);). (reenable depth writes before rendering the world)

According to some ATI paper (don't remember the title nor the link, but was something about efficient rendering) you should draw your skybox AFTER all opaque objects and before the transparent ones. This way you'll save a lot of overdraw and maybe shader work.


How?

How what? [smile]

How do you render the skybox between opaque and transparent objects? Split them into two groups and render those groups individually.

Here's the link to the document, btw. Have a look at pages 16 and 17.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!