int setcolorscheme(SDL_Window *window, int nc, int scheme) { int i; Uint16 red[256]; Uint16 green[256]; Uint16 blue[256]; if (scheme < 0 || scheme > NSCHEMES - 1 || nc > 256 || !window) _throw("Invalid argument"); for (i = 0; i < nc; i++) { red[i] = 0; green[i] = 0; blue[i] = 0; if (scheme == GREY || scheme == RED || scheme == YELLOW || scheme == MAGENTA) red[i] = (i * (256 / nc)) << 8; if (scheme == GREY || scheme == GREEN || scheme == YELLOW || scheme == CYAN) green[i] = (i * (256 / nc)) << 8; if (scheme == GREY || scheme == BLUE || scheme == MAGENTA || scheme == CYAN) blue[i] = (i * (256 / nc)) << 8; } SDL_SetWindowGammaRamp(window, red, green, blue); return 0; bailout: return -1; }
void VideoWrapper::setGammaContrast(float gamma, float contrast) { if (gamma == mGamma && contrast == mContrast) return; mGamma = gamma; mContrast = contrast; mHasSetGammaContrast = true; Uint16 red[256], green[256], blue[256]; for (int i = 0; i < 256; i++) { float k = i/256.0f; k = (k - 0.5f) * contrast + 0.5f; k = pow(k, 1.f/gamma); k *= 256; float value = k*256; if (value > 65535) value = 65535; else if (value < 0) value = 0; red[i] = green[i] = blue[i] = static_cast<Uint16>(value); } if (SDL_SetWindowGammaRamp(mWindow, red, green, blue) < 0) std::cout << "Couldn't set gamma: " << SDL_GetError() << std::endl; }
void gr_opengl_shutdown() { graphics::paths::PathRenderer::shutdown(); opengl_tcache_shutdown(); opengl_tnl_shutdown(); opengl_scene_texture_shutdown(); opengl_post_process_shutdown(); opengl_shader_shutdown(); GL_initted = false; glDeleteVertexArrays(1, &GL_vao); GL_vao = 0; if (GL_original_gamma_ramp != NULL && os::getSDLMainWindow() != nullptr) { SDL_SetWindowGammaRamp( os::getSDLMainWindow(), GL_original_gamma_ramp, (GL_original_gamma_ramp+256), (GL_original_gamma_ramp+512) ); } if (GL_original_gamma_ramp != NULL) { vm_free(GL_original_gamma_ramp); GL_original_gamma_ramp = NULL; } graphic_operations->makeOpenGLContextCurrent(nullptr, nullptr); GL_context = nullptr; }
void gr_opengl_set_gamma(float gamma) { ushort *gamma_ramp = NULL; Gr_gamma = gamma; Gr_gamma_int = int (Gr_gamma*10); // new way - but not while running FRED if (!Fred_running && !Cmdline_no_set_gamma && os::getSDLMainWindow() != nullptr) { gamma_ramp = (ushort*) vm_malloc( 3 * 256 * sizeof(ushort), memory::quiet_alloc); if (gamma_ramp == NULL) { Int3(); return; } memset( gamma_ramp, 0, 3 * 256 * sizeof(ushort) ); // Create the Gamma lookup table opengl_make_gamma_ramp(gamma, gamma_ramp); SDL_SetWindowGammaRamp( os::getSDLMainWindow(), gamma_ramp, (gamma_ramp+256), (gamma_ramp+512) ); vm_free(gamma_ramp); } }
void GLVideoSystem::set_gamma(float gamma) { Uint16 ramp[256]; SDL_CalculateGammaRamp(gamma, ramp); SDL_SetWindowGammaRamp(m_window, ramp, ramp, ramp); }
void SDLRenderer::set_gamma(float gamma) { Uint16 ramp[256]; SDL_CalculateGammaRamp(gamma, ramp); SDL_SetWindowGammaRamp(m_window, ramp, ramp, ramp); }
void SDLBaseVideoSystem::set_gamma(float gamma) { Uint16 ramp[256]; SDL_CalculateGammaRamp(gamma, ramp); SDL_SetWindowGammaRamp(m_sdl_window.get(), ramp, ramp, ramp); }
VideoWrapper::~VideoWrapper() { SDL_SetWindowFullscreen(mWindow, 0); // If user hasn't touched the defaults no need to restore if (mHasSetGammaContrast) SDL_SetWindowGammaRamp(mWindow, mOldSystemGammaRamp, &mOldSystemGammaRamp[256], &mOldSystemGammaRamp[512]); }
/* ================= GLimp_SetGamma ================= */ void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] ) { Uint16 table[3][256]; int i, j; if( !glConfig.deviceSupportsGamma || r_ignorehwgamma->integer > 0 ) return; for (i = 0; i < 256; i++) { table[0][i] = ( ( ( Uint16 ) red[i] ) << 8 ) | red[i]; table[1][i] = ( ( ( Uint16 ) green[i] ) << 8 ) | green[i]; table[2][i] = ( ( ( Uint16 ) blue[i] ) << 8 ) | blue[i]; } #ifdef _WIN32 #include <windows.h> // Win2K and newer put this odd restriction on gamma ramps... { OSVERSIONINFO vinfo; vinfo.dwOSVersionInfoSize = sizeof( vinfo ); GetVersionEx( &vinfo ); if( vinfo.dwMajorVersion >= 5 && vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) { ri.Printf( PRINT_DEVELOPER, "performing gamma clamp.\n" ); for( j = 0 ; j < 3 ; j++ ) { for( i = 0 ; i < 128 ; i++ ) { if( table[ j ] [ i] > ( ( 128 + i ) << 8 ) ) table[ j ][ i ] = ( 128 + i ) << 8; } if( table[ j ] [127 ] > 254 << 8 ) table[ j ][ 127 ] = 254 << 8; } } } #endif // enforce constantly increasing for (j = 0; j < 3; j++) { for (i = 1; i < 256; i++) { if (table[j][i] < table[j][i-1]) table[j][i] = table[j][i-1]; } } if (SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]) < 0) { ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowGammaRamp() failed: %s\n", SDL_GetError() ); } }
/* =============== GL_UpdateGammaRamp =============== */ void GL_UpdateGammaRamp( void ) { if( !glConfig.deviceSupportsGamma ) return; GL_BuildGammaTable(); #ifdef XASH_SDL SDL_SetWindowGammaRamp( host.hWnd, &glState.gammaRamp[0], &glState.gammaRamp[256], &glState.gammaRamp[512] ); #endif }
void UpdateHardwareGamma(void) { float gamma = (vid_gamma->value); Uint16 ramp[256]; CalculateGammaRamp(gamma, ramp, 256); #if SDL_VERSION_ATLEAST(2, 0, 0) if(SDL_SetWindowGammaRamp(window, ramp, ramp, ramp) != 0) { #else if(SDL_SetGammaRamp(ramp, ramp, ramp) < 0) { #endif VID_Printf(PRINT_ALL, "Setting gamma failed: %s\n", SDL_GetError()); } } #endif // X11GAMMA static qboolean IsFullscreen() { #if SDL_VERSION_ATLEAST(2, 0, 0) return !!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN); #else return !!(window->flags & SDL_FULLSCREEN); #endif } static qboolean CreateSDLWindow(int flags) { #if SDL_VERSION_ATLEAST(2, 0, 0) int windowPos = SDL_WINDOWPOS_UNDEFINED; // TODO: support fullscreen on different displays with SDL_WINDOWPOS_UNDEFINED_DISPLAY(displaynum) window = SDL_CreateWindow("Yamagi Quake II", windowPos, windowPos, vid.width, vid.height, flags); if(window == NULL) { return false; } context = SDL_GL_CreateContext(window); if(context == NULL) { SDL_DestroyWindow(window); window = NULL; return false; } return true; #else window = SDL_SetVideoMode(vid.width, vid.height, 0, flags); SDL_EnableUNICODE(SDL_TRUE); return window != NULL; #endif }
/* ================= GLimp_SetGamma ================= */ void GLimp_SetGamma(unsigned short red[256], unsigned short green[256], unsigned short blue[256]) { if ( !SDL_window ) { common->Warning("GLimp_SetGamma called without window"); return; } #if SDL_VERSION_ATLEAST(2, 0, 0) if (SDL_SetWindowGammaRamp( SDL_window, red, green, blue )) #else if (SDL_SetGammaRamp(red, green, blue)) #endif common->Warning("Couldn't set gamma ramp: %s", SDL_GetError()); }
void VID_RestoreGamma( void ) { if( !glConfig.deviceSupportsGamma ) return; // don't touch gamma if multiple instances was running if( VID_EnumerateInstances( ) > 1 ) return; #if defined(XASH_SDL) SDL_SetWindowGammaRamp( host.hWnd, &glState.stateRamp[0], &glState.stateRamp[256], &glState.stateRamp[512] ); #endif }
void WIN_SetGamma( glconfig_t *glConfig, byte red[256], byte green[256], byte blue[256] ) { Uint16 table[3][256]; int i, j; if( !glConfig->deviceSupportsGamma || r_ignorehwgamma->integer > 0 ) return; for (i = 0; i < 256; i++) { table[0][i] = ( ( ( Uint16 ) red[i] ) << 8 ) | red[i]; table[1][i] = ( ( ( Uint16 ) green[i] ) << 8 ) | green[i]; table[2][i] = ( ( ( Uint16 ) blue[i] ) << 8 ) | blue[i]; } #if defined(_WIN32) // Win2K and newer put this odd restriction on gamma ramps... { OSVERSIONINFO vinfo; vinfo.dwOSVersionInfoSize = sizeof( vinfo ); GetVersionEx( &vinfo ); if( vinfo.dwMajorVersion >= 5 && vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) { Com_DPrintf( "performing gamma clamp.\n" ); for( j = 0 ; j < 3 ; j++ ) { for( i = 0 ; i < 128 ; i++ ) { table[j][i] = Q_min(table[j][i], (128 + i) << 8); } table[j][127] = Q_min(table[j][127], 254 << 8); } } } #endif // enforce constantly increasing for (j = 0; j < 3; j++) { for (i = 1; i < 256; i++) { if (table[j][i] < table[j][i-1]) table[j][i] = table[j][i-1]; } } SDL_SetWindowGammaRamp(screen, table[0], table[1], table[2]); }
/** * TODO documentation */ void GLimp_SetGammaRamp( size_t stride, unsigned short size, unsigned short *ramp ) { unsigned short ramp256[3 * 256]; if( size != 256 ) return; memcpy( ramp256, ramp, size * sizeof( *ramp ) ); memcpy( ramp256 + 256, ramp + stride, size * sizeof( *ramp ) ); memcpy( ramp256 + 2 * 256, ramp + 2 * stride, size * sizeof( *ramp ) ); if( SDL_SetWindowGammaRamp( glw_state.sdl_window, ramp256, ramp256 + 256, ramp256 + ( 256 << 1 ) ) == -1 ) { Com_Printf( "SDL_SetWindowGammaRamp(...) failed: ", SDL_GetError() ); } }
void GraphicsManager::setGamma(float gamma) { // Force calling it from the main thread if (!Common::isMainThread()) { Events::MainThreadFunctor<void> functor(boost::bind(&GraphicsManager::setGamma, this, gamma)); return RequestMan.callInMainThread(functor); } _gamma = gamma; uint16* gammaRamp = 0; SDL_CalculateGammaRamp(gamma, gammaRamp); SDL_SetWindowGammaRamp(_screen, gammaRamp, gammaRamp, gammaRamp); delete gammaRamp; }
static int SDL_SetGamma(SDL_Window *win, float red, float green, float blue) { Uint16 red_ramp[256]; Uint16 green_ramp[256]; Uint16 blue_ramp[256]; SDL_CalculateGammaRamp(red, red_ramp); if (green == red) { Com_Memcpy(&green_ramp, &red_ramp, sizeof(red_ramp)); } else { SDL_CalculateGammaRamp(green, green_ramp); } if (blue == red) { Com_Memcpy(blue_ramp, red_ramp, sizeof(red_ramp)); } else { SDL_CalculateGammaRamp(blue, blue_ramp); } return SDL_SetWindowGammaRamp(win, red_ramp, green_ramp, blue_ramp); }
void SetGamma(const uint8_t *red, const uint8_t *green, const uint8_t *blue) { uint16_t table[3][256]; for (int i = 0; i < 256; i++) { table[0][i] = (((uint16_t)red[i]) << 8) | red[i]; table[1][i] = (((uint16_t)green[i]) << 8) | green[i]; table[2][i] = (((uint16_t)blue[i]) << 8) | blue[i]; } #ifdef _WIN32 // Win2K and newer put this odd restriction on gamma ramps... for (int j = 0; j < 3; j++) { for (int i = 0; i < 128; i++) { if (table[j][i] >((128 + i) << 8)) table[j][i] = (128 + i) << 8; } if (table[j][127] > 254 << 8) table[j][127] = 254 << 8; } #endif // enforce constantly increasing for (int j = 0; j < 3; j++) { for (int i = 1; i < 256; i++) { if (table[j][i] < table[j][i - 1]) table[j][i] = table[j][i - 1]; } } if (SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]) < 0) { interface::PrintWarningf("SDL_SetWindowGammaRamp() failed: %s\n", SDL_GetError()); } }
void SetGamma(double fGamma) { Uint16 pRawRamp[256]; SDL_CalculateGammaRamp((float)((std::min<double>)((std::max<double>)(fGamma, 0.0), 1.0)), pRawRamp); SDL_SetWindowGammaRamp(m_Window, pRawRamp, pRawRamp, pRawRamp); }
bool CVideoMode::InitSDL() { ENSURE(!m_IsInitialised); ReadConfig(); EnableS3TC(); // preferred video mode = current desktop settings // (command line params may override these) gfx::GetVideoMode(&m_PreferredW, &m_PreferredH, &m_PreferredBPP, &m_PreferredFreq); int w = m_ConfigW; int h = m_ConfigH; if (m_ConfigFullscreen) { // If fullscreen and no explicit size set, default to the desktop resolution if (w == 0 || h == 0) { w = m_PreferredW; h = m_PreferredH; } } // If no size determined, default to something sensible if (w == 0 || h == 0) { w = DEFAULT_WINDOW_W; h = DEFAULT_WINDOW_H; } if (!m_ConfigFullscreen) { // Limit the window to the screen size (if known) if (m_PreferredW) w = std::min(w, m_PreferredW); if (m_PreferredH) h = std::min(h, m_PreferredH); } int bpp = GetBestBPP(); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); #if !SDL_VERSION_ATLEAST(1, 3, 0) SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, g_VSync ? 1 : 0); #endif #if CONFIG2_GLES && SDL_VERSION_ATLEAST(1, 3, 0) // Require GLES 2.0 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); #endif if (!SetVideoMode(w, h, bpp, m_ConfigFullscreen)) { // Fall back to a smaller depth buffer // (The rendering may be ugly but this helps when running in VMware) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); if (!SetVideoMode(w, h, bpp, m_ConfigFullscreen)) return false; } #if SDL_VERSION_ATLEAST(1, 3, 0) SDL_GL_SetSwapInterval(g_VSync ? 1 : 0); #endif // Work around a bug in the proprietary Linux ATI driver (at least versions 8.16.20 and 8.14.13). // The driver appears to register its own atexit hook on context creation. // If this atexit hook is called before SDL_Quit destroys the OpenGL context, // some kind of double-free problem causes a crash and lockup in the driver. // Calling SDL_Quit twice appears to be harmless, though, and avoids the problem // by destroying the context *before* the driver's atexit hook is called. // (Note that atexit hooks are guaranteed to be called in reverse order of their registration.) atexit(SDL_Quit); // End work around. ogl_Init(); // required after each mode change // (TODO: does that mean we need to call this when toggling fullscreen later?) #if SDL_VERSION_ATLEAST(2, 0, 0) u16 ramp[256]; SDL_CalculateGammaRamp(g_Gamma, ramp); if (SDL_SetWindowGammaRamp(m_Window, ramp, ramp, ramp) < 0) LOGWARNING(L"SDL_SetGamma failed"); #else if (SDL_SetGamma(g_Gamma, g_Gamma, g_Gamma) < 0) LOGWARNING(L"SDL_SetGamma failed"); #endif m_IsInitialised = true; if (!m_ConfigFullscreen) { m_WindowedW = w; m_WindowedH = h; } return true; }
void VID_SetDeviceGammaRamp (unsigned short *ramps) { SDL_SetWindowGammaRamp(sdl_window, ramps, ramps+256,ramps+512); vid_hwgamma_enabled = true; }
void SDLHardwareRenderDevice::resetGamma() { SDL_SetWindowGammaRamp(window, gamma_r, gamma_g, gamma_b); }
/** * @brief GLimp_SetGamma * @param[in] red * @param[in] green * @param[in] blue */ void GLimp_SetGamma(unsigned char red[256], unsigned char green[256], unsigned char blue[256]) { Uint16 table[3][256]; int i, j; if (!cls.glconfig.deviceSupportsGamma || r_ignorehwgamma->integer > 0) { Com_Printf(S_COLOR_YELLOW "Device doesn't support gamma or r_ignorehwgamma is set.\n"); return; } for (i = 0; i < 256; i++) { table[0][i] = ((( Uint16 ) red[i]) << 8) | red[i]; table[1][i] = ((( Uint16 ) green[i]) << 8) | green[i]; table[2][i] = ((( Uint16 ) blue[i]) << 8) | blue[i]; } #ifdef _WIN32 // Win2K and newer put this odd restriction on gamma ramps... { OSVERSIONINFO vinfo; vinfo.dwOSVersionInfoSize = sizeof(vinfo); GetVersionEx(&vinfo); if (vinfo.dwMajorVersion >= 5 && vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { Com_DPrintf("performing gamma clamp.\n"); for (j = 0 ; j < 3 ; j++) { for (i = 0 ; i < 128 ; i++) { if (table[j][i] > ((128 + i) << 8)) { table[j][i] = (128 + i) << 8; } } if (table[j][127] > 254 << 8) { table[j][127] = 254 << 8; } } } } #endif // enforce constantly increasing for (j = 0; j < 3; j++) { for (i = 1; i < 256; i++) { if (table[j][i] < table[j][i - 1]) { table[j][i] = table[j][i - 1]; } } } SDL_SetWindowGammaRamp(main_window, table[0], table[1], table[2]); }
/* Set the gamma level. Based on Darkplaces implementation. */ void Window_SetGamma(unsigned short *usRamp, int iRampSize) { if (!SDL_SetWindowGammaRamp(sMainWindow, usRamp, usRamp + iRampSize, usRamp + iRampSize * 2)) Con_Warning("Failed to set gamma level!\n%s", SDL_GetError()); }
void SDLHardwareRenderDevice::setGamma(float g) { Uint16 ramp[256]; SDL_CalculateGammaRamp(g, ramp); SDL_SetWindowGammaRamp(window, ramp, ramp, ramp); }