//-- private methods ----- bool AssetManager::loadTexture(const char *filename, TextureAsset *textureAsset) { bool success= false; int pixelWidth=0, pixelHeight=0, channelCount=0; stbi_uc *image_buffer= stbi_load(filename, &pixelWidth, &pixelHeight, &channelCount, 3); if (image_buffer != NULL) { // GLint glPixelFormat= -1; if (channelCount == 3) { success = textureAsset->init(pixelWidth, pixelHeight, GL_RGB, GL_RGB, image_buffer); } else { Log_ERROR("AssetManager::loadTexture", "Image isn't RGB24 pixel format!"); } stbi_image_free(image_buffer); } else { Log_ERROR("AssetManager::loadTexture", "Failed to load: %s(%s)", filename, SDL_GetError()); } return success; }
bool OpenVRContext::init() { bool bSuccess = true; vr::EVRInitError eError = vr::VRInitError_None; // Loading the SteamVR Runtime m_pVRSystem = vr::VR_Init(&eError, vr::VRApplication_Scene); if (eError != vr::VRInitError_None) { m_pVRSystem = nullptr; Log_ERROR("OpenVRContext::startup", "Failed to initialize OpenVR: %s!", vr::VR_GetVRInitErrorAsEnglishDescription(eError)); bSuccess = false; } if (bSuccess) { m_pChaperone = (vr::IVRChaperone *)vr::VR_GetGenericInterface(vr::IVRChaperone_Version, &eError); if (m_pChaperone == nullptr) { Log_ERROR("OpenVRContext::startup", "Unable to get chaperone interface: %s!", vr::VR_GetVRInitErrorAsEnglishDescription(eError)); bSuccess = false; } } if (bSuccess) { m_pRenderModels = (vr::IVRRenderModels *)vr::VR_GetGenericInterface(vr::IVRRenderModels_Version, &eError); if (m_pRenderModels == nullptr) { Log_ERROR("OpenVRContext::startup", "Unable to get render model interface: %s!", vr::VR_GetVRInitErrorAsEnglishDescription(eError)); bSuccess = false; } } if (bSuccess) { m_bIsInitialized = true; } else { destroy(); } return bSuccess; }
//-- private methods ----- bool App::init(int argc, char** argv) { bool success= true; if (!m_openVRContext->init()) { Log_INFO("App::init", "Failed to initialize OpenVR!"); } if (success && !m_renderer->init()) { Log_ERROR("App::init", "Failed to initialize renderer!"); success= false; } if (success && !m_assetManager->init()) { Log_ERROR("App::init", "Failed to initialize asset manager!"); success= false; } if (success) { for (t_app_stage_map::const_iterator iter= m_nameToAppStageMap.begin(); iter != m_nameToAppStageMap.end(); ++iter) { if (!iter->second->init(argc, argv)) { Log_ERROR("App::init", "Failed to initialize app stage %s!", iter->first); success= false; break; } } } if (success) { m_orbitCamera.setIsLocked(false); m_fixedCamera.setIsLocked(true); } return success; }
void App::onClientPSMoveResponse( const ClientPSMoveAPI::ResponseMessage *response) { ClientPSMoveAPI::t_request_id request_id= response->request_id; const PSMoveProtocol::Response *protocol_response = GET_PSMOVEPROTOCOL_RESPONSE(response->opaque_response_handle); PSMoveProtocol::Response_ResponseType protocol_response_type= protocol_response->type(); const std::string& protocol_response_type_name = PSMoveProtocol::Response_ResponseType_Name(protocol_response_type); // All responses should have been handled by a response handler Log_ERROR("App::onClientPSMoveResponse", "Unhandled response type:%s (request id: %d)!", protocol_response_type_name.c_str(), request_id); }
void AppStage_MagnetometerCalibration::handle_release_controller( const ClientPSMoveAPI::ResponseMessage *response, void *userdata) { AppStage_MagnetometerCalibration *thisPtr= reinterpret_cast<AppStage_MagnetometerCalibration *>(userdata); if (response->result_code != ClientPSMoveAPI::_clientPSMoveResultCode_ok) { Log_ERROR("AppStage_MagnetometerCalibration", "Failed to release controller on server!"); } thisPtr->m_isControllerStreamActive= false; thisPtr->m_pendingAppStage = nullptr; thisPtr->m_app->setAppStage(AppStage_ControllerSettings::APP_STAGE_NAME); }
int App::exec(int argc, char** argv, const char *initial_state_name) { int result= 0; if (init(argc, argv)) { SDL_Event e; setAppStage(initial_state_name); while (!m_bShutdownRequested) { if (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE)) { Log_INFO("App::exec", "QUIT message received"); break; } else { onSDLEvent(e); } } update(); render(); } } else { Log_ERROR("App::exec", "Failed to initialize application!"); result= -1; } destroy(); return result; }
bool AssetManager::loadFont(const char *filename, const float pixelHeight, FontAsset *fontAsset) { unsigned char *temp_ttf_buffer = NULL; bool success= true; // Scratch buffer for true type font data loaded from file temp_ttf_buffer = NULL; // Load the True Type Font data into memory if (success) { FILE *fp= fopen(k_default_font_filename, "rb"); if (fp != NULL) { // obtain file size fseek (fp , 0 , SEEK_END); size_t fileSize = ftell (fp); rewind (fp); if (fileSize > 0 && fileSize < 10*k_meg) { temp_ttf_buffer= new unsigned char[fileSize]; size_t bytes_read= fread(temp_ttf_buffer, 1, fileSize, fp); if (bytes_read != fileSize) { Log_ERROR("AssetManager::loadFont", "Failed to load font (%s): failed to read expected # of bytes.", filename); success= false; } } else { Log_ERROR("AssetManager::loadFont", "Failed to load font (%s): file size invalid", filename); success= false; } fclose(fp); } else { Log_ERROR("AssetManager::loadFont", "Failed to open font file (%s)", filename); success= false; } } // Build the sprite sheet for the font if (success && !fontAsset->init(temp_ttf_buffer, pixelHeight)) { Log_ERROR("AssetManager::loadFont", "Failed to fit font(%s) into %dx%d sprite texture", filename, k_font_texture_width, k_font_texture_height); success = false; } // Free true type font scratch buffers if (temp_ttf_buffer != NULL) { delete[] temp_ttf_buffer; } return success; }