doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
win_gamma.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 /*
29 ** WIN_GAMMA.C
30 */
31 #include <assert.h>
32 #include "win_local.h"
33 #include "../../renderer/tr_local.h"
34 
35 static unsigned short s_oldHardwareGamma[3][256];
36 
37 /*
38 ** WG_GetOldGammaRamp
39 **
40 */
41 void WG_GetOldGammaRamp( void )
42 {
43  HDC hDC;
44 
45  hDC = GetDC( GetDesktopWindow() );
46  GetDeviceGammaRamp( hDC, s_oldHardwareGamma );
47  ReleaseDC( GetDesktopWindow(), hDC );
48 
49 
50 /*
51 ** GLimp_SetGamma
52 **
53 */
54 void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] )
55 {
56  unsigned short table[3][256];
57  int i;
58 
59  if ( !glw_state.hDC )
60  {
61  return;
62  }
63 
64  for ( i = 0; i < 256; i++ )
65  {
66  table[0][i] = ( ( ( unsigned short ) red[i] ) << 8 ) | red[i];
67  table[1][i] = ( ( ( unsigned short ) green[i] ) << 8 ) | green[i];
68  table[2][i] = ( ( ( unsigned short ) blue[i] ) << 8 ) | blue[i];
69  }
70 
71  if ( !SetDeviceGammaRamp( glw_state.hDC, table ) ) {
72  common->Printf( "WARNING: SetDeviceGammaRamp failed.\n" );
73  }
74 }
75 
76 /*
77 ** WG_RestoreGamma
78 */
79 void WG_RestoreGamma( void )
80 {
81  HDC hDC;
82 
83  // if we never read in a reasonable looking
84  // table, don't write it out
85  if ( s_oldHardwareGamma[0][255] == 0 ) {
86  return;
87  }
88 
89  hDC = GetDC( GetDesktopWindow() );
90  SetDeviceGammaRamp( hDC, s_oldHardwareGamma );
91  ReleaseDC( GetDesktopWindow(), hDC );
92 }
93 
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glext.h:2846
GLclampf GLclampf blue
Definition: glext.h:2843
int i
Definition: process.py:33
void WG_GetOldGammaRamp(void)
Definition: win_gamma.cpp:41
idCommon * common
Definition: Common.cpp:206
HDC hDC
Definition: wglext.h:383
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(void)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
glwstate_t glw_state
Definition: macosx_glimp.mm:56
void GLimp_SetGamma(unsigned short red[256], unsigned short green[256], unsigned short blue[256])
Definition: dedicated.cpp:79
GLclampf green
Definition: glext.h:2843