为什么我的彩色立方体不能与 GL_BLEND 一起使用?

发布于 2024-07-16 16:15:28 字数 1163 浏览 7 评论 0原文

当我使用 GL_BLEND 时,我的立方体未按预期渲染。

glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);

我在前面绘制一些半透明顶点时也遇到了类似的问题,这很可能是相关的。

相关:为什么我的半不透明顶点使 OpenGL 中的背景对象更亮?

它应该是这样的:

普通立方体 http://img408.imageshack.us/img408/2853/normalcube.png

这是它实际的样子:

深色立方体 http://img7.imageshack.us/img7/7133/darkcube.png

请参阅用于 创建彩色立方体,以及用于实际绘制的代码立方体

立方体是这样绘制的:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glLoadIdentity();

// ... do some translation, rotation, etc ...

drawCube();

glPopMatrix();

// ... swap the buffers ...

My cube isn't rendering as expected when I use GL_BLEND.

glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);

I'm also having a similar problem with drawing some semi-opaque vertices in front, which could well be related.

Related: Why do my semi-opaque vertices make background objects brighter in OpenGL?

Here's what it's supposed to look like:

Normal cube http://img408.imageshack.us/img408/2853/normalcube.png

And here's what it actually looks like:

Dark cube http://img7.imageshack.us/img7/7133/darkcube.png

Please see the code used to create the colored cube, and the code used to actually draw the cube.

The cube is being drawn like so:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glLoadIdentity();

// ... do some translation, rotation, etc ...

drawCube();

glPopMatrix();

// ... swap the buffers ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坚持沉默 2024-07-23 16:15:28

您可以尝试在绘制立方体之前禁用所有照明:

glDisable(GL_LIGHTING);

You could try disabling all lighting before drawing the cube:

glDisable(GL_LIGHTING);
蓝梦月影 2024-07-23 16:15:28

看起来你在第二个上启用了照明,

在绘制之前尝试使用 glShadeModel( GL_FLAT ),

It looks like you have lighting enabled on the second one,

try with a glShadeModel( GL_FLAT ) before drawing,

浅笑轻吟梦一曲 2024-07-23 16:15:28

这让我跺脚。 看起来有些顶点有一些不透明的 alpha 值。 但是,您发布的代码全部为 1. for alpha。 那么......为了进行更多调试,您是否尝试将透明颜色更改为非黑色? 说绿色?
从代码中,我怀疑照明是否打开,因为没有指定法线。

最后评论,题外话...你真的不应该使用 glBegin/glEnd (每个顶点 2 个函数调用 + 每个基元 2 个函数调用确实不是最近发展的一个好用法OpenGL)。 尝试使用 glDrawElementsQUAD_LIST,或者更好的是 TRIANGLE_LIST。 您已经为此精心准备了数据。

This has me stomped. What it looks like is that some vertices have some alpha values that are non-opaque. However the code you posted has all 1. for alpha. So... in order to debug more, did you try to change your clear color to something non-black ? Say green ?
From the code, I doubt lighting is turned on, since no normals were specified.

Last comment, offtopic... You should really not use glBegin/glEnd (2 function calls per vertex + 2 per primitive is really not a good usage of the recent developments in OpenGL). Try glDrawElements with QUAD_LIST, or even better, TRIANGLE_LIST. You already have the data nicely laid out for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文