Locking Framerate

Started by
1 comment, last by luridcortex 20 years, 5 months ago
I read a paper on how to do this a while back using TimeGetTime(), but i cant find it anywhere. been looking for the past hour :\ Anyway, what im trying to do is lock the framerate of my gl apps. basically what i think this invlolves is calling the Render() function if a certain timer interval has passed. im using the nehe gl basecode for my project, so heres the main loop:

while(!done)									// Loop That Runs While done=FALSE
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			if ((active && !DrawGLScene()) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?
			{
				done=TRUE;							// ESC or DrawGLScene Signalled A Quit
			}
			else									// Not Time To Quit, Update Screen
			{
				SwapBuffers(hDC);					// Swap Buffers (Double Buffering)
			}

			if (keys[VK_F1])						// Is F1 Being Pressed?
			{
				keys[VK_F1]=FALSE;					// If So Make Key FALSE
				KillGLWindow();						// Kill Our Current Window
				fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode
				// Recreate Our OpenGL Window
				if (!CreateGLWindow(/*"NeHe''s Texture Mapping Tutorial"*/"BIT|RAPE: Multiple Texture Loading",640,480,16,fullscreen))
				{
					return 0;						// Quit If Window Was Not Created
				}
			}
		}
	}
 
Advertisement
alright, i think i got it.

in your render function you can do something like this:

Render(){    DWORD startTime = GetTickCount();        // Do stuff....    while((GetTickCount - startTime) < 33)); // Lock FPS}Anyone know of a better way?   
yes. why do you want to lock the framerate?

EOF
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.

This topic is closed to new replies.

Advertisement