-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
79 lines (65 loc) · 2.18 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* FPSDemo
* David Schneider - 01/10
* main.cpp and glwindow class adapted from Beginning OpenGL Game Programming Second Edition by Benstead, Astle & Hawkins
*/
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include "glwindow.h"
#include "GameEngine.h"
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR cmdLine,
int cmdShow)
{
//Set our window settings
const int windowWidth = 1024;
const int windowHeight = 768;
const int windowBPP = 16;
const int windowFullscreen = false;
//This is our window
GLWindow programWindow(hInstance);
//The example OpenGL code
GameEngine engine;
//Attach our example to our window
programWindow.attachEngine(&engine);
//Attempt to create the window
if (!programWindow.create(windowWidth, windowHeight, windowBPP, windowFullscreen))
{
//If it fails
MessageBox(NULL, "Unable to create the OpenGL Window", "An error occurred", MB_ICONERROR | MB_OK);
programWindow.destroy(); //Reset the display and exit
return 1;
}
if (!engine.init()) //Initialize our example
{
MessageBox(NULL, "Could not initialize the application", "An error occurred", MB_ICONERROR | MB_OK);
programWindow.destroy(); //Reset the display and exit
return 1;
}
float FPSLimiter = 0.0f;
//This is the mainloop, we render frames until isRunning returns false
while(programWindow.isRunning())
{
programWindow.processEvents(); //Process any window events
//We get the time that passed since the last frame
float elapsedTime = programWindow.getElapsedSeconds();
FPSLimiter += elapsedTime;
//Limit to 60fps.
//if (FPSLimiter >= 0.0167f)
if (true)
{
if (GetForegroundWindow() == programWindow.getHWND())
{
engine.processInputs();
}
engine.prepare(elapsedTime); //Do any pre-rendering logic
engine.render(); //Render the scene
programWindow.swapBuffers();
FPSLimiter = 0.0f;
}
}
engine.shutdown(); //Free any resources
programWindow.destroy(); //Destroy the program window
return 0; //Return success
}