-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLUTMain.cpp
88 lines (73 loc) · 1.81 KB
/
GLUTMain.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
80
81
82
83
84
85
86
87
88
#include "Globals.h"
#include "cGame.h"
//Delete console
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
cGame Game;
void AppRender()
{
Game.Render();
}
void AppKeyboard(unsigned char key, int x, int y)
{
Game.ReadKeyboard(key,x,y,true);
}
void AppKeyboardUp(unsigned char key, int x, int y)
{
Game.ReadKeyboard(key,x,y,false);
}
void AppSpecialKeys(int key, int x, int y)
{
Game.ReadKeyboard(key,x,y,true);
}
void AppSpecialKeysUp(int key, int x, int y)
{
Game.ReadKeyboard(key,x,y,false);
}
void AppMouse(int button, int state, int x, int y)
{
Game.ReadMouse(button,state,x,y);
}
void AppIdle(){
int t1 = glutGet(GLUT_ELAPSED_TIME);
int t2;
if(!Game.Loop()) exit(0);
do {
t2 = glutGet(GLUT_ELAPSED_TIME);
} while (t2 - t1 < 20); //20ms -> 1000/20 = 50 fps
}
void reshape(int w, int h){
Game.setView(w, h);
}
void main(int argc, char** argv)
{
int res_x,res_y,pos_x,pos_y;
//GLUT initialization
glutInit(&argc, argv);
//RGBA with double buffer
glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE);
//Create centered window
res_x = glutGet(GLUT_SCREEN_WIDTH);
res_y = glutGet(GLUT_SCREEN_HEIGHT);
pos_x = (res_x>>1)-(GAME_WIDTH>>1);
pos_y = (res_y>>1)-(GAME_HEIGHT>>1);
glutInitWindowPosition(pos_x,pos_y);
glutInitWindowSize(GAME_WIDTH,GAME_HEIGHT);
glutCreateWindow("Zelda Returns");
/*glutGameModeString("800x600:32");
glutEnterGameMode();*/
//Make the default cursor disappear
//glutSetCursor(GLUT_CURSOR_NONE);
//Register callback functions
glutDisplayFunc(AppRender);
glutKeyboardFunc(AppKeyboard);
glutReshapeFunc(reshape);
glutKeyboardUpFunc(AppKeyboardUp);
glutSpecialFunc(AppSpecialKeys);
glutSpecialUpFunc(AppSpecialKeysUp);
glutMouseFunc(AppMouse);
glutIdleFunc(AppIdle);
//Game initializations
Game.Init();
//Application loop
glutMainLoop();
}