I render a simple mash structure with Tao (don't think this is relevant) using DisplayList.

Following code appears between

int displayList = Gl.glGenLists(1);
Gl.glNewList(displayList, Gl.GL_COMPILE);



Simplified version of the code, with removed unrelevant parts:


for (int i = 0; i < triangles.Count; i++)
    var triangle = triangles[i];

    bool ok = false;
    var normal = triangle.GetNormal(out ok); //get normal of TRIANGLE

  //this method just retrives correct color information here
    var visualData = GetVisualData(visual, 
                      visual.RenderSettings, triangle,null, false);

    //Set the color for the vertex here. Color is always the same in THIS case

    //for every vertex in triangle
    for (int vtx = 0; vtx < triangle.Vertices.Length; vtx++)
         var v = triangles[i].Vertices[vtx];
         Vertex3 v3 = v.Coord;                 
         Gl.glVertex3d(v3.x, v3.y, v3.z); //set vertex         
         Gl.glNormal3d(normal.x, normal.y, normal.z);  //set normal        




Accoring to documentation if I set the same color for all 3 vertices of the triangle it must have the solid color. But what I get is:

Screen shot

As you see the colors are not uniform across different triangles, but I'm pretty sure that in this loop the color is not changed, it remains static (I even tried to set constant int values as color , but result is always the same)


What can be possible reason of this rendering behaviour?


1 Answer 1


In immediate mode rendering in OpenGL, you open up a sequence of primitives by Begin, emit a bunch of elements in that sequence, and terminate it with End.

There's two choices on how OpenGL could have handled the emission of the elements. One way would be that a Vertex call would create an element and that subsequent calls to functions like Color, Normal, TexCoord would modify those attributes of that vertex.

That is not the case, however. The approach that OpenGL uses is that first you set all the attributes you want with those functions (Color, Normal, etc.), and then emit an immutable element with the Vertex function.

In your code, you do this correctly for Color, but your Normal changes are lagged by one vertex, resulting in inconsistent normals for a face.

In essence, set all the changed vertex attributes first, then invoke Vertex to emit a vertex with those attributes.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .