|
From: Per W. <pw...@ia...> - 2004-02-27 15:41:22
|
Unless this is a movie viewer or similar, where the drawed material requires a fixed frame rate, you shouldn't create the code for a fixed frame rate, since you can't know the speed of the machine, and amount of other programs currently needing processing time. You might use GetTickCount() to getch which millisecond you started draw. When the thread has drawn everything, it calls GetTickCount() again. The difference between these two represents number of used ms. You may then Sleep(xx-consumed) ms. Call GetTickCount() and check how lock you slept since all you know is that the program slept >= xx-consumed. The disadvantage with the above solution is that if the drawing takes >= allowed time, the machine will spend 100% of available capacity drawing. You might instead define that it is the sleep time between end of one frame and start of drawing of next frame that should fixed. You might also use the DirectX methods for drawing your information - they have functions for synchronizing frame rates. Alas, I don't know how to program with DirectX in the Dev-C++ environment. I have only tried this with M$ VC++. About your "strage" framerate: Windows tries to run threads for full time slices before swapping. /Per W On Fri, 27 Feb 2004, Emiliano wrote: > To any Win programmer listening... who would be sure better than me :) > > I have this problem: I have a 3 threaded app. One thread is for timing, one > for drawing, and the last reads windows messages. > > I need a working temporization. I've used both the "TimerFunc()" and the > "Sleep()" functions in the timer thread but both don't seem to be too > precise. The timer thread uses an Event object to awake the drawing thread. > > I used a timeout of 20 ms and I get 32 fps (instead of 50). I've tried with > 10 ms, and I get 64 fps :D instead of 1000/10 = 100...!! I know I can reach > that speed, since I draw a very simple scene, and my system can do it > (tested with other apps), and the video-refresh of my current video mode is > right 100-101 Hz. > > Is there some better way to achieve decent temporization? some library that > allows using interrupts or something similar? > > thanks in advance, > Emiliano > > PS I need this for an OpenGL program, I've only found nasty busy-waiting > loops with "PeekMessage()" and some drawFrame() + SwapBuffers() elsewhere... > that works ok most of the time, but if you try to put your window in the > background, the CPU usage reaches instantly 100%, and that sucks!! > > > > ------------------------------------------------------- > SF.Net is sponsored by: Speed Start Your Linux Apps Now. > Build and deploy apps & Web services for Linux with > a free DVD software kit from IBM. Click Now! > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |