/** * Initialize an EGL context for the current display. */ int Engine::InitDisplay() { if( !initialized_resources_ ) { gl_context_->Init( app_->window ); LoadResources(); initialized_resources_ = true; } else { // initialize OpenGL ES and EGL if( EGL_SUCCESS != gl_context_->Resume( app_->window ) ) { UnloadResources(); LoadResources(); } } ShowUI(); // Initialize GL state. glEnable( GL_CULL_FACE ); glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); //Note that screen size might have been changed glViewport( 0, 0, gl_context_->GetScreenWidth(), gl_context_->GetScreenHeight() ); renderer_.UpdateViewport(); tap_camera_.SetFlip( 1.f, -1.f, -1.f ); tap_camera_.SetPinchTransformFactor( 10.f, 10.f, 8.f ); return 0; }
/** * Just the current frame in the display. */ void Engine::DrawFrame() { float fps; if (monitor_.Update(fps)) { UpdateFPS(fps); } double dTime = monitor_.GetCurrentTime(); renderer_.Update(dTime); // Just fill the screen with a color. glClearColor(0.5f, 0.5f, 0.5f, 1.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); renderer_.Render(); // Swap if (EGL_SUCCESS != gl_context_->Swap()) { UnloadResources(); LoadResources(); } }
/** * Initialize an EGL context for the current display. */ int Engine::InitDisplay(android_app *app) { if (!initialized_resources_) { gl_context_->Init(app_->window); LoadResources(); initialized_resources_ = true; } else if(app->window != gl_context_->GetANativeWindow()) { // Re-initialize ANativeWindow. // On some devices, ANativeWindow is re-created when the app is resumed assert(gl_context_->GetANativeWindow()); UnloadResources(); gl_context_->Invalidate(); app_ = app; gl_context_->Init(app->window); LoadResources(); initialized_resources_ = true; } else { // initialize OpenGL ES and EGL if (EGL_SUCCESS == gl_context_->Resume(app_->window)) { UnloadResources(); LoadResources(); } else { assert(0); } } ShowUI(); // Initialize GL state. glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); // Note that screen size might have been changed glViewport(0, 0, gl_context_->GetScreenWidth(), gl_context_->GetScreenHeight()); renderer_.UpdateViewport(); tap_camera_.SetFlip(1.f, -1.f, -1.f); tap_camera_.SetPinchTransformFactor(10.f, 10.f, 8.f); return 0; }
/** * Unload resources */ void Engine::UnloadResources() { renderer_.Unload(); }
/** * Load resources */ void Engine::LoadResources() { renderer_.Init( NUM_TEAPOTS_X, NUM_TEAPOTS_Y, NUM_TEAPOTS_Z ); renderer_.Bind( &tap_camera_ ); }