コード例 #1
0
/******************* WIN32 FUNCTIONS ***************************/
int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure
	bool	done=false;								// Bool Variable To Exit Loop

	StartGame n = StartGame();
	activityManager.push(&n);
	console.Open();

	// Create Our OpenGL Window
	if (!CreateGLWindow("OpenGL Win32 Example",screenWidth,screenHeight))
	{
		return 0;									// Quit If Window Was Not Created
	}

	Clock clock;
	double timeSinceLastUpdate = 0.0;

	Clock fpsCounterClock;
	double fpsCounterTime = 0.0;
	int fpsCounter = 0;

	clock.start();
	fpsCounterClock.start();

	//*******************************************GAME 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
		{
			if(keys[VK_ESCAPE])
				done = true;

	
			if (!keys[VK_RETURN]){

				fpsCounterTime += fpsCounterClock.restart();

				timeSinceLastUpdate += clock.restart();	

				while (timeSinceLastUpdate > TIME_PER_FRAME) {
						
						fpsCounter++;
						timeSinceLastUpdate -= TIME_PER_FRAME;
						update(TIME_PER_FRAME);
				}

				
				if (fpsCounterTime > 1){
#ifdef displayFPS
					std::cout<<"\t\t\t\t\tFPS: "<<fpsCounter<<std::endl;
#endif
					fpsCounterTime = 0;
					
					fpsCounter = 0;
				}
				
			}
			display();					// Draw The Scene

			SwapBuffers(hDC);				// Swap Buffers (Double Buffering)
		}
	}



	console.Close();

	// Shutdown
	KillGLWindow();									// Kill The Window
	return (int)(msg.wParam);						// Exit The Program
}
コード例 #2
0
/******************* WIN32 FUNCTIONS ***************************/
int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	console.Open();
	
	MSG		msg;									// Windows Message Structure
	bool	done=false;								// Bool Variable To Exit Loop

	// Create Our OpenGL Window
	if (!CreateGLWindow("OpenGL Win32 Example",screenWidth,screenHeight))
	{
		return 0;									// Quit If Window Was Not Created
	}

	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
		{
			if(keys[VK_ESCAPE])
				done = true;
			//initialise timer
			LARGE_INTEGER t;
			QueryPerformanceCounter(&t);
			__int64 currentTime = t.QuadPart;

			__int64 ticksElapsed = currentTime - prevTime;					// Ticks elapsed since the previous time step
			double deltaT = double(ticksElapsed) * timerFrequencyRecip;		// Convert to seconds

			if (!initialisedPrevDeltaT) {
				// This is the first time step
				// So we do not have the time elapsed during the previous time step, since there is no previous time step

				// Cheat, and use the current time step time for both
				prevDeltaT = deltaT;

				// We have initialised prevDeltaT; set initialisedPrevDeltaT to true so we don't do this again
				initialisedPrevDeltaT = true;
			}


			// Advance timer
			prevTime = currentTime;					// use the current time as the previous time in the next step
			prevDeltaT = deltaT;

			update(deltaT);

			display();					// Draw The Scene
			SwapBuffers(hDC);				// Swap Buffers (Double Buffering)
		}
	}

	console.Close();

	// Shutdown
	KillGLWindow();									// Kill The Window
	return (int)(msg.wParam);						// Exit The Program
}