#ifdef G_OS_WIN32 #define WIN32_LEAN_AND_MEAN 1 #include #else #define FALSE 0 #define TRUE !FALSE #endif #include #include #include #include "message_queue.h" #include "message_input.h" #include "menu.h" #include "C_MatchBloxEngine.h" #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 #define KEY_ESCAPE 27 C_MatchBloxEngine *g_pEngine; void init_gl(void) { GLfloat l_fLightpos[4] = {0.0, 1.0, 1.0, 0.0}; glClearColor(1, 0.4, 0.2, 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); glDisable(GL_TEXTURE_2D); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); } // init_gl void idle_func(void) { //call engine idle func MenuRun(); glutPostRedisplay(); } void render_scene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); g_pEngine->Render(glutGet(GLUT_ELAPSED_TIME)); MenuRender(); 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) { struct messageq_s message; struct input_payload_keyboard payload; message.recipient = MESSAGE_MENU | MESSAGE_RENDERER; message.sender = MESSAGE_INPUT_KEYBOARD; switch (key) { case KEY_ESCAPE: exit(0); break; case 'n': g_pEngine->Abort(); g_pEngine->NewGame(0, 0, BS_LARGE); break; } payload.specialkey = FALSE; payload.key = (int)key; payload.modifier = glutGetModifiers(); payload.x = x; payload.y = y; message.payload = (struct input_payload_keyboard *)&payload; message.payload_size = sizeof(payload); messageq_send(&message); } // process_normal_keys void process_special_keys(int key, int x, int y) { switch (key) { // do sumting } } // process_special_keys void process_mouse(int button, int state, int x, int y) { MenuMouseClick(button, state, x, y); } // process_mouse void process_passive_mouse(int x, int y) { MenuMouseMove(x, y); } // process_passive_mouse int main(int argc, char **argv) { messageq_init(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); glutCreateWindow("MatchBlox"); glutReshapeFunc(reshape); glutDisplayFunc(render_scene); glutIdleFunc(idle_func); glutKeyboardFunc(process_normal_keys); glutSpecialFunc(process_special_keys); glutMouseFunc(process_mouse); glutPassiveMotionFunc(process_passive_mouse); glutSetCursor(GLUT_CURSOR_NONE); init_gl(); MenuInit(SCREEN_WIDTH, SCREEN_HEIGHT); g_pEngine = new C_MatchBloxEngine("models", ""); glutMainLoop(); return 0; } // main