Jump to content
  • Advertisement
Sign in to follow this  
smattey

Lighting problems with a SkyBox

This topic is 5010 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, I am creating a scene containing some particle systems have just added a textured SkyBox to my scene. Before the SkyBox was put in the particle systems looked fine but now the colours of the particles look dull as if the light isn't getting in the skybox correctly. When I draw the skybox without the top and bottom BMPs, the light gets in fine and the particle systems are the corret colour. I have been experimenting with glEnable(GL_LIGHTING) but I think I may be putting it in the wrong place. Any help will be greatly appreciated. The code I am using is below: This is in InitGL() // Load the textures for the SkyBox Image* texture = new Image("textures/space_front.bmp"); SkyboxTexture[0] = texture->setTexture(); texture = new Image("textures/space_back.bmp"); SkyboxTexture[1] = texture->setTexture(); texture = new Image("textures/space_left.bmp"); SkyboxTexture[2] = texture->setTexture(); texture = new Image("textures/space_right.bmp"); SkyboxTexture[3] = texture->setTexture(); texture = new Image("textures/space_bottom.bmp"); SkyboxTexture[4] = texture->setTexture(); texture = new Image("textures/space_top.bmp"); SkyboxTexture[5] = texture->setTexture(); The method that draws my skybox is: void Draw_Skybox(float x, float y, float z, float width, float height, float length) { glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); // Center the Skybox around the given x,y,z position x = x - width / 2; y = y - height / 2; z = z - length / 2; // Draw Front side glBindTexture(GL_TEXTURE_2D, SkyboxTexture[0]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z+length); glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y+height, z+length); glTexCoord2f(0.0f, 1.0f); glVertex3f(x+width, y+height, z+length); glTexCoord2f(0.0f, 0.0f); glVertex3f(x+width, y, z+length); glEnd(); // Draw Back side glBindTexture(GL_TEXTURE_2D, SkyboxTexture[1]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f(x+width, y, z); glTexCoord2f(1.0f, 1.0f); glVertex3f(x+width, y+height, z); glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y+height, z); glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z); glEnd(); // Draw Left side glBindTexture(GL_TEXTURE_2D, SkyboxTexture[2]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y+height, z); glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y+height, z+length); glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z+length); glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z); glEnd(); // Draw Right side glBindTexture(GL_TEXTURE_2D, SkyboxTexture[3]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x+width, y, z); glTexCoord2f(1.0f, 0.0f); glVertex3f(x+width, y, z+length); glTexCoord2f(1.0f, 1.0f); glVertex3f(x+width, y+height, z+length); glTexCoord2f(0.0f, 1.0f); glVertex3f(x+width, y+height, z); glEnd(); // Draw Up side glBindTexture(GL_TEXTURE_2D, SkyboxTexture[4]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x+width, y+height, z); glTexCoord2f(1.0f, 0.0f); glVertex3f(x+width, y+height, z+length); glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y+height, z+length); glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y+height, z); glEnd(); // Draw Down side glBindTexture(GL_TEXTURE_2D, SkyboxTexture[5]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z); glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z+length); glTexCoord2f(1.0f, 1.0f); glVertex3f(x+width, y, z+length); glTexCoord2f(0.0f, 1.0f); glVertex3f(x+width, y, z); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); }

Share this post


Link to post
Share on other sites
Advertisement
You're probably going to want to disable lighting and fog before you render your skybox, and turn it back on after you do.

Share this post


Link to post
Share on other sites
What do you mean the light isn't "getting in" the skybox? When rendering a skybox, lighting should be disabled (it should usually be disabled for a particle system as well).
Quote:
When I draw the skybox without the top and bottom BMPs, the light gets in fine and the particle systems are the corret colour

Do you mean the sides of the box that are rendered behind the particle systems? That would just be because you were blending the particles with a solid color background before, but now you are blending with the skybox. You would need to fix your blending if that's the case.

There's no way that light wouldn't be able to "get in" if you render the top and bottom of the skybox unless you are using something besides normal OpenGL lighting (shadow volumes, shadow maps, etc), but for some reason I doubt that's what you are doing.

EDIT: Also when posting long pieces of code, put source tags around it like this
[ source ]
code
[ /source ]
but without the spaces between between the brackets and letters.

Share this post


Link to post
Share on other sites
Cheers for the help people. I have just disabled Textures before the particles are drawn and this seems to have done the trick! Now just got to make my particle system look like a fountain :S

Thanks

Stephen

Share this post


Link to post
Share on other sites
I have been looking for the perfect "tropical" skyboxes for my scene and have not found them yet, so I finally took the advice I'd seen given here and built my own with terragen. It will take you about 1 hour or less to get a good skybox that is just right for your scene, and then another 15 minutes or so of rendering good quality images :-)

Terragen
Skybox tutorial for terragen

hth
F451

Share this post


Link to post
Share on other sites
Cheers mate, managed to find a site where I could download some pretty decent SkyBoxes, don't know if its of any use to you now?!

http://www.planetquake.com/simland/pages/materials.htm

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by smattey
Cheers for the help people. I have just disabled Textures before the particles are drawn and this seems to have done the trick! Now just got to make my particle system look like a fountain :S

Thanks

Stephen

Would it not be easier and safer just to call:

glBindTexture(GL_TEXTURE_2D, 0);

instead of disabling Textures entirely (and then having to enable them again)?

"Texture names are unsigned integers with the value zero reserved to represent the default texture for each texture target."

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Are there cases where they behave differently? Binding with Zero seems to draw as if texturing is diabled where I've used it.
(Sorry about anon posting, I'm waiting for the stupid confirmation e-mail to arrive)

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!