So I just started switching over from SDL to OpenGL today and I’m having this problem which I didn’t have when I was using SDL.
When there’s a lot of stuff on the screen the whole thing goes into slow motion. And when I say a lot I mean 200+ objects, but starts to be noticeable maybe from 50.
This is how things are rendered, I have a class Renderable with a virtual void render() which is called by the RenderManager in a loop void manage() which calls render() for every Renderable on screen.
The main loop looks like this
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
_renderManager.manage();
glFlush();
SDL_GL_SwapBuffers();
and render() for the objects I’m using are only squares so
glBegin(GL_QUADS);
// Draw square with colors
glEnd();
My CPU usage or memory usage don’t seem to be high at all, it’s just like… the game is slowing down.
I guess the problem is that you are using immediate mode, you should use Vertex Arrays if you have performance problems.
We don’t know all of your code so it’s difficult to give a complete answer but using vertex arrays is surely the first step you should ensure if things go slowly.
Take a look here: http://www.songho.ca/opengl/gl_vertexarray.html
Basically the fact is that with
glBegin…glEndyou end up doing many calls to the GPU while with vertex arrays you precompute your shapes, you save them in buffers and directly draw them reducing the number of calls by a significant amount.