#ifdef G_OS_WIN32 #define WIN32_LEAN_AND_MEAN 1 #include #else #define FALSE 0 #define TRUE !FALSE #endif #include #include #include "message_queue.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(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) { switch (key) { case KEY_ESCAPE: exit(0); break; case 'n': g_pEngine->Abort(); g_pEngine->NewGame(0, 0, BS_LARGE); break; case ' ': break; } } // 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) { } // process_mouse void process_passive_mouse(int x, int y) { //process_mouse(-1, -1, 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); init_gl(); //MenuInit(SCREEN_WIDTH, SCREEN_HEIGHT); g_pEngine = new C_MatchBloxEngine("models", ""); glutMainLoop(); return 0; } // main