I am writing a code in OpenGL, in c++ on Linux, where i need to draw a several sphere in the 3D space, for drawing it I use the glutSolidSphere( GLdouble(radius), GLint(slices), GLint(stacks) )
method, everytime, in the draw function, the glutSolidSphere is called a lot of times and after the sphere is traslated in the right position.
But I have noticed that when the program draw several spheres there is a framerate problem, so i was thinking if there was a method that allow me to "store" the model of the sphere without recreate it everytime and just change position.
I am not an OpenGL expert, sorry if i have committed english language errors.
Asked
Active
Viewed 135 times
0

Daniele Tr
- 5
- 3
-
What you are talking about (I think) is called _"Instancing"_ have a read of https://learnopengl.com/Advanced-OpenGL/Instancing – Richard Critten Dec 08 '19 at 12:56
-
Probably using the instancing method would improve my program, but it was not the question I asked, maybe I expressed myself badly, in the draw function I call glutSolidSphere every time, and this in my opinion slows down the program, what I would like to create the spheres only once and in the draw method move only the position of the spheres already created – Daniele Tr Dec 08 '19 at 13:39
-
Have you tried using less slices and less stacks? – user253751 Dec 09 '19 at 11:35
-
Yes, at the end slices and stacks was also part of the problem – Daniele Tr Dec 20 '19 at 18:10
1 Answers
0
The answer of @datenwolf in this topic is perfect, he said :
In OpenGL you don't create objects, you just draw them. Once they are drawn, OpenGL no longer cares about what geometry you sent it.
glutSolidSphere
is just sending drawing commands to OpenGL.
So if you have performance issues you will need to look for others ways to improve performance like multithreading or maybe look to implement your own sphere draw function (google or stackoverflow research).
I heard that GluSolidSphere
call glBegin(…)
/ glEnd()
and these can be slow so maybe draw all your spheres with a loop so you have only one call of glBegin(…)
/ glEnd()

Community
- 1
- 1

Ben Souchet
- 1,450
- 6
- 20
-
Thanks for the question, what do you mean with glBegin() and glEnd() ? I need to do this?: ```glBegin() glutSolidSphere( GLdouble(radius), GLint(slices), GLint(stacks) ) glEnd()``` – Daniele Tr Dec 08 '19 at 14:06
-
No, you don't need, I was saying that every-time you call `glutSolidSphere()` the function do internally at beginning a call to `glBegin()` and at end a call to `glEnd()` so if you implement you own version of function to draw a sphere you can store in a list all the spheres you want to draw than do a call yourself to `glBegin()` than iterate with your own function and after do yourself the call to `glEnd()`, so you will only call one time each function. But maybe I'm wrong this is just something I read. – Ben Souchet Dec 08 '19 at 15:02