PDA

View Full Version : Is glutSolidSphere deprecated?



zzzhhh
11-15-2017, 05:46 PM
... Seems not because I googled this question but found no answer. However, when I tried to use this function, it seemed that I have to use deprecated OpenGL functions like glMatrixMode, glPushMatrix, glPopMatrix, glRotatef and glTranslatef to control its position. I guess glutSolidSphere is nothing special than approximating a true sphere by polygons when drawing it. What I want to do is to use modern OpenGL pipeline to control the position of the polygon created by glutSolidSphere without having to creating it all by myself. If it's possible, how can I make the approximated vertices from glutSolidSphere enter the normal vertex shader (written by GLSL 4.5 for example) so that I can control their positions as usual in vertex shader (e.g., transfer only parameters of the model view matrix from CPU, create this matrix in vertex shader, multiple the mv matrix with vertex positions and output the results)? Please note that I am not asking how to approximate a sphere by a polygon on my own, but how to make use of the existing polygon created by glutSolidSphere. Thank you for your help.

Dark Photon
11-15-2017, 08:23 PM
It at the very least uses the legacy vertex attributes (e.g. GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, etc.).

So if you're using a context created using the OpenGL core profile (which strips away the old stuff), forget it.

However, if you're using a context created using the OpenGL compatibility profile (the default), and you're using shaders which make use of the old fixed-function attributes (e.g. GLSL or ARB/NV assembly), then you can probably use glutSolidSphere().

Note that on NVidia GL drivers, the fixed-function attributes are aliased on top of the generic vertex attributes, so NVidia drivers are the only ones where you can use generic vertex attributes in your GPU shaders and have those pick up the fixed-function vertex attributes setup on the CPU side.

All that said, there's nothing that complex going on inside glutSolidSphere(). You can download any one of a number of open source GLUT implementations, and adapt their glutSolidSphere() code to function well with whatever level of OpenGL capability your app supports, freeing you from all the above considerations.

GClements
11-16-2017, 10:59 AM
However, when I tried to use this function, it seemed that I have to use deprecated OpenGL functions like glMatrixMode, glPushMatrix, glPopMatrix, glRotatef and glTranslatef to control its position. I guess glutSolidSphere is nothing special than approximating a true sphere by polygons when drawing it.
Correct. The original GLUT draws it using glVertex() and glNormal(). More recent versions of FreeGLUT will use modern OpenGL (VBOs etc) where appropriate, with the legacy approach as a fall-back.

If you're using a version which uses glVertex() etc with OpenGL 2 or with OpenGL 3+ compatibility profile, you can either use the legacy matrix functions or a vertex shader (which will need to use gl_Vertex and gl_Normal to obtain the position and normal vectors respectively).

If you're using OpenGL 3+ core profile, the legacy version simply won't work.