
Total NOOB....
Posted Friday, 16 April, 2010 - 14:53 by TheNerd inHello all,
Can someone point me to a tutorial that would show me how to use the latest version of OpenTK to display basic primitives (sphere, Cube, cylinder, etc) ??? In the old OpenTK.Compatibility I know those functions existed in the Glu class, but as far as I know that namespace is supposed to be deprecated... so how do you do the same thing in the new one??????
Thanks!!!!


Comments
Re: Total NOOB....
MainWindow.cs
Program.cs
Re: Total NOOB....
Ah so you are saying I need to find the mathematical formulas and build them myself because there's no longer any GLUT emulation in OpenTK?
It'd be nice to be able to do something like GL.Sphere(Radius, VectorOfLocation) and have that return the vertices or a vertice array.
hmm maybe I should build and contribute :)
Re: Total NOOB....
Hi.
Ah so you are saying I need to find the mathematical formulas and build them myself because there's no longer any GLUT emulation in OpenTK?
Look in your OpenTK-Folder(bin) and you will see: OpenTK.Compatibility.dll is part of OpenTK until now. :-)
but as far as I know that namespace is supposed to be deprecated... so how do you do the same thing in the new one?
Yes, about years. So do it as before, until a successor is to come (on the way).
It'd be nice to be able to do something like GL.Sphere(Radius, VectorOfLocation) and have that return the vertices or a vertice array.
hmm maybe I should build and contribute :)
You should do it. ;-)
Re: Total NOOB....
OK so I ported over some code I found floating out there to do a hemisphere (works well for sky domes!) with texturing. This will also work to build a complete sphere, although I am not sure if its inefficient or not. This was ported directly from http://www.swiftless.com/tutorials/opengl/sphere.html
First, a struct:
Now, the method:
And then to render it I do something like this (I colored the two different halves differently to illustrate each call):
how can I improve this?
Re: Total NOOB....
Two enhancements I can think of:
The code below implements this for a hemisphere. It also supports ellipsoids, which is why it calculates normals separately:
You can render this trivially using immediate mode:
or you can load the data into VBOs and enjoy a couple orders of magnitude higher performance.
Re: Total NOOB....
Using Fiddler's example, I can generate a hemisphere perfectly (works great for a skydome!), but I can't figure out for the life of me how to generate a FULL Sphere from that. Any pointers?
Re: Total NOOB....
Nevermind, I figured it out :) Just change:
to
Re: Total NOOB....
Thanks for this code!
One change I would make is that you are making a vertex for the 0th segment, and then doing it again for the last segment. This means that you're duplicating data that you don't need to.
If you change:
double theta = (x / (segments - 1)) * 2 * Math.PI;To:
double theta = (x / (segments)) * 2 * Math.PI;And change this:
for (byte x = 0; x < segments - 1; x++)To this:
for (byte x = 0; x < segments; x++)And also change each of these:
data[i++] = (ushort)((y + 0) * segments + x + 1);Into this:
data[i++] = (ushort)((y + 0) * segments + (x + 1) % segments);Then you won't duplicate data.
I would recommend testing this with a 4 segments. In your original code, you'd see a 3-sided figure. With my code, you should see a 4-sided figure. Note that with my code, you actually produce the same amount of vertex data, but "rings" more element data.