Set up the screen
| 871 | |
| 872 | // Set up the screen |
| 873 | void 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; |
no test coverage detected