int video_mode(int f, int w, int h) { //senquack /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); int stereo = config_get_d(CONFIG_STEREO) ? 1 : 0; int stencil = config_get_d(CONFIG_REFLECTION) ? 1 : 0; int buffers = config_get_d(CONFIG_MULTISAMPLE) ? 1 : 0; int samples = config_get_d(CONFIG_MULTISAMPLE); int vsync = config_get_d(CONFIG_VSYNC) ? 1 : 0; int hmd = config_get_d(CONFIG_HMD) ? 1 : 0; int highdpi = config_get_d(CONFIG_HIGHDPI) ? 1 : 0; int dpy = config_get_d(CONFIG_DISPLAY); int X = SDL_WINDOWPOS_CENTERED_DISPLAY(dpy); int Y = SDL_WINDOWPOS_CENTERED_DISPLAY(dpy); hmd_free(); if (window) { SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); } //senquack // SDL_GL_SetAttribute(SDL_GL_STEREO, stereo); //senquack - disabled drawing shadows and reflections on GCW Zero, don't need a stencil buffer: #ifdef GCWZERO SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); #endif //senquack - don't need or want these on GCW Zero: #ifndef GCWZERO SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, buffers); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); #endif /* Require 16-bit double buffer with 16-bit depth buffer. */ //senquack - GCW Zero port change SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); // SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); // SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); // SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); // SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //senquack SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); /* Try to set the currently specified mode. */ log_printf("Creating a window (%dx%d, %s)\n", w, h, (f ? "fullscreen" : "windowed")); //senquack DEBUG - DO NOT RUN - loads GLES2.0 for some reason // SDL_VideoInit(NULL); window = SDL_CreateWindow("", X, Y, w, h, SDL_WINDOW_OPENGL | (highdpi ? SDL_WINDOW_ALLOW_HIGHDPI : 0) | (f ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)); if (window) { if ((context = SDL_GL_CreateContext(window))) { int buf, smp; SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buf); SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &smp); /* * Work around SDL+WGL returning pixel formats below * minimum specifications instead of failing, thus * bypassing our fallback path. SDL tries to ensure that * WGL plays by the rules, but forgets about extended * context attributes such as multisample. See SDL * Bugzilla #77. */ if (buf < buffers || smp < samples) { log_printf("GL context does not meet minimum specifications\n"); SDL_GL_DeleteContext(context); context = NULL; } } } if (window && context) { set_window_title(TITLE); set_window_icon(ICON); /* * SDL_GetWindowSize can be unreliable when going fullscreen * on OSX (and possibly elsewhere). We should really be * waiting for a resize / size change event, but for now we're * doing this lazy thing instead. */ if (f) { SDL_DisplayMode dm; if (SDL_GetDesktopDisplayMode(video_display(), &dm) == 0) { video.window_w = dm.w; video.window_h = dm.h; // //senquack dm.format = SDL_PIXELFORMAT_RGBA8888; // dm.format = SDL_PIXELFORMAT_RGB565; dm.w = 320; dm.h = 240; dm.refresh_rate = 60; dm.driverdata = 0; SDL_SetWindowDisplayMode(window, &dm); printf("setting new video dm..\n"); SDL_GetCurrentDisplayMode(0, &dm); SDL_Log("Screen w: %d h: %d\n", dm.w, dm.h); SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(dm.format)); SDL_Log("Screen dm: "); SDL_Log("\n\n"); SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR)); SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER)); SDL_Log("Version : %s\n", glGetString(GL_VERSION)); SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS)); SDL_Log("\n"); fflush(NULL); } } else { SDL_GetWindowSize(window, &video.window_w, &video.window_h); } if (highdpi) { SDL_GL_GetDrawableSize(window, &video.device_w, &video.device_h); } else { video.device_w = video.window_w; video.device_h = video.window_h; } video.device_scale = (float) video.device_h / (float) video.window_h; log_printf("Created a window (%u, %dx%d, %s)\n", SDL_GetWindowID(window), video.window_w, video.window_h, (f ? "fullscreen" : "windowed")); config_set_d(CONFIG_DISPLAY, video_display()); config_set_d(CONFIG_FULLSCREEN, f); config_set_d(CONFIG_WIDTH, video.window_w); config_set_d(CONFIG_HEIGHT, video.window_h); SDL_GL_SetSwapInterval(vsync); if (!glext_init()) return 0; glViewport(0, 0, video.device_w, video.device_h); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_BLEND); #if !ENABLE_OPENGLES glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); #endif glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); /* If GL supports multisample, and SDL got a multisample buffer... */ if (glext_check("ARB_multisample")) { SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers); if (buffers) glEnable(GL_MULTISAMPLE); } /* Set up HMD display if requested. */ if (hmd) hmd_init(); /* Initialize screen snapshotting. */ snapshot_init(); video_show_cursor(); /* Grab input immediately in HMD mode. */ if (hmd_stat()) SDL_SetWindowGrab(window, SDL_TRUE); return 1; } /* If the mode failed, try it without stereo. */ else if (stereo) { config_set_d(CONFIG_STEREO, 0); return video_mode(f, w, h); } /* If the mode failed, try decreasing the level of multisampling. */ else if (buffers) { config_set_d(CONFIG_MULTISAMPLE, samples / 2); return video_mode(f, w, h); } /* If that mode failed, try it without reflections. */ else if (stencil) { config_set_d(CONFIG_REFLECTION, 0); return video_mode(f, w, h); } /* If THAT mode failed, punt. */ return 0; }
int video_mode(int f, int w, int h) { int stereo = config_get_d(CONFIG_STEREO) ? 1 : 0; int stencil = config_get_d(CONFIG_REFLECTION) ? 1 : 0; int buffers = config_get_d(CONFIG_MULTISAMPLE) ? 1 : 0; int samples = config_get_d(CONFIG_MULTISAMPLE); int vsync = config_get_d(CONFIG_VSYNC) ? 1 : 0; int hmd = config_get_d(CONFIG_HMD) ? 1 : 0; hmd_free(); SDL_GL_SetAttribute(SDL_GL_STEREO, stereo); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencil); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, buffers); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, vsync); /* Require 16-bit double buffer with 16-bit depth buffer. */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /* Try to set the currently specified mode. */ if (SDL_SetVideoMode(w, h, 0, SDL_OPENGL | (f ? SDL_FULLSCREEN : 0))) { config_set_d(CONFIG_FULLSCREEN, f); config_set_d(CONFIG_WIDTH, w); config_set_d(CONFIG_HEIGHT, h); if (!glext_init()) return 0; glViewport(0, 0, w, h); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_BLEND); #if !ENABLE_OPENGLES glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); #endif glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); /* If GL supports multisample, and SDL got a multisample buffer... */ if (glext_check("ARB_multisample")) { SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers); if (buffers) glEnable(GL_MULTISAMPLE); } /* Attempt manual swap control if SDL's is broken. */ if (vsync && SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &vsync) == -1) sync_init(); /* Set up HMD display if requested. */ if (hmd) hmd_init(); /* Initialize screen snapshotting. */ snapshot_init(); video_show_cursor(); return 1; } /* If the mode failed, try it without stereo. */ else if (stereo) { config_set_d(CONFIG_STEREO, 0); return video_mode(f, w, h); } /* If the mode failed, try decreasing the level of multisampling. */ else if (buffers) { config_set_d(CONFIG_MULTISAMPLE, samples / 2); return video_mode(f, w, h); } /* If that mode failed, try it without reflections. */ else if (stencil) { config_set_d(CONFIG_REFLECTION, 0); return video_mode(f, w, h); } /* If THAT mode failed, punt. */ return 0; }
int video_mode(int f, int w, int h) { int stereo = config_get_d(CONFIG_STEREO) ? 1 : 0; int stencil = config_get_d(CONFIG_REFLECTION) ? 1 : 0; int buffers = config_get_d(CONFIG_MULTISAMPLE) ? 1 : 0; int samples = config_get_d(CONFIG_MULTISAMPLE); int vsync = config_get_d(CONFIG_VSYNC) ? 1 : 0; int hmd = config_get_d(CONFIG_HMD) ? 1 : 0; int highdpi = config_get_d(CONFIG_HIGHDPI) ? 1 : 0; int dpy = config_get_d(CONFIG_DISPLAY); int X = SDL_WINDOWPOS_CENTERED_DISPLAY(dpy); int Y = SDL_WINDOWPOS_CENTERED_DISPLAY(dpy); hmd_free(); if (window) { SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); } #if ENABLE_OPENGLES SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); #endif SDL_GL_SetAttribute(SDL_GL_STEREO, stereo); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencil); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, buffers); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); /* Require 16-bit double buffer with 16-bit depth buffer. */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /* Try to set the currently specified mode. */ log_printf("Creating a window (%dx%d, %s)\n", w, h, (f ? "fullscreen" : "windowed")); window = SDL_CreateWindow("", X, Y, w, h, SDL_WINDOW_OPENGL | (highdpi ? SDL_WINDOW_ALLOW_HIGHDPI : 0) | (f ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)); if (window) { if ((context = SDL_GL_CreateContext(window))) { int buf, smp; SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buf); SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &smp); /* * Work around SDL+WGL returning pixel formats below * minimum specifications instead of failing, thus * bypassing our fallback path. SDL tries to ensure that * WGL plays by the rules, but forgets about extended * context attributes such as multisample. See SDL * Bugzilla #77. */ if (buf < buffers || smp < samples) { log_printf("GL context does not meet minimum specifications\n"); SDL_GL_DeleteContext(context); context = NULL; } } } if (window && context) { set_window_title(TITLE); set_window_icon(ICON); /* * SDL_GetWindowSize can be unreliable when going fullscreen * on OSX (and possibly elsewhere). We should really be * waiting for a resize / size change event, but for now we're * doing this lazy thing instead. */ if (f) { SDL_DisplayMode dm; if (SDL_GetDesktopDisplayMode(video_display(), &dm) == 0) { video.window_w = dm.w; video.window_h = dm.h; } } else { SDL_GetWindowSize(window, &video.window_w, &video.window_h); } if (highdpi) { SDL_GL_GetDrawableSize(window, &video.device_w, &video.device_h); } else { video.device_w = video.window_w; video.device_h = video.window_h; } video.device_scale = (float) video.device_h / (float) video.window_h; log_printf("Created a window (%u, %dx%d, %s)\n", SDL_GetWindowID(window), video.window_w, video.window_h, (f ? "fullscreen" : "windowed")); config_set_d(CONFIG_DISPLAY, video_display()); config_set_d(CONFIG_FULLSCREEN, f); config_set_d(CONFIG_WIDTH, video.window_w); config_set_d(CONFIG_HEIGHT, video.window_h); SDL_GL_SetSwapInterval(vsync); if (!glext_init()) return 0; glViewport(0, 0, video.device_w, video.device_h); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_BLEND); #if !ENABLE_OPENGLES glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); #endif glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); /* If GL supports multisample, and SDL got a multisample buffer... */ if (glext_check("ARB_multisample")) { SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers); if (buffers) glEnable(GL_MULTISAMPLE); } /* Set up HMD display if requested. */ if (hmd) hmd_init(); /* Initialize screen snapshotting. */ snapshot_init(); video_show_cursor(); /* Grab input immediately in HMD mode. */ if (hmd_stat()) SDL_SetWindowGrab(window, SDL_TRUE); return 1; } /* If the mode failed, try it without stereo. */ else if (stereo) { config_set_d(CONFIG_STEREO, 0); return video_mode(f, w, h); } /* If the mode failed, try decreasing the level of multisampling. */ else if (buffers) { config_set_d(CONFIG_MULTISAMPLE, samples / 2); return video_mode(f, w, h); } /* If that mode failed, try it without reflections. */ else if (stencil) { config_set_d(CONFIG_REFLECTION, 0); return video_mode(f, w, h); } /* If THAT mode failed, punt. */ return 0; }
int video_mode(int f, int w, int h) { int stereo = config_get_d(CONFIG_STEREO) ? 1 : 0; int stencil = config_get_d(CONFIG_REFLECTION) ? 1 : 0; int buffers = config_get_d(CONFIG_MULTISAMPLE) ? 1 : 0; int samples = config_get_d(CONFIG_MULTISAMPLE); int vsync = config_get_d(CONFIG_VSYNC) ? 1 : 0; int hmd = config_get_d(CONFIG_HMD) ? 1 : 0; int dpy = config_get_d(CONFIG_DISPLAY); int X = SDL_WINDOWPOS_CENTERED_DISPLAY(dpy); int Y = SDL_WINDOWPOS_CENTERED_DISPLAY(dpy); hmd_free(); if (window) { SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); } SDL_GL_SetAttribute(SDL_GL_STEREO, stereo); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencil); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, buffers); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); /* Require 16-bit double buffer with 16-bit depth buffer. */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /* Try to set the currently specified mode. */ window = SDL_CreateWindow("", X, Y, w, h, SDL_WINDOW_OPENGL | (f ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)); if (window) { set_window_title(TITLE); set_window_icon(ICON); SDL_GetWindowSize(window, &w, &h); config_set_d(CONFIG_DISPLAY, video_display()); config_set_d(CONFIG_FULLSCREEN, f); config_set_d(CONFIG_WIDTH, w); config_set_d(CONFIG_HEIGHT, h); context = SDL_GL_CreateContext(window); SDL_GL_SetSwapInterval(vsync); if (!glext_init()) return 0; glViewport(0, 0, w, h); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_BLEND); #if !ENABLE_OPENGLES glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); #endif glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); /* If GL supports multisample, and SDL got a multisample buffer... */ if (glext_check("ARB_multisample")) { SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers); if (buffers) glEnable(GL_MULTISAMPLE); } /* Set up HMD display if requested. */ if (hmd) hmd_init(); /* Initialize screen snapshotting. */ snapshot_init(); video_show_cursor(); /* Grab input immediately in HMD mode. */ if (hmd_stat()) SDL_SetWindowGrab(window, SDL_TRUE); return 1; } /* If the mode failed, try it without stereo. */ else if (stereo) { config_set_d(CONFIG_STEREO, 0); return video_mode(f, w, h); } /* If the mode failed, try decreasing the level of multisampling. */ else if (buffers) { config_set_d(CONFIG_MULTISAMPLE, samples / 2); return video_mode(f, w, h); } /* If that mode failed, try it without reflections. */ else if (stencil) { config_set_d(CONFIG_REFLECTION, 0); return video_mode(f, w, h); } /* If THAT mode failed, punt. */ return 0; }