Creating a sky

Started by
8 comments, last by Lord_Evil 15 years, 9 months ago
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
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.
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.
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.
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)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
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).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
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.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
what bout dynamic skies? clouds? etc. Are they the same or similar approach?
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?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement