www.pudn.com > RCApp-src.zip > RCApp.cpp, change:2003-09-11,size:4151b
/* RedEye Project (http://members.ozemail.com.au/~ndmcevoy/) Copyright (C) 2003 Nick McEvoy This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------- Commented for use with Doxygen (http://www.doxygen.org) ----------------------------------------------------------------- */ /*! \file RCApp.cpp * \brief Redeye game main loop. * * This file contains the redeye game main loop. */ // GLUT includes #include// PLIB include #include #include // RedEye includes #include "Engine.h" //! Game constants #define APP_NAME "RCApp" #define APP_WINDOW_TITLE "Reality Check" #define INIT_WINDOW_POS_X 0 #define INIT_WINDOW_POS_Y 0 #define INIT_WINDOW_WIDTH 800 #define INIT_WINDOW_HEIGHT 600 //! GLUT callback handlers static void reGlutIdle() {reGetGameEngine()->Update();}; static void reGlutDisplay() {reGetGameEngine()->Display();}; static void reGlutReshape(int w, int h) {reGetGameEngine()->Reshape(w, h);}; static void reGlutKeyboard(unsigned char key, int x, int y) {reGetGameEngine()->Keyboard(key, x, y, true);}; static void reGlutKeyboardUp(unsigned char key, int x, int y) {reGetGameEngine()->Keyboard(key, x, y, false);}; static void reGlutSpecial(int key, int x, int y) {reGetGameEngine()->KeyboardSpecial(key, x, y, true);}; static void reGlutSpecialUp(int key, int x, int y) {reGetGameEngine()->KeyboardSpecial(key, x, y, false);}; static void reMouseFunc(int button, int state, int x, int y) {reGetGameEngine()->MouseFunc(button, state, x, y);}; static void reMotionFunc(int x, int y) {reGetGameEngine()->MotionFunc(x, y);}; static void rePassiveMotionFunc(int x, int y) {reGetGameEngine()->PassiveMotionFunc(x, y);}; //! Initialise OpenGL, GLUT & PLIB. /*! * \param none. * \return none. */ void reInitialiseGraphics() { printf("InitialiseGraphics() - initilising OpenGL, GLUT & PLIB\n"); int iFakeArgc = 1; char* FakeArgv[3]; FakeArgv[0] = APP_NAME; FakeArgv[1] = APP_WINDOW_TITLE; FakeArgv[2] = NULL; // Initialise GLUT glutInitWindowPosition(INIT_WINDOW_POS_X, INIT_WINDOW_POS_Y); glutInitWindowSize(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT); glutInit(&iFakeArgc, FakeArgv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow(FakeArgv[1]); // Setup GLUT callbacks glutDisplayFunc(reGlutDisplay); glutReshapeFunc(reGlutReshape); glutIdleFunc(reGlutIdle); glutKeyboardFunc(reGlutKeyboard); glutKeyboardUpFunc(reGlutKeyboardUp); glutSpecialFunc(reGlutSpecial); glutSpecialUpFunc(reGlutSpecialUp); glutMouseFunc(reMouseFunc); glutMotionFunc(reMotionFunc); glutPassiveMotionFunc(rePassiveMotionFunc); // Initialise PLIB (SSG & PUI) ssgInit(); puInit(); // Some basic OpenGL setup glClearColor(0.2f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glAlphaFunc(GL_GREATER, 0.1f); glEnable(GL_BLEND); glEnable(GL_ALPHA_TEST); // Setup the viewing parameters ssgSetFOV(60.0f, 45.0f); ssgSetNearFar(0.2f, 30000.0f); // Initialise game engine reGetGameEngine()->Init(); } //! Main loop. /*! * \param argc - argument count. * \param argv - arguments. * \return 0 success, else fail. */ int main(int argc, char* argv[]) { // Initialise graphics reInitialiseGraphics(); // Let GLUT take control ... glutMainLoop(); return 0; }