vkQuake2 doxygen  1.0 dev
rw_dib.c File Reference
#include "..\ref_soft\r_local.h"
#include "rw_win.h"

Go to the source code of this file.

Classes

struct  dibinfo
 
struct  identitypalette_t
 

Macros

#define NUM_SYS_COLORS   ( sizeof( s_syspalindices ) / sizeof( int ) )
 

Typedefs

typedef struct dibinfo dibinfo_t
 

Functions

static void DIB_SaveSystemColors (void)
 
static void DIB_RestoreSystemColors (void)
 
qboolean DIB_Init (unsigned char **ppbuffer, int *ppitch)
 
void DIB_SetPalette (const unsigned char *_pal)
 
void DIB_Shutdown (void)
 

Variables

static qboolean s_systemcolors_saved
 
static HGDIOBJ previously_selected_GDI_obj
 
static int s_syspalindices []
 
static int s_oldsyscolors [NUM_SYS_COLORS]
 
static identitypalette_t s_ipal
 

Macro Definition Documentation

◆ NUM_SYS_COLORS

#define NUM_SYS_COLORS   ( sizeof( s_syspalindices ) / sizeof( int ) )

Definition at line 61 of file rw_dib.c.

Typedef Documentation

◆ dibinfo_t

typedef struct dibinfo dibinfo_t

Function Documentation

◆ DIB_Init()

qboolean DIB_Init ( unsigned char **  ppbuffer,
int ppitch 
)

Definition at line 88 of file rw_dib.c.

89 {
90  dibinfo_t dibheader;
91  BITMAPINFO *pbmiDIB = ( BITMAPINFO * ) &dibheader;
92  DEVMODE gdevmode; //qb: for fullscreen
93  int i;
94 
95  memset( &dibheader, 0, sizeof( dibheader ) );
96 
97  /*
98  ** grab a DC
99  */
100  if ( !sww_state.hDC )
101  {
102  if ( ( sww_state.hDC = GetDC( sww_state.hWnd ) ) == NULL )
103  return false;
104  }
105 
106  /*
107  ** figure out if we're running in an 8-bit display mode
108  */
109  if ( GetDeviceCaps( sww_state.hDC, RASTERCAPS ) & RC_PALETTE )
110  {
111  sww_state.palettized = true;
112 
113  // save system colors
114  if ( !s_systemcolors_saved )
115  {
117  s_systemcolors_saved = true;
118  }
119  }
120  else
121  {
122  sww_state.palettized = false;
123  }
124 
125  vid.width = (int)(vid.width / 4) * 4; //qb: multiple of 4 required for DIB
126 
127  /*
128  ** fill in the BITMAPINFO struct
129  */
130  pbmiDIB->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
131  pbmiDIB->bmiHeader.biWidth = vid.width;
132  pbmiDIB->bmiHeader.biHeight = vid.height;
133  pbmiDIB->bmiHeader.biPlanes = 1;
134  pbmiDIB->bmiHeader.biBitCount = 8;
135  pbmiDIB->bmiHeader.biCompression = BI_RGB;
136  pbmiDIB->bmiHeader.biSizeImage = 0;
137  pbmiDIB->bmiHeader.biXPelsPerMeter = 0;
138  pbmiDIB->bmiHeader.biYPelsPerMeter = 0;
139  pbmiDIB->bmiHeader.biClrUsed = 256;
140  pbmiDIB->bmiHeader.biClrImportant = 256;
141 
142  /*
143  ** fill in the palette
144  */
145  for ( i = 0; i < 256; i++ )
146  {
147  dibheader.acolors[i].rgbRed = ( d_8to24table[i] >> 0 ) & 0xff;
148  dibheader.acolors[i].rgbGreen = ( d_8to24table[i] >> 8 ) & 0xff;
149  dibheader.acolors[i].rgbBlue = ( d_8to24table[i] >> 16 ) & 0xff;
150  }
151 
152  /*
153  ** create the DIB section
154  */
155  sww_state.hDIBSection = CreateDIBSection( sww_state.hDC,
156  pbmiDIB,
157  DIB_RGB_COLORS,
159  NULL,
160  0 );
161 
162  if ( sww_state.hDIBSection == NULL )
163  {
164  ri.Con_Printf( PRINT_ALL, "DIB_Init() - CreateDIBSection failed\n" );
165  goto fail;
166  }
167 
168  if ( pbmiDIB->bmiHeader.biHeight > 0 )
169  {
170  // bottom up
171  *ppbuffer = sww_state.pDIBBase + ( vid.height - 1 ) * vid.width;
172  *ppitch = -vid.width;
173  }
174  else
175  {
176  // top down
177  *ppbuffer = sww_state.pDIBBase;
178  *ppitch = vid.width;
179  }
180 
181  MONITORINFOEX monInfo;
182  memset(&monInfo, 0, sizeof(MONITORINFOEX));
183  monInfo.cbSize = sizeof(MONITORINFOEX);
184  GetMonitorInfo( MonitorFromWindow(sww_state.hWnd, MONITOR_DEFAULTTOPRIMARY), (LPMONITORINFO)&monInfo );
185 
186  ChangeDisplaySettingsEx(monInfo.szDevice, NULL, NULL, 0, NULL);
187 
188  if (vid_fullscreen->value) //qb: fullscreen dib
189  {
190 
191  RECT WindowRect;
192  DWORD WindowStyle, ExWindowStyle;
193 
194  WindowRect.top = monInfo.rcMonitor.top;
195  WindowRect.left = monInfo.rcMonitor.left;
196 
197  WindowRect.right = vid.width;
198  WindowRect.bottom = vid.height;
199  memset(&gdevmode, 0, sizeof(gdevmode));
200  gdevmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
201  gdevmode.dmPelsWidth = vid.width;
202  gdevmode.dmPelsHeight = vid.height;
203  gdevmode.dmSize = sizeof (gdevmode);
204 
205  if ( ChangeDisplaySettingsEx( monInfo.szDevice, &gdevmode, NULL, CDS_FULLSCREEN, NULL ) != DISP_CHANGE_SUCCESSFUL )
206  {
207  //ri.Sys_Error(ERR_FATAL, "Couldn't set fullscreen DIB mode");
208  goto fail; //qb: don't panic
209  }
210 
211  GetMonitorInfo( MonitorFromWindow(sww_state.hWnd, MONITOR_DEFAULTTOPRIMARY), (LPMONITORINFO)&monInfo );
212  if (!SetWindowPos(sww_state.hWnd,
213  NULL,
214  monInfo.rcMonitor.left, monInfo.rcMonitor.top,
215  WindowRect.right,
216  WindowRect.bottom,
217  SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOZORDER))
218  {
219  //ri.Sys_Error(ERR_FATAL, "Couldn't resize DIB window");
220  goto fail; //qb: don't panic
221  }
222 
223  WindowStyle = WS_POPUP | WS_SYSMENU | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
224  ExWindowStyle = 0;
225 
226  AdjustWindowRectEx(&WindowRect, WindowStyle, FALSE, 0);
227 
228  SetWindowLong(sww_state.hWnd, GWL_STYLE, WindowStyle | WS_VISIBLE);
229  SetWindowLong(sww_state.hWnd, GWL_EXSTYLE, ExWindowStyle);
230  }
231 
232  /*
233  ** clear the DIB memory buffer
234  */
235  memset(sww_state.pDIBBase, 0x00, vid.width * vid.height); //qb: do black, was 0xff
236 
237  if ( ( sww_state.hdcDIBSection = CreateCompatibleDC( sww_state.hDC ) ) == NULL )
238  {
239  ri.Con_Printf( PRINT_ALL, "DIB_Init() - CreateCompatibleDC failed\n" );
240  goto fail;
241  }
243  {
244  ri.Con_Printf( PRINT_ALL, "DIB_Init() - SelectObject failed\n" );
245  goto fail;
246  }
247 
248  return true;
249 
250 fail:
251  DIB_Shutdown();
252  return false;
253 
254 }

Referenced by SWimp_InitGraphics().

◆ DIB_RestoreSystemColors()

static void DIB_RestoreSystemColors ( void  )
static

Definition at line 417 of file rw_dib.c.

418 {
419  SetSystemPaletteUse( sww_state.hDC, SYSPAL_STATIC );
421 }

Referenced by DIB_Shutdown().

◆ DIB_SaveSystemColors()

static void DIB_SaveSystemColors ( void  )
static

Definition at line 423 of file rw_dib.c.

424 {
425  int i;
426 
427  for ( i = 0; i < NUM_SYS_COLORS; i++ )
428  s_oldsyscolors[i] = GetSysColor( s_syspalindices[i] );
429 }

Referenced by DIB_Init().

◆ DIB_SetPalette()

void DIB_SetPalette ( const unsigned char *  _pal)

Definition at line 269 of file rw_dib.c.

270 {
271  const unsigned char *pal = _pal;
272  LOGPALETTE *pLogPal = ( LOGPALETTE * ) &s_ipal;
273  RGBQUAD colors[256];
274  int i;
275  int ret;
276  HDC hDC = sww_state.hDC;
277 
278  /*
279  ** set the DIB color table
280  */
281  if ( sww_state.hdcDIBSection )
282  {
283  for ( i = 0; i < 256; i++, pal += 4 )
284  {
285  colors[i].rgbRed = pal[0];
286  colors[i].rgbGreen = pal[1];
287  colors[i].rgbBlue = pal[2];
288  colors[i].rgbReserved = 0;
289  }
290 
291  colors[0].rgbRed = 0;
292  colors[0].rgbGreen = 0;
293  colors[0].rgbBlue = 0;
294 
295  colors[255].rgbRed = 0xff;
296  colors[255].rgbGreen = 0xff;
297  colors[255].rgbBlue = 0xff;
298 
299  if ( SetDIBColorTable( sww_state.hdcDIBSection, 0, 256, colors ) == 0 )
300  {
301  ri.Con_Printf( PRINT_ALL, "DIB_SetPalette() - SetDIBColorTable failed\n" );
302  }
303  }
304 
305  /*
306  ** for 8-bit color desktop modes we set up the palette for maximum
307  ** speed by going into an identity palette mode.
308  */
309  if ( sww_state.palettized )
310  {
311  int i;
312  HPALETTE hpalOld;
313 
314  if ( SetSystemPaletteUse( hDC, SYSPAL_NOSTATIC ) == SYSPAL_ERROR )
315  {
316  ri.Sys_Error( ERR_FATAL, "DIB_SetPalette() - SetSystemPaletteUse() failed\n" );
317  }
318 
319  /*
320  ** destroy our old palette
321  */
322  if ( sww_state.hPal )
323  {
324  DeleteObject( sww_state.hPal );
325  sww_state.hPal = 0;
326  }
327 
328  /*
329  ** take up all physical palette entries to flush out anything that's currently
330  ** in the palette
331  */
332  pLogPal->palVersion = 0x300;
333  pLogPal->palNumEntries = 256;
334 
335  for ( i = 0, pal = _pal; i < 256; i++, pal += 4 )
336  {
337  pLogPal->palPalEntry[i].peRed = pal[0];
338  pLogPal->palPalEntry[i].peGreen = pal[1];
339  pLogPal->palPalEntry[i].peBlue = pal[2];
340  pLogPal->palPalEntry[i].peFlags = PC_RESERVED | PC_NOCOLLAPSE;
341  }
342  pLogPal->palPalEntry[0].peRed = 0;
343  pLogPal->palPalEntry[0].peGreen = 0;
344  pLogPal->palPalEntry[0].peBlue = 0;
345  pLogPal->palPalEntry[0].peFlags = 0;
346  pLogPal->palPalEntry[255].peRed = 0xff;
347  pLogPal->palPalEntry[255].peGreen = 0xff;
348  pLogPal->palPalEntry[255].peBlue = 0xff;
349  pLogPal->palPalEntry[255].peFlags = 0;
350 
351  if ( ( sww_state.hPal = CreatePalette( pLogPal ) ) == NULL )
352  {
353  ri.Sys_Error( ERR_FATAL, "DIB_SetPalette() - CreatePalette failed(%x)\n", GetLastError() );
354  }
355 
356  if ( ( hpalOld = SelectPalette( hDC, sww_state.hPal, FALSE ) ) == NULL )
357  {
358  ri.Sys_Error( ERR_FATAL, "DIB_SetPalette() - SelectPalette failed(%x)\n",GetLastError() );
359  }
360 
361  if ( sww_state.hpalOld == NULL )
362  sww_state.hpalOld = hpalOld;
363 
364  if ( ( ret = RealizePalette( hDC ) ) != pLogPal->palNumEntries )
365  {
366  ri.Sys_Error( ERR_FATAL, "DIB_SetPalette() - RealizePalette set %d entries\n", ret );
367  }
368  }
369 }

Referenced by SWimp_SetPalette().

◆ DIB_Shutdown()

void DIB_Shutdown ( void  )

Definition at line 374 of file rw_dib.c.

375 {
378 
379  if ( sww_state.hPal )
380  {
381  DeleteObject( sww_state.hPal );
382  sww_state.hPal = 0;
383  }
384 
385  if ( sww_state.hpalOld )
386  {
387  SelectPalette( sww_state.hDC, sww_state.hpalOld, FALSE );
388  RealizePalette( sww_state.hDC );
390  }
391 
392  if ( sww_state.hdcDIBSection )
393  {
395  DeleteDC( sww_state.hdcDIBSection );
397  }
398 
399  if ( sww_state.hDIBSection )
400  {
401  DeleteObject( sww_state.hDIBSection );
404  }
405 
406  if ( sww_state.hDC )
407  {
408  ReleaseDC( sww_state.hWnd, sww_state.hDC );
409  sww_state.hDC = 0;
410  }
411 }

Referenced by DIB_Init(), and SWimp_Shutdown().

Variable Documentation

◆ previously_selected_GDI_obj

HGDIOBJ previously_selected_GDI_obj
static

Definition at line 35 of file rw_dib.c.

Referenced by DIB_Init(), and DIB_Shutdown().

◆ s_ipal

identitypalette_t s_ipal
static

Definition at line 78 of file rw_dib.c.

Referenced by DIB_SetPalette().

◆ s_oldsyscolors

int s_oldsyscolors[NUM_SYS_COLORS]
static

Definition at line 63 of file rw_dib.c.

Referenced by DIB_RestoreSystemColors(), and DIB_SaveSystemColors().

◆ s_syspalindices

int s_syspalindices[]
static
Initial value:
=
{
COLOR_ACTIVEBORDER,
COLOR_ACTIVECAPTION,
COLOR_APPWORKSPACE,
COLOR_BACKGROUND,
COLOR_BTNFACE,
COLOR_BTNSHADOW,
COLOR_BTNTEXT,
COLOR_CAPTIONTEXT,
COLOR_GRAYTEXT,
COLOR_HIGHLIGHT,
COLOR_HIGHLIGHTTEXT,
COLOR_INACTIVEBORDER,
COLOR_INACTIVECAPTION,
COLOR_MENU,
COLOR_MENUTEXT,
COLOR_SCROLLBAR,
COLOR_WINDOW,
COLOR_WINDOWFRAME,
COLOR_WINDOWTEXT
}

Definition at line 37 of file rw_dib.c.

Referenced by DIB_RestoreSystemColors(), and DIB_SaveSystemColors().

◆ s_systemcolors_saved

qboolean s_systemcolors_saved
static

Definition at line 33 of file rw_dib.c.

Referenced by DIB_Init(), and DIB_Shutdown().

vid_fullscreen
cvar_t * vid_fullscreen
Definition: vid_dll.c:47
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
s_ipal
static identitypalette_t s_ipal
Definition: rw_dib.c:78
ri
refimport_t ri
Definition: r_main.c:25
i
int i
Definition: q_shared.c:305
previously_selected_GDI_obj
static HGDIOBJ previously_selected_GDI_obj
Definition: rw_dib.c:35
swwstate_t::pDIBBase
unsigned char * pDIBBase
Definition: rw_win.h:35
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:202
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:751
swwstate_t::hPal
HPALETTE hPal
Definition: rw_win.h:37
swwstate_t::palettized
qboolean palettized
Definition: rw_win.h:49
viddef_t::width
unsigned width
Definition: vid.h:29
HDC
HDC(WINAPI *qwglGetCurrentDC)(VOID)
refimport_t::Sys_Error
void(* Sys_Error)(int err_level, char *str,...)
Definition: ref.h:194
viddef_t::height
unsigned height
Definition: vid.h:29
DIB_SaveSystemColors
static void DIB_SaveSystemColors(void)
Definition: rw_dib.c:423
cvar_s::value
float value
Definition: q_shared.h:331
NULL
#define NULL
Definition: q_shared.h:67
DIB_Shutdown
void DIB_Shutdown(void)
Definition: rw_dib.c:374
DIB_RestoreSystemColors
static void DIB_RestoreSystemColors(void)
Definition: rw_dib.c:417
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:743
dibinfo::acolors
RGBQUAD acolors[256]
Definition: rw_dib.c:68
d_8to24table
unsigned d_8to24table[256]
Definition: r_main.c:27
swwstate_t::hpalOld
HPALETTE hpalOld
Definition: rw_win.h:38
swwstate_t::hdcDIBSection
HDC hdcDIBSection
Definition: rw_win.h:33
s_syspalindices
static int s_syspalindices[]
Definition: rw_dib.c:37
DWORD
DWORD
Definition: qgl_win.c:49
dibinfo
Definition: rw_dib.c:65
FALSE
#define FALSE
Definition: stb_vorbis.c:618
sww_state
swwstate_t sww_state
Definition: rw_imp.c:38
swwstate_t::hWnd
HWND hWnd
Definition: rw_win.h:31
swwstate_t::hDC
HDC hDC
Definition: rw_win.h:30
NUM_SYS_COLORS
#define NUM_SYS_COLORS
Definition: rw_dib.c:61
s_systemcolors_saved
static qboolean s_systemcolors_saved
Definition: rw_dib.c:33
s_oldsyscolors
static int s_oldsyscolors[NUM_SYS_COLORS]
Definition: rw_dib.c:63
swwstate_t::hDIBSection
HBITMAP hDIBSection
Definition: rw_win.h:34
vid
viddef_t vid
Definition: r_main.c:24