I have a very simple 2D draving. I use DisplayList to draw a small box onto the screen (20x20pix) and move it only in X and Y. But my simple app takes about 98% of CPU. why?? Is it common to OpenGL apps?
I have tried to use the multimedia timer to call the draving function every 20ms, but now the flickering occurs - it looks like the previous frame is displayed before swapbuffers occurs. I also used the GL_EXT_Swap extension, to synchronize to the vsync of monitor, but it doesn’t change a thing besides the speed of movement.
What is wrong? what else can I do to save some CPU power (I need to run a server in the thread, but now when I do this, the movement is very slow).
What is the best scheme to do this kind of application which uses OpenGL and sockets?
(bloking or non-bloking sockets).
Ane tutorial or code?
The flickering probably is a result of not using doublebuffering and if you render a small amount of polygnos and have swap_interval active you shouldnt get 100% cpu use. but for things that needs to give away processortime and still animate i use to have a timer to refresh the screen.
The fact that the animation slows down is probably because you change che animation values with a fixed value per frame, thats a bad idea even if you have v-blanc syncronization ative, because you dont know it the mashine will have 60 or 120Hz refreshrate, multiply the animation value with the deltatime ( time between frames) to get accurat animationspeed in time not in frames.
I use doublebuffer for sure (if I dissable it in PIXELFORMAT the result is even worst).
The animations slow down when I turn on the server so the CPU is overloaded.
IE: if I don’t use a timer to save CPU time, and the server thread is off, then everything is smooth (98% CPU usage).When I turn on the server thread, animation slowing 3-5 times down.
That’s why I wanted to use the timer to save CPU power (so I call display function every ie.20ms), but I get flickering.
Are you using swap control or some other extension?
What are the parameters your using for that function. Plus remove the socket stuff while your testing.
I use WGL_EXT_swap_control extension, with the parameter set to 1 (or more sometimes).
Sockets are dissabled - they are created in thread (server thread) but the thread isn’t started at all while I’m testing this.
If would be ok, if the movement wasn’t smooth, but without the effect of seeing the “previus frame” on the screen.