The use of glPolygonOffset(1,1) seems satisfactory at this time.
zeoverlord says that GL_TRIANGLES is definitely easier to use than GL_TRIANGLE_STRIP. Ok but what about performance in my case (solid fill + wireframe) : will it improve ?
For using C# with OpenGL, you should have a look at the Tao framework. It comes with tons of examples, including a C# implementation of the NeHe tutorials.
I’ll take a look at Tao : does it provide code example of efficent 3d plotting (solid fill + wireframe) ?
I got another problem : coloring the triangles. I choose to paint them each with a uniform color depending on their z-value. From blue to red - how surprising
My solution is based on a color gradient : for that the code uses the HSL color space to move the hue according to the z-value (float between 0-red and 0.666-blue). What I don’t understand is that if I lower the saturation and brightness, the plot becomes completely white !!??!
Is that linked to the color depth associated with my opengl scene ? Am I in 256 colors only ? How can I check and how to change it ??? (I couldn’t figure that out)
You should be able to get descent results for most applications using glPolygonOffset.
For example the graphs on this page were created using glPolygonOffset; plot page
Just watch the values used for the far and near clip planes, especially the near clip plane.
Actually the algorithm used to color the surface is quite simple and I wouldn’t necessarily recommend it, since I’ve been meaning to replace it altogether.
Basically in RGBA mode the R,G,B values are determined by dividing the grid vertex value by the larger value of the graph range or domain.
So for example R was determined by the grid’s x value divided by the larger absolute value of xmax or xmin, and then just normalized to a value between 0 and 1, as the arguments to GLColor3f should be in that range. The G & B values are determined the same way using the y and z grid values. You can also set one the variables R,G,B to 1 and emphasize that color. I did use lighting but it doesn’t matter either way.
I used both triangles and triangle strips, triangle strips for the smooth surface and triangles for the wireframe.
Of course you don’t have to use triangle strips at all, but the triangle strips will improve performance, especially on a filled surface.
I can’t think of anything special to enable/disable. It’s hard to say why it should seem slow. I wrote the program in C++, but I think C# should be of comparable speed. It is difficult to ascertain performance issues, so many factors could be involved. The algorithms, the programming language, the compiler optimizations, etc.
I think it best to just do your program and when you have it working the way you like it go back and begin optimizing the algorithms.
You should probably avoid immediate mode under .NET.
All OpenGL calls under .NET involve the interop layer and associated marshaling overhead, which you can normally disregard, but when issuing hundreds or thousands of glVertex calls in a loop, the frame rate can really take a beating.
Take the VBO plunge under .NET (you probably will anyway), or more generally, try to avoid Pinvoke in performance critical areas.