-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (61 loc) · 1.33 KB
/
main.cpp
File metadata and controls
80 lines (61 loc) · 1.33 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
/*
* main.cc
* Advanced2D
*
* Created by Ralph Smith on 9/4/10.
* Copyright 2010 Ralph Smith. All rights reserved.
*
*/
#include <iostream>
#include <stdio.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#elif _WIN32
#include <GL/glut.h>
#else
#include <GL/glut.h>
#endif
#include "game.h"
#define WIDTH 1024
#define HEIGHT 768
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, w, 0.0f, h, -1.0f, 1.0f);
}
void handleKeypress(unsigned char key, int x, int y) {
game_input(key, x, y);
}
void update(int value) {
g_engine->Update();
if (gameover) {
handleKeypress(27, 0, 0);
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
void draw() {
glutSwapBuffers();
}
int main (int argc, char * argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("Advanced 2D Game Engine Test");
g_engine = new Advanced2D::Engine();
if (!game_preload()) {
printf("Error preloading game\n");
return 0;
}
if (!g_engine->Init(WIDTH, HEIGHT, 32, false)) {
printf("Error initializing the engine");
return 0;
}
glutDisplayFunc(draw);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0);
glutMainLoop();
return 0;
}