Different color on each side of a polygon

How do you draw a polygon with two colors, one on the outside and the other on the inside?

I know you can draw two polygons, but won’t this cause z-fighting? This will surely affect drastically the speed of the application.

Does anyone know a better way to do this?

Thanks in advance,

Billy.
http://planeta.clix.pt/billy/

Set color of one face of the triangle.
Enable back face culling (glEnable(GL_CULL_FACE)), and cull back faces (glCullFace(GL_BACK)).
Draw the triangle(s).
Set color of the other face.
Change cull face to cull the front faces (glCullFace(GL_FRONT)).
Draw the same triangle(s) again.

No Z-fighting, and no extra overdraw.

Hello!

> and no extra overdraw.

But you are still drawing the triangle twice, aren’t you?

-nemesis-

Thanks for your post Bob but I have the same doubt as nemesis.

It solves the z fighting problem you mentioned, and there’s no overdraw, although you draw it twice only one side is visible the other is culled.

There is another way though.

You use two sided lighting and draw once, OpenGL would handle it. That’s what all that material FRONT & BACK malarkey is for. If you have no lighting then I suppose the EMISSION or AMBIENT material terms would do, and you could use glColorMaterial to change them on the fly.

Beware though, some manufacturers cripple this feature to help sell more expensive graphics cards to the CAD indistry, so it might be slow or broken, on oohh… say an NVIDIA card that wasn’t a Quadro or DCC class board.

You have been warned.

I was wondering…

what should be faster, drawing two faces (culling) or drawing one textured face…?

-nemesis-

But you are still drawing the triangle twice, aren’t you?

Yes, I pass the data of the model twice. But if you draw it in two passes, first removing back faces, then removing front faces, you only draw any given triangle once, and ONLY once. That is because a triangle is either front facing or back facing. Not both front and back facing, not neither front nor back facing.

And where did you get texturing from? Texturing won’t help. Either the culling method I described, or the lighting method dorbie described. And only you can answer which one is faster; try both metods and see what happens. My culling method is not going to be any slower than a single pass, unless you are geometry limited.

Just to make it clear. I said extra overdraw. A regular model has some amount of overdraw, but my method does not give you any more overdraw. Just more data passed to OpenGL.

Oh! excuse me I didn’t understand the question!
I thougth he was asking about drawing a poly with different colors in the middle and in the edge.
I get it now!
Yeah, texturing has nothing to do here

-nemesis-

[This message has been edited by nemesis (edited 01-07-2002).]