Repository navigation
Expand file tree
/
Copy pathMain.cpp
More file actions
220 lines (170 loc) · 5.07 KB
/
Copy pathMain.cpp
File metadata and controls
220 lines (170 loc) · 5.07 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
////////////////////////////////////////////////Libraries
//Debug info
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include <stdio.h>
#include <stdlib.h>
#include "GL/glew.h"
#include "GL/glut.h"
#include "Mouse.h"
#include "Keyboard.h"
#include "Constants.h"
#include "Display.h"
#include "Extensions.h"
#include "ForcePong.h"
#include "ConstantsIO.h"
#include "Conversion.h"
#include "Sound.h"
#include "VectorT.h"
void forIdle();
void forDisplay();
//keyboard functions
void processSpecialKeys(int key, int x, int y);
void processNormalKeys(unsigned char key, int x, int y);
void processSpecialKeysUp(int key, int x, int y);
void processNormalKeysUp(unsigned char key, int x, int y);
//mouse functions
void processMouse(int button, int state, int x, int y);//controls movement with passive and active mouse
void processMousePassiveMotion(int x, int y);
void processMouseActiveMotion(int x, int y);
//Main functions
void Runner();
void init();
//Secondary functions
void cleanup();
void changeSize(int width,int height);
void setVsync(bool vSyncOn);
//Etc
float frameRate=0.0f;
float pTime=glutGet(GLUT_ELAPSED_TIME);
float fTime=pTime;
int frameCount=0;
//Game
ForcePong forcePong;
////////////////////////////////////////////////Main loop entry point
int main(int argc, char** argv){//main function
//Debug info
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
atexit(cleanup);
glutInit(&argc,argv);
//Window functions
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
if(FULLSCREEN){
//Attempt to enter gamemode
glutGameModeString("1024x768:32");
glutEnterGameMode();
}else{
glutInitWindowSize(WINDOWWIDTH,WINDOWHEIGHT);
glutCreateWindow("Liquidus");
}
glutDisplayFunc(forDisplay);
glutIdleFunc(forIdle);
//keyboard functions
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(processSpecialKeys);
glutKeyboardUpFunc(processNormalKeysUp);
glutSpecialUpFunc(processSpecialKeysUp);
glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
//Mouse functions
glutMouseFunc(processMouse);
glutMotionFunc(processMouseActiveMotion);
glutPassiveMotionFunc(processMousePassiveMotion);
glutReshapeFunc(changeSize);
GLenum err = glewInit();
if (GLEW_OK != err){
printf("Error: %s\n", glewGetErrorString(err));
}
if(GL_TRUE != glewGetExtension( "GL_ARB_fragment_shader"))
printf("GL_ARB_fragment_shader extension is not available!");
if(GL_TRUE != glewGetExtension("GL_ARB_vertex_shader"))
printf("GL_ARB_vertex_shader extension is not available!");
if(GL_TRUE != glewGetExtension("GL_ARB_shader_objects"))
printf("GL_ARB_shader_objects extension is not available!");
if( ! GLEW_ATI_texture_float )
printf("NO GLEW_ATI_texture_float");
//Sound
//Initialize the OpenAL library
Sound::init(argc,argv);
init();
glutMainLoop();
return 1;
}//end of function
void forIdle(){
float currentTime=glutGet(GLUT_ELAPSED_TIME);
//Frame caps
if(currentTime-fTime>=1000/GAMESPEED){
fTime=currentTime;
if(currentTime-pTime>=1000){
pTime=currentTime;
frameRate=frameCount;//calc framerates
frameCount=0;
}
++frameCount;
Runner();
}
glutSwapBuffers();
glutPostRedisplay();
}
void cleanup(){
forcePong.cleanup();
delete []defaultSinValues;
Sound::kill();
}
void forDisplay(){
}
void Runner(){
forcePong.run();
string fpsString=numberToString((int)frameRate);
glColor3f(0,0,0);
defaultDisplay.displayString(fpsString,defaultDisplay.windowWidth-100,50,FONT_SIZE,NULL);
}
void init(){
setVsync(VSYNC_ON);
glutSetCursor(GLUT_CURSOR_FULL_CROSSHAIR);
forcePong.init();
}
void processSpecialKeys(int key, int x, int y){
//catch special keys and store in static keyboard variables.
defaultMouse.changeMouseCords(x,y);
defaultKeyboard.update(key,1);
}
void processNormalKeys(unsigned char key, int x, int y) {
defaultMouse.changeMouseCords(x,y);
defaultKeyboard.update(key,1);
}
void processSpecialKeysUp(int key, int x, int y){
defaultMouse.changeMouseCords(x,y);
defaultKeyboard.update(key,0);
}
void processNormalKeysUp(unsigned char key, int x, int y){
defaultMouse.changeMouseCords(x,y);
defaultKeyboard.update(key,0);
}
void processMouseActiveMotion(int x, int y){
defaultMouse.changeMouseCords(x,y);
}
void processMouse(int button, int state, int x, int y){
defaultMouse.changeMouseCords(x,y,button,state);
}
void processMousePassiveMotion(int x, int y){
defaultMouse.changeMouseCords(x,y);
}
/////////////////////////////////////////////////
//Secondary Functions
////////////////////////////////////////////////
void changeSize(int width,int height){
forcePong.resize(VectorT(width,height),VectorT(defaultDisplay.windowWidth,defaultDisplay.windowHeight));
defaultDisplay.changeSize(width,height);
}
void setVsync(bool vSyncOn){
const GLubyte *extensions = glGetString( GL_EXTENSIONS );
if( strstr((char*)extensions, "WGL_EXT_swap_control" ) == 0 )
return; // Error: WGL_EXT_swap_control extension not supported on your computer.\n");
else
{
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress( "wglSwapIntervalEXT" );
if( wglSwapIntervalEXT )
wglSwapIntervalEXT(vSyncOn);
}
}