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
|
#include <GL/glut.h>
#include <iostream>
#include "MessageQueue.h"
#include "C_MatchBloxEngine.h"
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
msgQueue g_Queue;
C_MatchBloxEngine *g_pEngine;
void init_gl(void)
{
GLfloat l_fLightpos[4] = {0.0, 1.0, 1.0, 0.0};
glClearColor(0.9, 0.9, 0.9, 1.0);
glClearDepth(1000.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, l_fLightpos);
glEnable(GL_NORMALIZE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
} // init_gl
void idle_func(void)
{
//call engine idle func
glutPostRedisplay();
}
void render_scene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
g_pEngine->Render(glutGet(GLUT_ELAPSED_TIME));
glutSwapBuffers();
} // render_scene
void reshape(int w, int h)
{
//set the new viewport dimension
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0, ((GLdouble)h)/((GLdouble)w), 0.5, 100.0);
glTranslated(0.0, 0.0, -0.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void process_normal_keys(unsigned char key, int x, int y)
{
// escape
if (key == 27)
{
exit(0);
}
else
{
if (key == 'n')
{
g_pEngine->Abort();
g_pEngine->NewGame(0, 0, BS_LARGE);
}
msgStruct l_msg;
l_msg.m_MessageType = KEY_PRESS;
l_msg.parm1 = key;
l_msg.parm2 = x;
l_msg.parm3 = y;
g_Queue.push(l_msg);
}
} // process_normal_keys
void process_special_keys(int key, int x, int y)
{
switch (key)
{
// do sumting
}
msgStruct l_msg;
l_msg.m_MessageType = SPECIAL_KEY;
l_msg.parm1 = key;
l_msg.parm2 = x;
l_msg.parm3 = y;
g_Queue.push(l_msg);
} // process_special_keys
void process_mouse(int button, int state, int x, int y)
{
msgStruct l_msg;
l_msg.m_MessageType = MOUSE_PRESS;
l_msg.parm1 = button;
l_msg.parm2 = state;
l_msg.parm3 = x;
l_msg.parm4 = y;
g_Queue.push(l_msg);
} // process_mouse
void process_passive_mouse(int x, int y)
{
//process_mouse(-1, -1, x, y);
msgStruct l_msg;
l_msg.m_MessageType = MOUSE_MOVE;
l_msg.parm1 = x;
l_msg.parm2 = y;
l_msg.parm3 = 0;
l_msg.parm4 = 0;
g_Queue.push(l_msg);
} // process_passive_mouse
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
glutCreateWindow("MatchBloxEngine demo");
glutReshapeFunc(reshape);
glutDisplayFunc(render_scene);
glutIdleFunc(idle_func);
glutKeyboardFunc(process_normal_keys);
glutSpecialFunc(process_special_keys);
glutMouseFunc(process_mouse);
glutPassiveMotionFunc(process_passive_mouse);
init_gl();
//MenuInit(SCREEN_WIDTH, SCREEN_HEIGHT);
g_pEngine = new C_MatchBloxEngine("models", "");
glutMainLoop();
return 0;
} // main
|