PDA

View Full Version : Spheres and GLSL



Cjacchus
02-15-2012, 05:44 AM
Hello,
I'm sorry to disturb you with such a question, but I've been thinking about this for a while and wasn't able to find an answer.
At a first moment, I was learning about OpenGL and I didn't know anything about GLSL, even it's existence. So I was using many deprecated functions without knowing it.

Now I'm trying to learn how to use an OpenGL 4.2 context in a core profile, trying to avoid things like pushmatrix, or glBegin, and trying to explore VBO, VAO and GLSL in general.

I came to doubt when I got tired of drawing triangles and polygons in general and started thinking about spheres and cylinders.
How should I proceed in such a case? Because I can't think in a way to pass the vertex data to the VBO with, for instance, glutSolidSphere. Should I create an algorithm to draw a sphere made of triangles?
Any help is appreciated, thanks in advance.

McLeary
02-15-2012, 07:16 AM
glutSolidSphere deals with the drawing process of a sphere for you. There is no easy way to capture the mesh generated by this function and pass to a VBO. You going to generate your own sphere meshes. Start with the parametric equation of an sphere. Also, take a look at this tutorial on how to generate a so called geosphere.

http://sol.gfxile.net/sphere/index.html

Cjacchus
02-15-2012, 09:18 AM
Thank you, I really appreciate your help!
This isn't the simplest way, but sometimes it's good not to avoid the hard work, this tutorial is really great.
I'll try it and I tell you if it works.

Gustavo R. A.
02-15-2012, 10:56 AM
You could also take a look at http://www.arcsynthesis.org/gltut/Illumination/Tutorial%2013.html
and the other tutorials there. This particular one opened my mind to a lot of cool things that can be done once you start using shaders.