Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to create a small solar system and render it uding opengl. I got several spheres rotating around origo with planetary textures on them.

One of the planets got an atmosphere created by creating a slightly larger sphere at the same position with a texture with alpha blending.

Everything works except when the watched from a distanace it looks like black riples in the atmosphere. It's only when watched froma distance. When up close it's working perfectly.

C#
void drawAtmo()
{
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);
    glPushMatrix();
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glColor4f(1, 1, 1 ,0.5);
    glBindTexture(GL_TEXTURE_2D, shared.earthTexture1);
    gluSphere(shared.quadric, 3.2, 32, 32);
glPopMatrix();
glDisable(GL_BLEND);
}
Posted

1 solution

It's likely caused because your using a 16-bit depth buffer, which means that from a distance there isn't enough detail in the depth buffer to differentiate between the planet and its atmosphere so they're being drawn a little randomly.

I'd like to mention that the depth buffer doesn't store depth information with the same degree of accuracy across the whole scene, objects near the screen will have more precision than those towards the back of scene.

The solution is to either use a 24-bit depth buffer, or adjust your zNear and zFar values to squeeze some more precision out of the depth buffer, so it's a pretty simple fix. If your already using a 24-bit depth buffer then you should adjust your near and far values, change z-near so it is not as close to 0 and reduce the distance between zNear and zFar

OpenGL FAQ on the depth buffer[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900