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

Go to the source code of this file.

Macros

#define WINDOW_CLASS_NAME   "Quake 2"
 

Functions

void VID_CreateWindow (int width, int height, int stylebits)
 
int SWimp_Init (void *hInstance, void *wndProc)
 
static qboolean SWimp_InitGraphics (void)
 
void SWimp_EndFrame (void)
 
rserr_t SWimp_SetMode (int *pwidth, int *pheight, int mode, qboolean fullscreen)
 
void SWimp_SetPalette (const unsigned char *palette)
 
void SWimp_Shutdown (void)
 
void SWimp_AppActivate (qboolean active)
 
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
 
void Sys_SetFPCW (void)
 

Variables

swwstate_t sww_state
 

Macro Definition Documentation

◆ WINDOW_CLASS_NAME

#define WINDOW_CLASS_NAME   "Quake 2"

Definition at line 43 of file rw_imp.c.

Function Documentation

◆ SWimp_AppActivate()

void SWimp_AppActivate ( qboolean  active)

Definition at line 292 of file rw_imp.c.

293 {
294  if ( active )
295  {
296  if ( sww_state.hWnd )
297  {
298  SetForegroundWindow( sww_state.hWnd );
299  ShowWindow( sww_state.hWnd, SW_RESTORE );
300  }
301  }
302  else
303  {
304  if ( sww_state.hWnd )
305  {
306  if ( sww_state.initializing )
307  return;
308  if ( vid_fullscreen->value )
309  ShowWindow( sww_state.hWnd, SW_MINIMIZE );
310  }
311  }
312 }

Referenced by GetRefAPI().

◆ SWimp_EndFrame()

void SWimp_EndFrame ( void  )

Definition at line 163 of file rw_imp.c.

164 {
165 
166  if (sww_state.palettized)
167  {
168  // holdpal = SelectPalette(hdcScreen, hpalDIB, FALSE);
169  // RealizePalette(hdcScreen);
170  }
171 
172  BitBlt(sww_state.hDC,
173  0, 0,
174  vid.width,
175  vid.height,
177  0, 0,
178  SRCCOPY);
179 
180  if (sww_state.palettized)
181  {
182  // SelectPalette(hdcScreen, holdpal, FALSE);
183  }
184 }

Referenced by GetRefAPI(), and R_CinematicSetPalette().

◆ SWimp_Init()

int SWimp_Init ( void hInstance,
void wndProc 
)

Definition at line 118 of file rw_imp.c.

119 {
120  sww_state.hInstance = ( HINSTANCE ) hInstance;
121  sww_state.wndproc = wndProc;
122 
123  return true;
124 }

Referenced by R_Init().

◆ SWimp_InitGraphics()

static qboolean SWimp_InitGraphics ( void  )
static

Definition at line 135 of file rw_imp.c.

136 {
137  // free resources in use
138  SWimp_Shutdown ();
139 
140  // create a new window
142 
143  // initialize the appropriate subsystem
144  //qb: nuke ddraw
145 
146  if (!DIB_Init(&vid.buffer, &vid.rowbytes))
147  {
148  vid.buffer = 0;
149  vid.rowbytes = 0;
150 
151  return false;
152  }
153 
154  return true;
155 }

Referenced by SWimp_SetMode().

◆ SWimp_SetMode()

rserr_t SWimp_SetMode ( int pwidth,
int pheight,
int  mode,
qboolean  fullscreen 
)

Definition at line 189 of file rw_imp.c.

190 {
191  const char *win_fs[] = { "W", "FS" };
192  rserr_t retval = rserr_ok;
193 
194  ri.Con_Printf (PRINT_ALL, "setting mode %d:", mode );
195 
196  if ( !ri.Vid_GetModeInfo( pwidth, pheight, mode ) )
197  {
198  ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
199  return rserr_invalid_mode;
200  }
201 
202  ri.Con_Printf(PRINT_ALL, " %d %d %s\n", *pwidth, *pheight, win_fs[fullscreen]);
203 
204  sww_state.initializing = true;
205  if (fullscreen) //qb: get rid of 'fullscreen'.
206  {
207  if (!SWimp_InitGraphics())
208  {
209  ri.Cvar_SetValue("vid_fullscreen", !fullscreen); //qb: added
210  vid_fullscreen->modified = true;
211  if (SWimp_InitGraphics())
212  {
213  // mode is legal but not as fullscreen
214  retval = rserr_invalid_fullscreen;
215  }
216  else
217  {
218  // failed to set a valid mode in windowed mode
219  retval = rserr_unknown;
220  }
221  }
222  }
223  else
224  {
225  // failure to set a valid mode in windowed mode
226  if (!SWimp_InitGraphics())
227  {
228  sww_state.initializing = true;
229  return rserr_unknown;
230  }
231  }
232 
233  sw_state.fullscreen = fullscreen;
234 #if 0
235  if ( retval != rserr_unknown )
236  {
237  if ( retval == rserr_invalid_fullscreen ||
238  ( retval == rserr_ok && !fullscreen ) )
239  {
240  SetWindowLong( sww_state.hWnd, GWL_STYLE, WINDOW_STYLE );
241  }
242  }
243 #endif
244  R_GammaCorrectAndSetPalette( ( const unsigned char * ) d_8to24table );
245  sww_state.initializing = true;
246 
247  return retval;
248 }

Referenced by R_BeginFrame().

◆ SWimp_SetPalette()

void SWimp_SetPalette ( const unsigned char *  palette)

Definition at line 257 of file rw_imp.c.

258 {
259  // MGL - what the fuck was kendall doing here?!
260  // clear screen to black and change palette
261  // for (i=0 ; i<vid.height ; i++)
262  // memset (vid.buffer + i*vid.rowbytes, 0, vid.width);
263 
264  if ( !palette )
265  palette = ( const unsigned char * ) sw_state.currentpalette;
266  DIB_SetPalette((const unsigned char *)palette);
267 }

Referenced by R_GammaCorrectAndSetPalette().

◆ SWimp_Shutdown()

void SWimp_Shutdown ( void  )

Definition at line 274 of file rw_imp.c.

275 {
276  ri.Con_Printf( PRINT_ALL, "Shutting down SW imp\n" );
277  DIB_Shutdown();
278 
279  if ( sww_state.hWnd )
280  {
281  ri.Con_Printf( PRINT_ALL, "...destroying window\n" );
282  ShowWindow( sww_state.hWnd, SW_SHOWNORMAL ); // prevents leaving empty slots in the taskbar
283  DestroyWindow (sww_state.hWnd);
284  sww_state.hWnd = NULL;
285  UnregisterClass (WINDOW_CLASS_NAME, sww_state.hInstance);
286  }
287 }

Referenced by R_Shutdown(), and SWimp_InitGraphics().

◆ Sys_MakeCodeWriteable()

void Sys_MakeCodeWriteable ( unsigned long  startaddr,
unsigned long  length 
)

Definition at line 322 of file rw_imp.c.

323 {
324  DWORD flOldProtect;
325 
326  if (!VirtualProtect((LPVOID)startaddr, length, PAGE_READWRITE, &flOldProtect))
327  ri.Sys_Error(ERR_FATAL, "Protection change failed\n");
328 }

Referenced by D_Patch(), and R_Init().

◆ Sys_SetFPCW()

void Sys_SetFPCW ( void  )

Definition at line 351 of file rw_imp.c.

352 {
353 }

Referenced by R_Init().

◆ VID_CreateWindow()

void VID_CreateWindow ( int  width,
int  height,
int  stylebits 
)

Definition at line 45 of file rw_imp.c.

46 {
47  WNDCLASS wc;
48  RECT r;
50  int x, y, w, h;
51  int exstyle;
52 
53  vid_xpos = ri.Cvar_Get ("vid_xpos", "0", 0);
54  vid_ypos = ri.Cvar_Get ("vid_ypos", "0", 0);
55  vid_fullscreen = ri.Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE );
56 
57  if ( vid_fullscreen->value )
58  exstyle = WS_EX_TOPMOST;
59  else
60  exstyle = 0;
61 
62  /* Register the frame class */
63  wc.style = 0;
64  wc.lpfnWndProc = (WNDPROC)sww_state.wndproc;
65  wc.cbClsExtra = 0;
66  wc.cbWndExtra = 0;
67  wc.hInstance = sww_state.hInstance;
68  wc.hIcon = 0;
69  wc.hCursor = LoadCursor (NULL,IDC_ARROW);
70  wc.hbrBackground = (void *)COLOR_GRAYTEXT;
71  wc.lpszMenuName = 0;
72  wc.lpszClassName = WINDOW_CLASS_NAME;
73 
74  if (!RegisterClass (&wc) )
75  ri.Sys_Error (ERR_FATAL, "Couldn't register window class");
76 
77  r.left = 0;
78  r.top = 0;
79  r.right = width;
80  r.bottom = height;
81 
82  AdjustWindowRect (&r, stylebits, FALSE);
83 
84  w = r.right - r.left;
85  h = r.bottom - r.top;
86  x = vid_xpos->value;
87  y = vid_ypos->value;
88 
89  sww_state.hWnd = CreateWindowEx (
90  exstyle,
92  "Quake 2 (Software) "CPUSTRING,
93  stylebits,
94  x, y, w, h,
95  NULL,
96  NULL,
98  NULL);
99 
100  if (!sww_state.hWnd)
101  ri.Sys_Error (ERR_FATAL, "Couldn't create window");
102 
103  ShowWindow( sww_state.hWnd, SW_SHOWNORMAL );
104  UpdateWindow( sww_state.hWnd );
105  SetForegroundWindow( sww_state.hWnd );
106  SetFocus( sww_state.hWnd );
107 
108  // let the sound and input subsystems know about the new window
110 }

Referenced by SWimp_InitGraphics().

Variable Documentation

◆ sww_state

vid_fullscreen
cvar_t * vid_fullscreen
Definition: vid_dll.c:47
rserr_t
rserr_t
Definition: r_local.h:103
height
GLsizei height
Definition: qgl_win.c:69
DIB_Init
qboolean DIB_Init(unsigned char **ppbuffer, int *ppitch)
Definition: rw_dib.c:88
DIB_SetPalette
void DIB_SetPalette(const unsigned char *_pal)
Definition: rw_dib.c:269
WINDOW_CLASS_NAME
#define WINDOW_CLASS_NAME
Definition: rw_imp.c:43
swwstate_t::initializing
qboolean initializing
Definition: rw_win.h:52
viddef_t::buffer
pixel_t * buffer
Definition: r_local.h:94
R_GammaCorrectAndSetPalette
void R_GammaCorrectAndSetPalette(const unsigned char *pal)
Definition: r_main.c:1257
ri
refimport_t ri
Definition: r_main.c:25
refimport_t::Vid_NewWindow
void(* Vid_NewWindow)(int width, int height)
Definition: ref.h:222
cvar_s::modified
qboolean modified
Definition: q_shared.h:330
refimport_t::Cvar_Get
cvar_t *(* Cvar_Get)(char *name, char *value, int flags)
Definition: ref.h:216
x
GLint GLenum GLint x
Definition: qgl_win.c:116
SWimp_Shutdown
void SWimp_Shutdown(void)
Definition: rw_imp.c:274
width
GLint GLsizei width
Definition: qgl_win.c:115
cvar_s
Definition: q_shared.h:324
rserr_unknown
@ rserr_unknown
Definition: r_local.h:110
refimport_t::Vid_GetModeInfo
qboolean(* Vid_GetModeInfo)(int *width, int *height, int mode)
Definition: ref.h:220
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::palettized
qboolean palettized
Definition: rw_win.h:49
viddef_t::rowbytes
int rowbytes
Definition: r_local.h:97
r
GLdouble GLdouble r
Definition: qgl_win.c:336
viddef_t::width
unsigned width
Definition: vid.h:29
SWimp_InitGraphics
static qboolean SWimp_InitGraphics(void)
Definition: rw_imp.c:135
rserr_invalid_mode
@ rserr_invalid_mode
Definition: r_local.h:108
swwstate_t::hInstance
HINSTANCE hInstance
Definition: rw_win.h:28
refimport_t::Sys_Error
void(* Sys_Error)(int err_level, char *str,...)
Definition: ref.h:194
CVAR_ARCHIVE
#define CVAR_ARCHIVE
Definition: q_shared.h:316
viddef_t::height
unsigned height
Definition: vid.h:29
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
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:743
VID_CreateWindow
void VID_CreateWindow(int width, int height, int stylebits)
Definition: rw_imp.c:45
y
GLint y
Definition: qgl_win.c:115
WINDOW_STYLE
#define WINDOW_STYLE
Definition: winquake.h:28
d_8to24table
unsigned d_8to24table[256]
Definition: r_main.c:27
rserr_ok
@ rserr_ok
Definition: r_local.h:105
swstate_s::fullscreen
qboolean fullscreen
Definition: r_local.h:880
swwstate_t::wndproc
void * wndproc
Definition: rw_win.h:29
vid_xpos
cvar_t * vid_xpos
Definition: vid_dll.c:45
swwstate_t::hdcDIBSection
HDC hdcDIBSection
Definition: rw_win.h:33
DWORD
DWORD
Definition: qgl_win.c:49
w
GLdouble GLdouble GLdouble w
Definition: qgl_win.c:291
FALSE
#define FALSE
Definition: stb_vorbis.c:618
refimport_t::Cvar_SetValue
void(* Cvar_SetValue)(char *name, float value)
Definition: ref.h:218
mode
GLenum mode
Definition: qgl_win.c:113
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
vid_ypos
cvar_t * vid_ypos
Definition: vid_dll.c:46
swstate_s::currentpalette
byte currentpalette[1024]
Definition: r_local.h:884
CPUSTRING
#define CPUSTRING
Definition: qcommon.h:86
sw_state
swstate_t sw_state
Definition: r_main.c:49
rserr_invalid_fullscreen
@ rserr_invalid_fullscreen
Definition: r_local.h:107
vid
viddef_t vid
Definition: r_main.c:24