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

1k Views Asked by At

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.

2

There are 2 best solutions below

1
PierreBdR On

Try adding:

glDisable(GL_LIGHTING);

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

1
Pencrace On

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.