简体   繁体   English

三角形条上的OpenGL不需要的褪色问题。 想要在三角形上获得均匀的颜色

[英]OpenGL unwanted color fading problem on triangle strip. Want to get uniform color over the triangle

Here's my problem. 这是我的问题。 I'm drawing a box using a GL_TRIANGLE_STRIP. 我正在使用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. 我正在使用OpenGL ES 1.1(我知道我不是最新的),并且该程序正在iPhone / iPad上运行。

Try adding: 尝试添加:

glDisable(GL_LIGHTING);

to make sure there is really no lighting even if by default. 确保即使默认情况下也确实没有照明。

I forgot to mention that I'm using the engine Sio2 Engine. 我忘了提到我正在使用引擎Sio2 Engine。 I went hardstyle and hooked the entire openGL init and redid it myself. 我采用硬式风格,并钩住了整个openGL init,然后自己重​​新进行了重新设置。 For some reason, one of the glEnable(GL_TEXTURE_2D) call was making the weird effect appear. 由于某种原因,glEnable(GL_TEXTURE_2D)调用之一使怪异的效果出现。

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. 不幸的是,我无法解释原因,但是如果您使用的是Sio2 Engine,最后会出现一些奇怪的褪色效果……那么请通过注释两个在引擎代码中启用GL_TEXTURE_2D的调用之一来检查它是否解决了。

I welcome any explanation, I don't have time to go deeper and find it myself. 我欢迎任何解释,我没有时间深入了解自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM