View Full Version : Plot 3D : both solid fill and wireframe triangles
10-23-2006, 03:36 AM
I'm a newbie in OpenGL. I'm trying to create a C# library to plot (X,Y,Z) surface made from connected triangles (I just pass axis X and Y array.
My specs are:
* each triangle just use a plain color depending on their z-value (gradient: red to blue) => no lighting / shade effect.
* the resulting surface is "solid" (filled) along with its wireframe (in black).
* labeling (text and decimal) on axes shall be displayed.
* Do you know any existing open-source implementation for .NET ?
* Do you recommand to use GL_TRIANGLE_STRIP or GL_TRIANGLES to build the surface ?
* How to both fill a triangle AND draw its black border ? I couldn't find any satisafctory answer...
10-23-2006, 06:20 AM
1. i know that there are, but i haven't used C# myself, take a look at nehe.gamedev.net, i know that there are some C# openGL examples there.
2. GL_TRIANGLES is definitely easier to use than GL_TRIANGLE_STRIP.
3. simple first draw them as solids, then draw them as wireframe, perhaps with some polygon offset if needed.
10-23-2006, 06:51 AM
I'll give a try to the polygon offset because drawing polygon fill+line does not look professional at all.
I actually find another thread talkingabout this :
but obviously there are still limitations ... so NO definitive solution to this ???
10-23-2006, 07:37 AM
Values 1.0 1.0 seem to be good for a lot of cases.
10-23-2006, 11:17 PM
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 ?
10-24-2006, 05:25 AM
Triangle strips can be a bit better for perf, and well suited for regular grids.
For arbitrary triangles, stay with GL_TRIANGLES for a start.
Do you have performance problems now ?
Try display lists, or VBO.
10-24-2006, 05:43 AM
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.
EDIT: Forgot the link ;)
10-24-2006, 10:26 PM
Ok thanks for the answers.
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)
10-25-2006, 12:46 AM
>>the code uses the HSL color space to move the hue according to the z-value
Most likely you have a bug in this part of the code.
10-25-2006, 01:32 AM
I guess by default opengl windows lib works at 24 or 32 bits color depth ?
10-25-2006, 09:49 PM
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 (http://www.plot3d.net/gallery.html)
Just watch the values used for the far and near clip planes, especially the near clip plane.
Waooh! Amazing!!! And very smooth !
I'm trying, to make quite the same but in C#... Is it a bad idea to ask you a simple question ?
As for the color effect, you are using lighting, right ? What is your algo for coloring ? Are you using HSL ?
Btw, do you use GL_TRIANGLES or GL_TRIANGLE_STRIP ?
Thanks for the beautiful plots !
10-28-2006, 06:46 AM
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.
10-29-2006, 11:00 AM
Thanks a lot for the explanations. As for the performance, I'm not sure I can reach yours. My plots (32x32) seem way slower....
Do you enable / disable anything special ?
10-30-2006, 09:03 PM
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.
10-30-2006, 10:33 PM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.