2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // gl_vidnt.c -- NT GL vid component
27 #define MAX_MODE_LIST 30
28 #define VID_ROW_SIZE 3
29 #define MAXWIDTH 10000
30 #define MAXHEIGHT 10000
32 #define MODE_WINDOWED 0
33 #define NO_MODE (MODE_WINDOWED - 1)
34 #define MODE_FULLSCREEN_DEFAULT (MODE_WINDOWED + 1)
53 lmode_t lowresmodes[] = {
60 qboolean scr_skipupdate;
62 static vmode_t modelist[MAX_MODE_LIST];
64 static vmode_t badmode;
66 static DEVMODE gdevmode;
67 static qboolean vid_initialized = false;
68 static qboolean windowed, leavecurrentmode;
69 static qboolean vid_canalttab = false;
70 static qboolean vid_wassuspended = false;
71 static int vid_usingmouse;
72 extern qboolean mouseactive; // from in_win.c
75 int DIBWidth, DIBHeight;
77 DWORD WindowStyle, ExWindowStyle;
81 int vid_modenum = NO_MODE;
83 int vid_default = MODE_WINDOWED;
84 static int windowed_default;
85 unsigned char vid_curpal[256*3];
90 HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
95 modestate_t modestate = MS_UNINIT;
97 void VID_MenuDraw (void);
98 void VID_MenuKey (int key);
100 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
101 void AppActivate(BOOL fActive, BOOL minimize);
102 char *VID_GetModeDescription (int mode);
103 void ClearAllStates (void);
104 void VID_UpdateWindowStatus (void);
106 //====================================
108 int window_center_x, window_center_y, window_x, window_y, window_width, window_height;
111 // direct draw software compatability stuff
113 void CenterWindow(HWND hWndCenter, int width, int height, BOOL lefttopjustify)
115 int CenterX, CenterY;
117 CenterX = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
118 CenterY = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
119 if (CenterX > CenterY*2)
120 CenterX >>= 1; // dual screens
121 CenterX = (CenterX < 0) ? 0: CenterX;
122 CenterY = (CenterY < 0) ? 0: CenterY;
123 SetWindowPos (hWndCenter, NULL, CenterX, CenterY, 0, 0,
124 SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
127 qboolean VID_SetWindowedMode (int modenum)
129 int lastmodestate, width, height;
132 lastmodestate = modestate;
134 WindowRect.top = WindowRect.left = 0;
136 WindowRect.right = modelist[modenum].width;
137 WindowRect.bottom = modelist[modenum].height;
139 DIBWidth = modelist[modenum].width;
140 DIBHeight = modelist[modenum].height;
142 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
146 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
148 width = rect.right - rect.left;
149 height = rect.bottom - rect.top;
151 // Create the DIB window
152 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
155 Sys_Error ("Couldn't create DIB window");
157 // Center and show the DIB window
158 CenterWindow(mainwindow, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, false);
160 ShowWindow (mainwindow, SW_SHOWDEFAULT);
161 UpdateWindow (mainwindow);
163 modestate = MS_WINDOWED;
165 if (vid.conheight > modelist[modenum].height)
166 vid.conheight = modelist[modenum].height;
167 if (vid.conwidth > modelist[modenum].width)
168 vid.conwidth = modelist[modenum].width;
170 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
171 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
177 qboolean VID_SetFullDIBMode (int modenum)
179 int lastmodestate, width, height;
182 if (!leavecurrentmode)
184 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
185 gdevmode.dmBitsPerPel = modelist[modenum].bpp;
186 gdevmode.dmPelsWidth = modelist[modenum].width << modelist[modenum].halfscreen;
187 gdevmode.dmPelsHeight = modelist[modenum].height;
188 gdevmode.dmSize = sizeof (gdevmode);
190 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
191 Sys_Error ("Couldn't set fullscreen DIB mode");
194 lastmodestate = modestate;
195 modestate = MS_FULLDIB;
197 WindowRect.top = WindowRect.left = 0;
199 WindowRect.right = modelist[modenum].width;
200 WindowRect.bottom = modelist[modenum].height;
202 DIBWidth = modelist[modenum].width;
203 DIBHeight = modelist[modenum].height;
205 WindowStyle = WS_POPUP;
209 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
211 width = rect.right - rect.left;
212 height = rect.bottom - rect.top;
214 // Create the DIB window
215 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
218 Sys_Error ("Couldn't create DIB window");
220 ShowWindow (mainwindow, SW_SHOWDEFAULT);
221 UpdateWindow (mainwindow);
223 if (vid.conheight > modelist[modenum].height)
224 vid.conheight = modelist[modenum].height;
225 if (vid.conwidth > modelist[modenum].width)
226 vid.conwidth = modelist[modenum].width;
228 // needed because we're not getting WM_MOVE messages fullscreen on NT
232 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
233 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
239 int VID_SetMode (int modenum)
245 if ((windowed && (modenum != 0)) || (!windowed && (modenum < 1)) || (!windowed && (modenum >= nummodes)))
246 Sys_Error ("Bad video mode\n");
250 if (vid_modenum == NO_MODE)
251 original_mode = windowed_default;
253 original_mode = vid_modenum;
255 // Set either the fullscreen or windowed mode
256 if (modelist[modenum].type == MS_WINDOWED)
257 stat = VID_SetWindowedMode(modenum);
258 else if (modelist[modenum].type == MS_FULLDIB)
259 stat = VID_SetFullDIBMode(modenum);
261 Sys_Error ("VID_SetMode: Bad mode type in modelist");
263 window_width = DIBWidth;
264 window_height = DIBHeight;
265 VID_UpdateWindowStatus ();
270 Sys_Error ("Couldn't set video mode");
272 // now we try to make sure we get the focus on the mode switch, because
273 // sometimes in some systems we don't. We grab the foreground, then
274 // finish setting up, pump all our messages, and sleep for a little while
275 // to let messages finish bouncing around the system, then we put
276 // ourselves at the top of the z order, then grab the foreground again,
277 // Who knows if it helps, but it probably doesn't hurt
278 SetForegroundWindow (mainwindow);
279 vid_modenum = modenum;
280 Cvar_SetValue ("vid_mode", (float)vid_modenum);
282 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
284 TranslateMessage (&msg);
285 DispatchMessage (&msg);
290 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
292 SetForegroundWindow (mainwindow);
294 // fix the leftover Alt from any Alt-Tab or the like that switched us away
298 Con_SafePrintf ("Video mode %s initialized.\n", VID_GetModeDescription (vid_modenum));
306 VID_UpdateWindowStatus
309 void VID_UpdateWindowStatus (void)
311 window_rect.left = window_x;
312 window_rect.top = window_y;
313 window_rect.right = window_x + window_width;
314 window_rect.bottom = window_y + window_height;
315 window_center_x = (window_rect.left + window_rect.right) / 2;
316 window_center_y = (window_rect.top + window_rect.bottom) / 2;
318 IN_UpdateClipCursor ();
322 //====================================
329 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
332 *width = WindowRect.right - WindowRect.left;
333 *height = WindowRect.bottom - WindowRect.top;
337 void VID_Finish (void)
340 if (r_render.integer && !scr_skipupdate)
346 // handle the mouse state when windowed if that's changed
347 vid_usemouse = false;
348 if (vid_mouse.integer && key_dest == key_game)
350 if (modestate == MS_FULLDIB)
352 if (!vid_activewindow)
353 vid_usemouse = false;
358 vid_usingmouse = true;
367 vid_usingmouse = false;
368 IN_DeactivateMouse ();
374 void VID_SetDefaultMode (void)
376 IN_DeactivateMouse ();
379 void VID_RestoreSystemGamma(void);
381 void VID_Shutdown (void)
390 vid_canalttab = false;
391 hRC = wglGetCurrentContext();
392 hDC = wglGetCurrentDC();
394 wglMakeCurrent(NULL, NULL);
396 // LordHavoc: free textures before closing (may help NVIDIA)
397 for (i = 0;i < 8192;i++)
399 qglDeleteTextures(8192, temp);
402 wglDeleteContext(hRC);
404 if (hDC && mainwindow)
405 ReleaseDC(mainwindow, hDC);
407 if (modestate == MS_FULLDIB)
408 ChangeDisplaySettings (NULL, 0);
410 if (maindc && mainwindow)
411 ReleaseDC (mainwindow, maindc);
413 AppActivate(false, false);
415 VID_RestoreSystemGamma();
422 //==========================================================================
425 BOOL bSetupPixelFormat(HDC hDC)
427 static PIXELFORMATDESCRIPTOR pfd = {
428 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
430 PFD_DRAW_TO_WINDOW // support window
431 | PFD_SUPPORT_OPENGL // support OpenGL
432 | PFD_DOUBLEBUFFER , // double buffered
433 PFD_TYPE_RGBA, // RGBA type
434 24, // 24-bit color depth
435 0, 0, 0, 0, 0, 0, // color bits ignored
436 0, // no alpha buffer
437 0, // shift bit ignored
438 0, // no accumulation buffer
439 0, 0, 0, 0, // accum bits ignored
440 32, // 32-bit z-buffer
441 0, // no stencil buffer
442 0, // no auxiliary buffer
443 PFD_MAIN_PLANE, // main layer
445 0, 0, 0 // layer masks ignored
449 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
451 MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
455 if (SetPixelFormat(hDC, pixelformat, &pfd) == false)
457 MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
466 qbyte scantokey[128] =
468 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
469 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
470 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
471 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
472 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
473 K_F6 ,K_F7 ,K_F8 ,K_F9 ,K_F10,K_PAUSE,0 ,K_HOME,K_UPARROW,K_PGUP,'-' ,K_LEFTARROW,'5' ,K_RIGHTARROW,'+' ,K_END , // 4
474 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
475 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
476 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
484 Map from windows to quake keynums
487 int MapKey (int key, int virtualkey)
492 if (scantokey[key] == 0)
493 Con_DPrintf("key 0x%02x has no translation\n", key);
494 return scantokey[key];
498 ===================================================================
502 ===================================================================
510 void ClearAllStates (void)
514 // send an up event for each key, to make sure the server clears them all
515 for (i=0 ; i<256 ; i++)
517 Key_Event (i, false);
524 void VID_RestoreGameGamma(void);
525 extern qboolean host_loopactive;
527 void AppActivate(BOOL fActive, BOOL minimize)
528 /****************************************************************************
530 * Function: AppActivate
531 * Parameters: fActive - True if app is activating
533 * Description: If the application is activating, then swap the system
534 * into SYSPAL_NOSTATIC mode so that our palettes will display
537 ****************************************************************************/
539 static BOOL sound_active;
541 vid_activewindow = fActive;
542 Minimized = minimize;
544 // enable/disable sound on focus gain/loss
545 if (!vid_activewindow && sound_active)
548 sound_active = false;
550 else if (vid_activewindow && !sound_active)
558 if (modestate == MS_FULLDIB)
560 if (vid_canalttab && vid_wassuspended)
562 vid_wassuspended = false;
563 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
564 ShowWindow(mainwindow, SW_SHOWNORMAL);
567 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
568 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
571 VID_RestoreGameGamma();
576 vid_usingmouse = false;
577 IN_DeactivateMouse ();
579 if (modestate == MS_FULLDIB && vid_canalttab)
581 ChangeDisplaySettings (NULL, 0);
582 vid_wassuspended = true;
584 VID_RestoreSystemGamma();
588 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
590 /* main window procedure */
591 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
594 int fActive, fMinimized, temp;
595 extern unsigned int uiWheelMessage;
597 if ( uMsg == uiWheelMessage )
598 uMsg = WM_MOUSEWHEEL;
603 if (modestate == MS_FULLDIB)
604 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
611 window_x = (int) LOWORD(lParam);
612 window_y = (int) HIWORD(lParam);
613 VID_UpdateWindowStatus ();
618 Key_Event (MapKey(lParam, wParam), true);
623 Key_Event (MapKey(lParam, wParam), false);
627 // keep Alt-Space from happening
630 // this is complicated because Win32 seems to pack multiple mouse events into
631 // one update sometimes, so we always check all states and look for events
641 if (wParam & MK_LBUTTON)
644 if (wParam & MK_RBUTTON)
647 if (wParam & MK_MBUTTON)
650 IN_MouseEvent (temp);
654 // JACK: This is the mouse wheel with the Intellimouse
655 // Its delta is either positive or neg, and we generate the proper
658 if ((short) HIWORD(wParam) > 0) {
659 Key_Event(K_MWHEELUP, true);
660 Key_Event(K_MWHEELUP, false);
662 Key_Event(K_MWHEELDOWN, true);
663 Key_Event(K_MWHEELDOWN, false);
671 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
677 fActive = LOWORD(wParam);
678 fMinimized = (BOOL) HIWORD(wParam);
679 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
681 // fix the leftover Alt from any Alt-Tab or the like that switched us away
689 DestroyWindow (mainwindow);
696 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
700 /* pass all unhandled messages to DefWindowProc */
701 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
705 /* return 1 if handled message, 0 if not */
715 int VID_NumModes (void)
726 vmode_t *VID_GetModePtr (int modenum)
729 if ((modenum >= 0) && (modenum < nummodes))
730 return &modelist[modenum];
738 VID_GetModeDescription
741 char *VID_GetModeDescription (int mode)
745 static char temp[100];
747 if ((mode < 0) || (mode >= nummodes))
750 if (!leavecurrentmode)
752 pv = VID_GetModePtr (mode);
753 pinfo = pv->modedesc;
757 sprintf (temp, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
765 // KJB: Added this to return the mode driver name in description for console
767 char *VID_GetExtModeDescription (int mode)
769 static char pinfo[40];
772 if ((mode < 0) || (mode >= nummodes))
775 pv = VID_GetModePtr (mode);
776 if (modelist[mode].type == MS_FULLDIB)
778 if (!leavecurrentmode)
779 sprintf(pinfo,"%s fullscreen", pv->modedesc);
781 sprintf (pinfo, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
785 if (modestate == MS_WINDOWED)
786 sprintf(pinfo, "%s windowed", pv->modedesc);
788 sprintf(pinfo, "windowed");
797 VID_DescribeCurrentMode_f
800 void VID_DescribeCurrentMode_f (void)
802 Con_Printf ("%s\n", VID_GetExtModeDescription (vid_modenum));
811 void VID_NumModes_f (void)
814 Con_Printf ("%d video mode is available\n", nummodes);
816 Con_Printf ("%d video modes are available\n", nummodes);
825 void VID_DescribeMode_f (void)
829 modenum = atoi (Cmd_Argv(1));
831 t = leavecurrentmode;
832 leavecurrentmode = 0;
834 Con_Printf ("%s\n", VID_GetExtModeDescription (modenum));
836 leavecurrentmode = t;
845 void VID_DescribeModes_f (void)
851 lnummodes = VID_NumModes ();
853 t = leavecurrentmode;
854 leavecurrentmode = 0;
856 for (i=1 ; i<lnummodes ; i++)
858 pv = VID_GetModePtr (i);
859 pinfo = VID_GetExtModeDescription (i);
860 Con_Printf ("%2d: %s\n", i, pinfo);
863 leavecurrentmode = t;
866 void VID_AddMode(int type, int width, int height, int modenum, int halfscreen, int dib, int fullscreen, int bpp)
869 if (nummodes >= MAX_MODE_LIST)
871 modelist[nummodes].type = type;
872 modelist[nummodes].width = width;
873 modelist[nummodes].height = height;
874 modelist[nummodes].modenum = modenum;
875 modelist[nummodes].halfscreen = halfscreen;
876 modelist[nummodes].dib = dib;
877 modelist[nummodes].fullscreen = fullscreen;
878 modelist[nummodes].bpp = bpp;
880 sprintf (modelist[nummodes].modedesc, "%dx%d", width, height);
882 sprintf (modelist[nummodes].modedesc, "%dx%dx%d", width, height, bpp);
883 for (i = 0;i < nummodes;i++)
885 if (!memcmp(&modelist[i], &modelist[nummodes], sizeof(vmode_t)))
891 void VID_InitDIB (HINSTANCE hInstance)
896 // Register the frame class
898 wc.lpfnWndProc = (WNDPROC)MainWndProc;
901 wc.hInstance = hInstance;
903 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
904 wc.hbrBackground = NULL;
906 wc.lpszClassName = gamename;
908 if (!RegisterClass (&wc) )
909 Sys_Error ("Couldn't register window class");
911 if (COM_CheckParm("-width"))
912 w = atoi(com_argv[COM_CheckParm("-width")+1]);
919 if (COM_CheckParm("-height"))
920 h = atoi(com_argv[COM_CheckParm("-height")+1]);
927 VID_AddMode(MS_WINDOWED, w, h, 0, 0, 1, 0, 0);
936 void VID_InitFullDIB (HINSTANCE hInstance)
940 int originalnummodes;
947 // enumerate >8 bpp modes
948 originalnummodes = nummodes;
953 stat = EnumDisplaySettings (NULL, modenum, &devmode);
955 if ((devmode.dmBitsPerPel >= 15) && (devmode.dmPelsWidth <= MAXWIDTH) && (devmode.dmPelsHeight <= MAXHEIGHT) && (nummodes < MAX_MODE_LIST))
957 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
959 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
961 // if the width is more than twice the height, reduce it by half because this
962 // is probably a dual-screen monitor
963 if ((!COM_CheckParm("-noadjustaspect")) && (devmode.dmPelsWidth > (devmode.dmPelsHeight << 1)))
964 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth >> 1, devmode.dmPelsHeight, 0, 1, 1, 1, devmode.dmBitsPerPel);
966 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
974 // see if there are any low-res modes that aren't being reported
975 numlowresmodes = sizeof(lowresmodes) / sizeof(lowresmodes[0]);
981 for (j=0 ; (j<numlowresmodes) && (nummodes < MAX_MODE_LIST) ; j++)
983 devmode.dmBitsPerPel = bpp;
984 devmode.dmPelsWidth = lowresmodes[j].width;
985 devmode.dmPelsHeight = lowresmodes[j].height;
986 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
988 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
989 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
1008 if (nummodes == originalnummodes)
1009 Con_SafePrintf ("No fullscreen DIB modes found\n");
1012 //static int grabsysgamma = true;
1013 WORD systemgammaramps[3][256], currentgammaramps[3][256];
1015 int VID_SetGamma(float prescale, float gamma, float scale, float base)
1021 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
1022 for (i = 0;i < 256;i++)
1023 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
1025 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
1027 ReleaseDC (NULL, hdc);
1028 return i; // return success or failure
1031 void VID_RestoreGameGamma(void)
1033 VID_UpdateGamma(true);
1036 void VID_GetSystemGamma(void)
1041 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1043 ReleaseDC (NULL, hdc);
1046 void VID_RestoreSystemGamma(void)
1051 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1053 ReleaseDC (NULL, hdc);
1061 void VID_Init (void)
1064 int basenummodes, width, height = 0, bpp, findbpp, done;
1070 memset(&devmode, 0, sizeof(devmode));
1072 Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
1073 Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
1074 Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
1075 Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);
1077 VID_GetSystemGamma();
1079 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
1081 InitCommonControls();
1083 VID_InitDIB (global_hInstance);
1084 basenummodes = nummodes = 1;
1086 VID_InitFullDIB (global_hInstance);
1088 if (COM_CheckParm("-window"))
1092 if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
1093 Sys_Error ("Can't run in non-RGB mode");
1095 ReleaseDC (NULL, hdc);
1099 vid_default = MODE_WINDOWED;
1104 Sys_Error ("No RGB fullscreen modes available");
1108 if (COM_CheckParm("-mode"))
1109 vid_default = atoi(com_argv[COM_CheckParm("-mode")+1]);
1112 if (COM_CheckParm("-current"))
1114 modelist[MODE_FULLSCREEN_DEFAULT].width = GetSystemMetrics (SM_CXSCREEN);
1115 modelist[MODE_FULLSCREEN_DEFAULT].height = GetSystemMetrics (SM_CYSCREEN);
1116 vid_default = MODE_FULLSCREEN_DEFAULT;
1117 leavecurrentmode = 1;
1121 if (COM_CheckParm("-width"))
1122 width = atoi(com_argv[COM_CheckParm("-width")+1]);
1126 if (COM_CheckParm("-bpp"))
1128 bpp = atoi(com_argv[COM_CheckParm("-bpp")+1]);
1137 if (COM_CheckParm("-height"))
1138 height = atoi(com_argv[COM_CheckParm("-height")+1]);
1140 // if they want to force it, add the specified mode to the list
1141 if (COM_CheckParm("-force") && (nummodes < MAX_MODE_LIST))
1142 VID_AddMode(MS_FULLDIB, width, height, 0, 0, 1, 1, bpp);
1148 if (COM_CheckParm("-height"))
1150 height = atoi(com_argv[COM_CheckParm("-height")+1]);
1152 for (i=1, vid_default=0 ; i<nummodes ; i++)
1154 if ((modelist[i].width == width) && (modelist[i].height == height) && (modelist[i].bpp == bpp))
1164 for (i=1, vid_default=0 ; i<nummodes ; i++)
1166 if ((modelist[i].width == width) && (modelist[i].bpp == bpp))
1181 case 15: bpp = 16;break;
1182 case 16: bpp = 32;break;
1183 case 32: bpp = 24;break;
1184 case 24: done = 1;break;
1194 Sys_Error ("Specified video mode not available");
1199 vid_initialized = true;
1201 if ((i = COM_CheckParm("-conwidth")) != 0)
1202 vid.conwidth = atoi(com_argv[i+1]);
1206 vid.conwidth &= 0xfff8; // make it a multiple of eight
1208 if (vid.conwidth < 320)
1211 // pick a conheight that matches with correct aspect
1212 vid.conheight = vid.conwidth*3 / 4;
1214 if ((i = COM_CheckParm("-conheight")) != 0)
1215 vid.conheight = atoi(com_argv[i+1]);
1216 if (vid.conheight < 200)
1217 vid.conheight = 200;
1219 VID_SetMode (vid_default);
1221 maindc = GetDC(mainwindow);
1222 bSetupPixelFormat(maindc);
1224 baseRC = wglCreateContext( maindc );
1226 Sys_Error ("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.");
1227 if (!wglMakeCurrent( maindc, baseRC ))
1228 Sys_Error ("wglMakeCurrent failed");
1232 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
1233 if (strncasecmp(gl_vendor,"ATI",3)==0)
1235 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
1238 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
1241 vid_realmode = vid_modenum;
1243 vid_menudrawfn = VID_MenuDraw;
1244 vid_menukeyfn = VID_MenuKey;
1246 strcpy (badmode.modedesc, "Bad mode");
1247 vid_canalttab = true;
1253 //========================================================
1255 //========================================================
1257 extern void M_Menu_Options_f (void);
1258 extern void M_Print (float cx, float cy, char *str);
1259 extern void M_PrintWhite (float cx, float cy, char *str);
1260 extern void M_DrawCharacter (float cx, float cy, int num);
1261 extern void M_DrawPic (float cx, float cy, char *picname);
1263 static int vid_wmodes;
1272 #define MAX_COLUMN_SIZE 9
1273 #define MODE_AREA_HEIGHT (MAX_COLUMN_SIZE + 2)
1274 #define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
1276 static modedesc_t modedescs[MAX_MODEDESCS];
1283 void VID_MenuDraw (void)
1287 int lnummodes, i, k, column, row;
1290 p = Draw_CachePic ("gfx/vidmodes.lmp");
1291 M_DrawPic ( (320-p->width)/2, 4, "gfx/vidmodes.lmp");
1294 lnummodes = VID_NumModes ();
1296 for (i=1 ; (i<lnummodes) && (vid_wmodes < MAX_MODEDESCS) ; i++)
1298 ptr = VID_GetModeDescription (i);
1299 pv = VID_GetModePtr (i);
1303 modedescs[k].modenum = i;
1304 modedescs[k].desc = ptr;
1305 modedescs[k].iscur = 0;
1307 if (i == vid_modenum)
1308 modedescs[k].iscur = 1;
1316 M_Print (2*8, 36+0*8, "Fullscreen Modes (WIDTHxHEIGHTxBPP)");
1321 for (i=0 ; i<vid_wmodes ; i++)
1323 if (modedescs[i].iscur)
1324 M_PrintWhite (column, row, modedescs[i].desc);
1326 M_Print (column, row, modedescs[i].desc);
1330 if ((i % VID_ROW_SIZE) == (VID_ROW_SIZE - 1))
1338 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*2, "Video modes must be set from the");
1339 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*3, "command line with -width <width>");
1340 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*4, "and -bpp <bits-per-pixel>");
1341 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*6, "Select windowed mode with -window");
1350 void VID_MenuKey (int key)
1355 S_LocalSound ("misc/menu1.wav");
1356 M_Menu_Options_f ();