OpenGL Alpha混合 [英] Opengl alpha blending

查看:111
本文介绍了OpenGL Alpha混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个小型的太阳系,并在opengl中对其进行渲染.我得到了几个围绕origo旋转的球体,上面带有行星纹理.

其中一颗行星通过在相同位置创建具有Alpha混合纹理的稍大的球体而创建了大气.

一切正常,除了从远处观看时,它看起来像黑色的涟漪在大气中.只有从远处观看.当关闭时,它可以正常工作.

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.

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);
}

推荐答案

可能是由于您使用16位深度缓冲区造成的,这意味着从远处看还不够深度缓冲区中的细节,以区分行星和大气,因此它们会被随机绘制.

我要提到的是,深度缓冲区在整个场景中不会以相同的精度存储深度信息,靠近屏幕的对象将比朝向场景后面的对象具有更高的精度.

解决方案是使用24位深度缓冲区,或者调整zNear和zFar值以从深度缓冲区中挤出更多精度,因此这是一个非常简单的解决方案.如果您已经在使用24位深度缓冲区,则应调整近距和远距值,更改z-near使其不那么接近0,并减小zNear和zFar之间的距离

有关深度缓冲区的OpenGL常见问题解答 [
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[^]


这篇关于OpenGL Alpha混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆