Opengl透明度问题 [英] Opengl Transparency problem

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

问题描述

Hello Everyone,

  void  mainRender()
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderSTLs();

glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

renderPoints();

}





我需要实现相互透明度。如果点的alpha值改变了,它应该显示它后面的stls。在上面的例子中它是成功的,因为stls在点之前呈现,因此该点可以与stls混合。但是,如果我更改stls点的透明度值,则不会通过它显示。我猜是因为在渲染之前没有任何东西可以与stls融合。

我需要两个案例才能工作。虽然通过首先调用renderPoints()更改render函数调用然后renderSTLs()将使stl transprency工作。



点和stls的透明度如何工作同时。我陷入了这个问题。请有人帮忙。



谢谢,

Arpan

解决方案

< pre lang =c ++> void mainRender()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderSTLs();

glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
if (bPointThroughSTL)
{
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
}
其他
{ // 此处,目标缓冲区(STL)中的alpha用于与点混合。
glBlendFun(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);

}

renderPoints();
}





glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);

不会工作,因为目的地的alpha值缓冲区(FrameBuffer)总是1.0。



如果你可以通过渲染到纹理方法[http://www.songho.ca/opengl/gl_fbo.html ,着色器可以根据需要混合这些纹理。


Hello Everyone,

void mainRender()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    renderSTLs(); 

    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

 renderPoints();

}



I need to achieve mutual transparency. if alpha value for points is changed it should show the stls behind it. In the above case it is a success because the stls is rendered before the points, so the point can blend with stls. But if I Change the transparency value for stls points are not shown through it. I guess because there is nothing to blend with for stls before it is render.
I need both the cases to work. though changing the render function call by first calling renderPoints() and then renderSTLs() will make the stl transprency work.

how can both the transparency of points and stls works at the same time. I am stuck in this problem. Please somebody help.

Thank you,
Arpan

解决方案

void mainRender()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    renderSTLs(); 
 
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    if( bPointThroughSTL )
    {
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
    else
    { // Here alpha from Destination buffer( STL ) is used to blend with points.
      glBlendFun(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);

    }
 
    renderPoints();
}



glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
wont work because alpha value in destination buffer(FrameBuffer) will be always 1.0.

If you can prepare two textures with these STLs and points by rendering to texture method[http://www.songho.ca/opengl/gl_fbo.html], a shader can blend these textures as you required.


这篇关于Opengl透明度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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