PDA

View Full Version : Triangle Strip - Per Triangle color



Aliii
09-27-2013, 04:41 AM
In the old OpenGL(glBegin, glEnd), when you draw a triangle strip, there was no way to set the color per-triangle. Only per-vertex. Is this the same with shaders? I would need to draw the heightmap from trianle strips but I need different colors for each triangle, ....so the edges between them are visible. Thanks!

Dark Photon
09-27-2013, 07:16 AM
In the old OpenGL(glBegin, glEnd), when you draw a triangle strip, there was no way to set the color per-triangle. Only per-vertex. Is this the same with shaders?

With old fixed-function OpenGL, you did have glShadeModel( GL_FLAT ), and there was a convention for which vertex's color was used for the whole triangle.

What you're talking about is termed flat shading, and AFAIK the capability for it it's still there, but generalized for shaders. You can search for it in the latest OpenGL Spec:

* http://www.opengl.org/registry/doc/glspec44.compatibility.pdf

In particular, see section "13.4 Flat Shading". You can set which vertex in the primitive defines the color and other values for the whole primitive. In your GLSL shader, you mark the interpolator in your shader with the interpolation qualifier "flat" to signify that you don't want it smoothly blended across the surface of the primitive, but left fixed. See the GLSL spec for details (in particular, Section 4.5 Interpolation Qualifiers):

* http://www.opengl.org/registry/doc/GLSLangSpec.4.40.pdf

Aliii
09-27-2013, 09:14 AM
Thanks! Works fine. Thats what I wanted!