bool App::InitApp (void) { #ifdef CONFDIR strcpy (settings_path, (std::string (CONFDIR) + PATH_SEPARATOR + "test3d.ini").c_str()); #else strcpy (settings_path, (std::string (SDL_GetBasePath ()) + "settings.ini").c_str()); #endif int w, h; // initialize SDL with screen sizes from settings file: w = LoadSetting (settings_path, SCREENWIDTH_SETTING); if (w < 640) w = 640; h = LoadSetting (settings_path, SCREENHEIGHT_SETTING); if (h < 480) h = 480; fullscreen = LoadSetting (settings_path, FULLSCREEN_SETTING) > 0 ? true : false; // Create a window: if (!InitializeSDL(w, h)) return false; // Create a rendering context in the window: if (!InitializeGL()) return false; pScene = new HubScene (this); RandomSeed (); Progress progress; Loader loader; // Collect jobs to be done: pScene->AddAll (&loader); // Progress bar is rendered in a different thread while the scene loads: bool error = false; SDL_Thread* progressThread = MakeSDLThread ( [&] () { return ProgressLoop (mainWindow, &progress, error); }, "progress" ); if (!progressThread) { SetError ("failed to create progress thread: %s", SDL_GetError()); return false; } /* Do all jobs while the progress bar is rendered. Some of them depend on the current thread's rendering context. */ if (!loader.LoadAll (&progress)) { error = true; SDL_DetachThread (progressThread); return false; } // progressThread will finish automatically, now that everything is loaded .. // Check for other errors: if (!CheckGLOK ("scene init")) return false; // Wait for progress display thread to finish: int progressReturn; SDL_WaitThread (progressThread, &progressReturn); if (progressReturn != 0) { SetError ("progress thread returned exit code %d", progressReturn); return false; } return true; }