Preventing Vertex colors from blending?


I am attempting to create a cel-shading effect using OpenGL. I began experimenting with the NeHe example, which you can find here:

Soon after playing around with it, I noticed that it had a flaw… it was providing the shading by mapping a texture… so I edited it to load a texture, and map that instead. And instead of using the texture, it should now just use a color, based on the old 1D texture it would use.

All of that seems to work flawlessly. However, my problem is, is that the colors for the vertexes are blending in! This creates a pseudo-photo-realistic render, completely opposite of what I am looking for!

Here, you can see the textured model (not a very detailed texture though…) without glColor applied to the vertexes:

And here, you can see what happens when I am using glColor on them:

As you can see, the color blending is causing problems… making it look more like a 3d object, than a drawing.

For clarification, glDisable(GL_BLEND) is being called, directly before glBegin…

Any help is appreciated… Thanks!

That’s exactly the reason why you normally use a texture for this kind of effect. OpenGL always interpolates everything linearly at the inside of a polygon.

You only tell OpenGL the color at the vertices, it has no way of figuring out what color you want at the inside, so it just interpolates. So you have to use a texture, to create this sharp edge.

Why do you think using a texture is a flaw in the algorithm? I don’t think there is any other way to do this effect (other than really highly tesselated meshes, but that would be very slow).

Thanks for your answer.

So, in order to create a cel-shaded look, I must use textures for the lighting? That would mean that I have to implement multi-texturing I guess, if I want to have my own “skin” on the model…

In that case, could someone point me to an introduction to that?

Actually the best thing to use is a fragment shader, with it you can implement some pretty detailed and accurate cell shading that even accounts for ambient occlusion.