|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : openglex.cpp 00004 * Part of : OpenC / OpenCOpenglEx 00005 * Interface : 00006 * Description : The main entry point to the application is implemented here. 00007 * Version : 00008 * 00009 * Copyright (c) 2007 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 #include <stdio.h> // for printf 00017 00018 #ifdef __GCCE__ 00019 //#include <staticlibinit_gcce.h> 00020 #endif 00021 00022 #include <e32base.h> // for Symbian classes. 00023 #include <coemain.h> // for CCoeEnv. 00024 #include "game.h" // for the CGame class 00025 #include "gamecontroller.h" // for the CGameController class. 00026 00027 // Error codes 00028 const TInt KErrDisplayNotCreated = -5001; 00029 const TInt KErrDisplayNotInitialized = -5002; 00030 00031 // Function prototypes 00032 00033 // Creates the Game, Game Controller and starts the Game loop. 00034 void StartGameL( EGLDisplay aEglDisplay ); 00035 00036 // ----------------------------------------------------------------------------- 00037 // main() 00038 // 00039 // The main entry point to the application. 00040 // ----------------------------------------------------------------------------- 00041 // 00042 int main(void) 00043 { 00044 __UHEAP_MARK; 00045 00046 TInt result = KErrNone; 00047 00048 // Create the control environment. 00049 CCoeEnv* environment = new (ELeave) CCoeEnv(); 00050 00051 TRAPD( err, environment->ConstructL( ETrue, 0 ) ); 00052 00053 if( err != KErrNone ) 00054 { 00055 printf( "Unable to create a CCoeEnv!\n" ); 00056 getchar(); 00057 00058 result = KErrCoeEnvNotInitialized; 00059 } 00060 else 00061 { 00062 // Get the default display for rendering on to. 00063 EGLDisplay eglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00064 if( eglDisplay != NULL ) 00065 { 00066 // Initialize EGL. 00067 if( eglInitialize( eglDisplay, NULL, NULL ) == EGL_FALSE ) 00068 { 00069 printf( "EGL Initialize failed!\n" ); 00070 getchar(); 00071 00072 result = KErrDisplayNotInitialized; 00073 } 00074 else 00075 { 00076 // Start the Game. 00077 // This has to be called inside a TRAPD, as eglInitialize 00078 // internally creates a Trap Handler. 00079 TRAPD( result, StartGameL( eglDisplay ) ); 00080 00081 if( KErrNone != result ) 00082 { 00083 printf( "StartGameL failed with result = %d!\n", result ); 00084 getchar(); 00085 } 00086 00087 // EGL related cleanup. 00088 eglTerminate( eglDisplay ); 00089 } 00090 } 00091 else 00092 { 00093 printf( "EGL Get Display failed!\n" ); 00094 getchar(); 00095 00096 result = KErrDisplayNotCreated; 00097 } 00098 } 00099 00100 // Close the stdout & stdin, else printf / getchar causes a memory leak. 00101 fclose( stdout ); 00102 fclose( stdin ); 00103 00104 // Cleanup 00105 CCoeEnv::Static()->DestroyEnvironment(); 00106 delete CCoeEnv::Static(); 00107 00108 __UHEAP_MARKEND; 00109 00110 return result; 00111 } 00112 00113 // ----------------------------------------------------------------------------- 00114 // StartGameL 00115 // 00116 // Initializes the Game, the GameController and starts off the game loop. 00117 // This will return only if either the Game Exits or if an error occurs. 00118 // ----------------------------------------------------------------------------- 00119 // 00120 void StartGameL( EGLDisplay aEglDisplay ) 00121 { 00122 // The CCoeEnv creates certain Active Objects that are not needed 00123 // for the current application. 00124 00125 // So delete the current Active Scheduler and create your own. 00126 delete CActiveScheduler::Current(); 00127 CActiveScheduler* actScheduler = new (ELeave) CActiveScheduler(); 00128 CActiveScheduler::Install( actScheduler ); 00129 CleanupStack::PushL( actScheduler ); 00130 00131 // Create the Game Controller. 00132 // The Game controller creates the window & initializes the egl context. 00133 CGameController* gameController = CGameController::NewLC( aEglDisplay ); 00134 00135 // Create the Game. 00136 // The game will take care of rendering using opengl es calls. 00137 CGame* game = CGame::NewLC(); 00138 00139 // Start the game loop. 00140 gameController->StartGameL( *game ); 00141 00142 // The game has completed so destroy 00143 // the game controller, the game and the actScheduler. 00144 CleanupStack::PopAndDestroy( 3 ); 00145 } 00146 00147 // eof
|
© Nokia 2009 |