MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / InitScreen

Method InitScreen

Source/Graphics/graphics.cpp:873–1364  ·  view source on GitHub ↗

Set up the screen

Source from the content-addressed store, hash-verified

871
872// Set up the screen
873void Graphics::InitScreen() {
874 PROFILER_ZONE(g_profiler_ctx, "Graphics::InitScreen");
875 Textures* textures = Textures::Instance();
876 Shaders* shaders = Shaders::Instance();
877 if (first_load) {
878 PROFILER_ENTER(g_profiler_ctx, "Setting up driver and window");
879 int n_video_driver = SDL_GetNumVideoDrivers();
880 LOGI << "There are " << n_video_driver << " available video drivers." << std::endl;
881 LOGI << "Video drivers are following:" << std::endl;
882
883 for (int i = 0; i < n_video_driver; i++) {
884 LOGI << "Video driver " << i << ": " << SDL_GetVideoDriver(i) << std::endl;
885 }
886
887 // Initialize default video driver
888 if (SDL_VideoInit(NULL) < 0) {
889 FatalError("Error", "Could not initialize default video driver");
890 } else {
891 LOGI << "Initialized video driver: " << SDL_GetCurrentVideoDriver() << std::endl;
892 }
893 // Set GL attributes
894 SDL_GL_SetAttributeErrCheck(SDL_GL_RED_SIZE, 8);
895 SDL_GL_SetAttributeErrCheck(SDL_GL_GREEN_SIZE, 8);
896 SDL_GL_SetAttributeErrCheck(SDL_GL_BLUE_SIZE, 8);
897 SDL_GL_SetAttributeErrCheck(SDL_GL_ALPHA_SIZE, 8);
898 SDL_GL_SetAttributeErrCheck(SDL_GL_DEPTH_SIZE, 24);
899 SDL_GL_SetAttributeErrCheck(SDL_GL_DOUBLEBUFFER, 1);
900 SDL_GL_SetAttributeErrCheck(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
901 SDL_GL_SetAttributeErrCheck(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
902 SDL_GL_SetAttributeErrCheck(SDL_GL_CONTEXT_MINOR_VERSION, 2);
903 SDL_GL_SetAttributeErrCheck(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
904#ifndef NO_GL_ERROR_CHECKING
905 SDL_GL_SetAttributeErrCheck(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
906#endif
907 // MSAA is handled later with renderbuffers and fbo
908 SDL_GL_SetAttributeErrCheck(SDL_GL_MULTISAMPLEBUFFERS, false);
909 SDL_GL_SetAttributeErrCheck(SDL_GL_MULTISAMPLESAMPLES, 0);
910
911 LOGI << "Attribute group 1 set" << std::endl;
912
913 // Create window
914 const char* window_title = "Overgrowth";
915 uint32_t window_flags = SDL_WINDOW_OPENGL;
916
917 int target_monitor = config_.target_monitor();
918 if (target_monitor >= config.GetMonitorCount()) {
919 target_monitor = config.GetMonitorCount() - 1;
920 config.GetRef("target_monitor") = target_monitor;
921 }
922
923 currentFullscreenType = config_.full_screen();
924 switch (config_.full_screen()) {
925 case FullscreenMode::kWindowed: {
926 window_flags |= SDL_WINDOW_RESIZABLE;
927
928 window_dims[0] = config_.screen_width();
929 window_dims[1] = config_.screen_height();
930 break;

Callers 2

LiveUpdateFunction · 0.80
InitializeMethod · 0.80

Calls 15

SDL_GLprofile_stringFunction · 0.85
gladLoadGLLoaderFunction · 0.85
ApplyVsyncFunction · 0.85
GetGLVendorFunction · 0.85
target_monitorMethod · 0.80
GetMonitorCountMethod · 0.80
full_screenMethod · 0.80
screen_widthMethod · 0.80
screen_heightMethod · 0.80
SetScreenWidthMethod · 0.80

Tested by

no test coverage detected