在openGL中重叠部分透明的形状 [英] overlapping partially transparent shapes in openGL

查看:175
本文介绍了在openGL中重叠部分透明的形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查我发现的这段简洁代码:

Please check this neat piece of code I found:

glEnable(GL_LINE_SMOOTH);

glColor4ub(0, 0, 0, 150);
mmDrawCircle( ccp(100, 100), 20, 0, 50, NO);

glLineWidth(40);
ccDrawLine(ccp(100, 100), ccp(100 + 100, 100));

mmDrawCircle( ccp(100+100, 100), 20, 0, 50, NO);

其中mmDrawCircle和ccDrawLine只是以某种方式绘制了这些形状[FILLED] ...(ccp表示一个点

where mmDrawCircle and ccDrawLine just draws these shapes [FILLED] somehow... (ccp means a point with the given x, y coordinates respectively).

我的问题...。是的,您猜对了,该线与圆重叠,并且都是半透明的(半透明)。因此,最终的形状就在那里了,但是重叠的部分变暗了,整体形状看起来很丑。.即,如果我使用255 alpha进行绘制,我会很好的。

My problem .... Yes, you guessed it, The line overlaps with the circle, and both are translucent (semi transparent). So, the final shape is there, but the overlapping part becomes darker and the overall shape looks ugly.. i.e, I would be fine if I was drawing with 255 alpha.

有没有办法告诉OpenGL在重叠部分渲染一个形状?

Is there a way to tell OpenGL to render one of the shapes in the overlapping parts??

(该形状显然是一个矩形,带有圆角的边缘..半圆..)

(The shape is obviously a rectangle with rounded edges .. half-circles..)

推荐答案

您可以启用GL_DEPTH_TEST并首先渲染该线,并使其更接近相机。当您在下方绘制圆形时,线条的片段将不会被触摸。
(您也可以使用模版缓冲区获得类似效果)。

You could turn on GL_DEPTH_TEST and render the line first and a little closer to the camera. When you then render the circle below, the fragments of the line won't be touched. (You can also use the stencil buffer for an effect like this).

请注意,这看起来仍然很丑陋。如果您想使用抗锯齿功能,则应该认真考虑应用哪种混合模式以及渲染基元的顺序。

Note that this might still look ugly. If you want to use anti-aliasing you should think quite hard on which blending modes you apply and in what order you render the primitives.

这篇关于在openGL中重叠部分透明的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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