Page 1 of 1

Resource managing in OpenGL

Posted: Wed Jan 28, 2009 4:53 pm
by cloudncali
So I have been working in OpenGL for a few days and have a working animation and masking system working. But when I look at the program in the presses manager it says that its taking up about %50 CPU space!

Is this normal for OpenGL, or could it be my animation system. All I do for my animation system is make an object with all the frames Gluint textures. And it swaps the current texture when the timer goes pass the amount of time per frame.

Any one know why my program is taking up so much memory, I didn’t want to just past my code up here and say “what’s wrong with this” but if some one requests my code I will show it.

Re: Resource managing in OpenGL

Posted: Wed Jan 28, 2009 5:10 pm
by LeonBlade
It shouldn't be unless your computer fails...
Post your code

Re: Resource managing in OpenGL

Posted: Wed Jan 28, 2009 5:42 pm
by cloudncali
Source.rar

That is the entire source code for the program, so far i only have one animated image and one non animated image that just rotates. so it doesn't seem like something that would be very resource needy. so its probably something in my code that's not very efficient.

just a quick overview:
App.h and App.cpp is the main program code, Main is just there for the Main Function.
GameObject.h has all the different classes for game objects(the three are Graphic object, Animated Graphic object, and Animation)
Animation object is just for animation
Animated Graphic Object has an Animated object in it and has other object properties.
Edit: An update and more info, i manage to lower that %50 to about %20 buy adding SDL_Delay(50) after the output funtion but i feel like that is a temporary fix
oh i forgot to mention that this is SDL+OpenGL not pure OpenGL

Re: Resource managing in OpenGL

Posted: Thu Jan 29, 2009 8:49 am
by Falco Girgis
I have a feeling that there's nothing wrong with your code. OpenGL just is resource heavy (in the CPU department).

Re: Resource managing in OpenGL

Posted: Thu Jan 29, 2009 9:14 am
by Amarant
First of, there is no such thing as CPU space.
CPU usage is measured over time and 50% CPU usage means that 50% of the time the CPU spends executing anything is spent on your program.

So I don't think this has anything to do with OpenGL or something that's wrong with your program.
You're probably just not limiting the framerate of your program and that's why it's using all the cpu time that's available.

I suspect you're machine is equipped with a dual core processor, which is why only 50% (1 core) of the CPU time is used.

Edit:
If your main game loop is like this:

Code: Select all

while(gameIsRunning)
{
    // do opengl stuff
}
It's always going to use as much CPU time as is available, regardless of what you do in that loop.
(Except for actively telling the Operating System to stop executing your program for a while, which is what SDL_Delay does.)

So it's not really a big deal if 50% of CPU time is used.

Re: Resource managing in OpenGL

Posted: Thu Jan 29, 2009 11:40 am
by cloudncali
ok thanks for the help.but now Ihave another problem related to OpenGL, I have a for some reason with my working set up I have 1 animated graphic and 2 static graphics(one is rotating with OpenGLs rotate function). But this causes the game to become abnormal slow, like the rotating graphic lags like non other. I will look into this more later, but if any one knows what could be causing the game to lag please tell me what i can do different.