OpenGL 三角形带上出现不必要的褪色问题。想要在三角形上获得均匀的颜色

发布于 2024-09-07 13:05:19 字数 2132 浏览 4 评论 0 原文

这是我的问题。我正在使用 GL_TRIANGLE_STRIP 绘制一个盒子。不涉及纹理、材质和着色器。我只是渲染彩色三角形。

您可以在这里看到它的样子: 失败框

但正如你所看到的,我有一些明显的褪色问题。也没有激活照明。

这里是我用来初始化和渲染盒子的代码。

//here init code
for(list<Particle*>::iterator p = this->shapes[this->activeShape].particles.begin();
                p != this->shapes[this->activeShape].particles.end(); p++)
            {
                float yValue = 20.0f;

                this->vertexArray[this->activeShape][current].Position.x = (*p)->x0.x;
                this->vertexArray[this->activeShape][current].Position.y = -yValue;
                this->vertexArray[this->activeShape][current].Position.z = (*p)->x0.y;


                this->vertexArray[this->activeShape][current + listSize].Position.x = (*p)->x0.x;
                this->vertexArray[this->activeShape][current + listSize].Position.y = yValue;
                this->vertexArray[this->activeShape][current + listSize].Position.z = (*p)->x0.y;

                current++;
            }


        // render code
                glFrontFace(GL_CW);
                glEnable(GL_BLEND);

                glVertexPointer(3, GL_FLOAT, sizeof(LsmVertexColor), &this->vertexArray[this->activeShape][0].Position);
                glEnableClientState(GL_VERTEX_ARRAY);

                glColor4f(SCULPTY_R, SCULPTY_G, SCULPTY_B, SCULPTY_A);

                glDrawElements(GL_TRIANGLE_STRIP, 20, GL_UNSIGNED_SHORT, &this->indexArray[this->activeShape][0]);
                glDrawElements(GL_TRIANGLE_STRIP, 20, GL_UNSIGNED_SHORT, &this->indexArray[this->activeShape][22]);
                glDrawElements(GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_SHORT, &this->indexArray[this->activeShape][44]);
                glDrawElements(GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_SHORT, &this->indexArray[this->activeShape][54]);

我正在使用 OpenGL ES 1.1(我知道我不是最新的)并且该程序正在 iPhone/iPad 上运行。

Here's my problem. I'm drawing a box using a GL_TRIANGLE_STRIP. There is no texture involved, no material and no shaders. I'm just rendering colored triangle.

You can see what it looks like here : Fail box

But as you can see, I've some clear color fading problem. There is no lighting activated either.

Here the code I use to init and render the box.

//here init code
for(list<Particle*>::iterator p = this->shapes[this->activeShape].particles.begin();
                p != this->shapes[this->activeShape].particles.end(); p++)
            {
                float yValue = 20.0f;

                this->vertexArray[this->activeShape][current].Position.x = (*p)->x0.x;
                this->vertexArray[this->activeShape][current].Position.y = -yValue;
                this->vertexArray[this->activeShape][current].Position.z = (*p)->x0.y;


                this->vertexArray[this->activeShape][current + listSize].Position.x = (*p)->x0.x;
                this->vertexArray[this->activeShape][current + listSize].Position.y = yValue;
                this->vertexArray[this->activeShape][current + listSize].Position.z = (*p)->x0.y;

                current++;
            }


        // render code
                glFrontFace(GL_CW);
                glEnable(GL_BLEND);

                glVertexPointer(3, GL_FLOAT, sizeof(LsmVertexColor), &this->vertexArray[this->activeShape][0].Position);
                glEnableClientState(GL_VERTEX_ARRAY);

                glColor4f(SCULPTY_R, SCULPTY_G, SCULPTY_B, SCULPTY_A);

                glDrawElements(GL_TRIANGLE_STRIP, 20, GL_UNSIGNED_SHORT, &this->indexArray[this->activeShape][0]);
                glDrawElements(GL_TRIANGLE_STRIP, 20, GL_UNSIGNED_SHORT, &this->indexArray[this->activeShape][22]);
                glDrawElements(GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_SHORT, &this->indexArray[this->activeShape][44]);
                glDrawElements(GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_SHORT, &this->indexArray[this->activeShape][54]);

I'm using OpenGL ES 1.1 (I know I'm not up-to-date) and the program is running on iPhone/iPad.

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

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

发布评论

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

评论(2

柏林苍穹下 2024-09-14 13:05:19

尝试添加:

glDisable(GL_LIGHTING);

以确保即使默认情况下也确实没有照明。

Try adding:

glDisable(GL_LIGHTING);

to make sure there is really no lighting even if by default.

心的憧憬 2024-09-14 13:05:19

我忘了提及我正在使用引擎 Sio2 Engine。我采取了硬性风格,挂钩了整个 openGL init 并自己重新编写了它。由于某种原因,glEnable(GL_TEXTURE_2D) 调用之一导致出现奇怪的效果。

不幸的是,我无法解释原因,但如果您使用 Sio2 引擎并最终出现一些奇怪的颜色褪色效果...然后通过注释引擎代码中启用 GL_TEXTURE_2D 的两个调用之一来检查它是否已解决。

我欢迎任何解释,我没有时间自己深入寻找。

I forgot to mention that I'm using the engine Sio2 Engine. I went hardstyle and hooked the entire openGL init and redid it myself. For some reason, one of the glEnable(GL_TEXTURE_2D) call was making the weird effect appear.

I unfortunately can't explain why, but if you're using Sio2 Engine and end up with some strange effect of color fading... then check if it is solved by commenting one of the two calls to enable GL_TEXTURE_2D in the engine code.

I welcome any explanation, I don't have time to go deeper and find it myself.

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