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 // close the library before we get rid of the window
407 if (hDC && mainwindow)
408 ReleaseDC(mainwindow, hDC);
410 if (modestate == MS_FULLDIB)
411 ChangeDisplaySettings (NULL, 0);
413 if (maindc && mainwindow)
414 ReleaseDC (mainwindow, maindc);
416 AppActivate(false, false);
418 VID_RestoreSystemGamma();
423 //==========================================================================
426 BOOL bSetupPixelFormat(HDC hDC)
428 static PIXELFORMATDESCRIPTOR pfd = {
429 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
431 PFD_DRAW_TO_WINDOW // support window
432 | PFD_SUPPORT_OPENGL // support OpenGL
433 | PFD_DOUBLEBUFFER , // double buffered
434 PFD_TYPE_RGBA, // RGBA type
435 24, // 24-bit color depth
436 0, 0, 0, 0, 0, 0, // color bits ignored
437 0, // no alpha buffer
438 0, // shift bit ignored
439 0, // no accumulation buffer
440 0, 0, 0, 0, // accum bits ignored
441 32, // 32-bit z-buffer
442 0, // no stencil buffer
443 0, // no auxiliary buffer
444 PFD_MAIN_PLANE, // main layer
446 0, 0, 0 // layer masks ignored
450 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
452 MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
456 if (SetPixelFormat(hDC, pixelformat, &pfd) == false)
458 MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
467 qbyte scantokey[128] =
469 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
470 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
471 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
472 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
473 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
474 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
475 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
476 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
477 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
485 Map from windows to quake keynums
488 int MapKey (int key, int virtualkey)
493 if (scantokey[key] == 0)
494 Con_DPrintf("key 0x%02x has no translation\n", key);
495 return scantokey[key];
499 ===================================================================
503 ===================================================================
511 void ClearAllStates (void)
515 // send an up event for each key, to make sure the server clears them all
516 for (i=0 ; i<256 ; i++)
518 Key_Event (i, false);
525 void VID_RestoreGameGamma(void);
526 extern qboolean host_loopactive;
528 void AppActivate(BOOL fActive, BOOL minimize)
529 /****************************************************************************
531 * Function: AppActivate
532 * Parameters: fActive - True if app is activating
534 * Description: If the application is activating, then swap the system
535 * into SYSPAL_NOSTATIC mode so that our palettes will display
538 ****************************************************************************/
540 static BOOL sound_active;
542 vid_activewindow = fActive;
543 vid_hidden = minimize;
545 // enable/disable sound on focus gain/loss
546 if (!vid_activewindow && sound_active)
549 sound_active = false;
551 else if (vid_activewindow && !sound_active)
559 if (modestate == MS_FULLDIB)
561 if (vid_canalttab && vid_wassuspended)
563 vid_wassuspended = false;
564 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
565 ShowWindow(mainwindow, SW_SHOWNORMAL);
568 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
569 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
572 VID_RestoreGameGamma();
577 vid_usingmouse = false;
578 IN_DeactivateMouse ();
580 if (modestate == MS_FULLDIB && vid_canalttab)
582 ChangeDisplaySettings (NULL, 0);
583 vid_wassuspended = true;
585 VID_RestoreSystemGamma();
589 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
591 /* main window procedure */
592 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
595 int fActive, fMinimized, temp;
596 extern unsigned int uiWheelMessage;
598 if ( uMsg == uiWheelMessage )
599 uMsg = WM_MOUSEWHEEL;
604 if (modestate == MS_FULLDIB)
605 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
612 window_x = (int) LOWORD(lParam);
613 window_y = (int) HIWORD(lParam);
614 VID_UpdateWindowStatus ();
619 Key_Event (MapKey(lParam, wParam), true);
624 Key_Event (MapKey(lParam, wParam), false);
628 // keep Alt-Space from happening
631 // this is complicated because Win32 seems to pack multiple mouse events into
632 // one update sometimes, so we always check all states and look for events
642 if (wParam & MK_LBUTTON)
645 if (wParam & MK_RBUTTON)
648 if (wParam & MK_MBUTTON)
651 IN_MouseEvent (temp);
655 // JACK: This is the mouse wheel with the Intellimouse
656 // Its delta is either positive or neg, and we generate the proper
659 if ((short) HIWORD(wParam) > 0) {
660 Key_Event(K_MWHEELUP, true);
661 Key_Event(K_MWHEELUP, false);
663 Key_Event(K_MWHEELDOWN, true);
664 Key_Event(K_MWHEELDOWN, false);
672 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
678 fActive = LOWORD(wParam);
679 fMinimized = (BOOL) HIWORD(wParam);
680 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
682 // fix the leftover Alt from any Alt-Tab or the like that switched us away
690 DestroyWindow (mainwindow);
697 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
701 /* pass all unhandled messages to DefWindowProc */
702 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
706 /* return 1 if handled message, 0 if not */
716 int VID_NumModes (void)
727 vmode_t *VID_GetModePtr (int modenum)
730 if ((modenum >= 0) && (modenum < nummodes))
731 return &modelist[modenum];
739 VID_GetModeDescription
742 char *VID_GetModeDescription (int mode)
746 static char temp[100];
748 if ((mode < 0) || (mode >= nummodes))
751 if (!leavecurrentmode)
753 pv = VID_GetModePtr (mode);
754 pinfo = pv->modedesc;
758 sprintf (temp, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
766 // KJB: Added this to return the mode driver name in description for console
768 char *VID_GetExtModeDescription (int mode)
770 static char pinfo[40];
773 if ((mode < 0) || (mode >= nummodes))
776 pv = VID_GetModePtr (mode);
777 if (modelist[mode].type == MS_FULLDIB)
779 if (!leavecurrentmode)
780 sprintf(pinfo,"%s fullscreen", pv->modedesc);
782 sprintf (pinfo, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
786 if (modestate == MS_WINDOWED)
787 sprintf(pinfo, "%s windowed", pv->modedesc);
789 sprintf(pinfo, "windowed");
798 VID_DescribeCurrentMode_f
801 void VID_DescribeCurrentMode_f (void)
803 Con_Printf ("%s\n", VID_GetExtModeDescription (vid_modenum));
812 void VID_NumModes_f (void)
815 Con_Printf ("%d video mode is available\n", nummodes);
817 Con_Printf ("%d video modes are available\n", nummodes);
826 void VID_DescribeMode_f (void)
830 modenum = atoi (Cmd_Argv(1));
832 t = leavecurrentmode;
833 leavecurrentmode = 0;
835 Con_Printf ("%s\n", VID_GetExtModeDescription (modenum));
837 leavecurrentmode = t;
846 void VID_DescribeModes_f (void)
852 lnummodes = VID_NumModes ();
854 t = leavecurrentmode;
855 leavecurrentmode = 0;
857 for (i=1 ; i<lnummodes ; i++)
859 pv = VID_GetModePtr (i);
860 pinfo = VID_GetExtModeDescription (i);
861 Con_Printf ("%2d: %s\n", i, pinfo);
864 leavecurrentmode = t;
867 void VID_AddMode(int type, int width, int height, int modenum, int halfscreen, int dib, int fullscreen, int bpp)
870 if (nummodes >= MAX_MODE_LIST)
872 modelist[nummodes].type = type;
873 modelist[nummodes].width = width;
874 modelist[nummodes].height = height;
875 modelist[nummodes].modenum = modenum;
876 modelist[nummodes].halfscreen = halfscreen;
877 modelist[nummodes].dib = dib;
878 modelist[nummodes].fullscreen = fullscreen;
879 modelist[nummodes].bpp = bpp;
881 sprintf (modelist[nummodes].modedesc, "%dx%d", width, height);
883 sprintf (modelist[nummodes].modedesc, "%dx%dx%d", width, height, bpp);
884 for (i = 0;i < nummodes;i++)
886 if (!memcmp(&modelist[i], &modelist[nummodes], sizeof(vmode_t)))
892 void VID_InitDIB (HINSTANCE hInstance)
897 // Register the frame class
899 wc.lpfnWndProc = (WNDPROC)MainWndProc;
902 wc.hInstance = hInstance;
904 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
905 wc.hbrBackground = NULL;
907 wc.lpszClassName = gamename;
909 if (!RegisterClass (&wc) )
910 Sys_Error ("Couldn't register window class");
912 if (COM_CheckParm("-width"))
913 w = atoi(com_argv[COM_CheckParm("-width")+1]);
920 if (COM_CheckParm("-height"))
921 h = atoi(com_argv[COM_CheckParm("-height")+1]);
928 VID_AddMode(MS_WINDOWED, w, h, 0, 0, 1, 0, 0);
937 void VID_InitFullDIB (HINSTANCE hInstance)
941 int originalnummodes;
948 // enumerate >8 bpp modes
949 originalnummodes = nummodes;
954 stat = EnumDisplaySettings (NULL, modenum, &devmode);
956 if ((devmode.dmBitsPerPel >= 15) && (devmode.dmPelsWidth <= MAXWIDTH) && (devmode.dmPelsHeight <= MAXHEIGHT) && (nummodes < MAX_MODE_LIST))
958 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
960 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
962 // if the width is more than twice the height, reduce it by half because this
963 // is probably a dual-screen monitor
964 if ((!COM_CheckParm("-noadjustaspect")) && (devmode.dmPelsWidth > (devmode.dmPelsHeight << 1)))
965 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth >> 1, devmode.dmPelsHeight, 0, 1, 1, 1, devmode.dmBitsPerPel);
967 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
975 // see if there are any low-res modes that aren't being reported
976 numlowresmodes = sizeof(lowresmodes) / sizeof(lowresmodes[0]);
982 for (j=0 ; (j<numlowresmodes) && (nummodes < MAX_MODE_LIST) ; j++)
984 devmode.dmBitsPerPel = bpp;
985 devmode.dmPelsWidth = lowresmodes[j].width;
986 devmode.dmPelsHeight = lowresmodes[j].height;
987 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
989 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
990 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
1009 if (nummodes == originalnummodes)
1010 Con_SafePrintf ("No fullscreen DIB modes found\n");
1013 //static int grabsysgamma = true;
1014 WORD systemgammaramps[3][256], currentgammaramps[3][256];
1016 int VID_SetGamma(float prescale, float gamma, float scale, float base)
1022 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
1023 for (i = 0;i < 256;i++)
1024 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
1026 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
1028 ReleaseDC (NULL, hdc);
1029 return i; // return success or failure
1032 void VID_RestoreGameGamma(void)
1034 VID_UpdateGamma(true);
1037 void VID_GetSystemGamma(void)
1042 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1044 ReleaseDC (NULL, hdc);
1047 void VID_RestoreSystemGamma(void)
1052 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1054 ReleaseDC (NULL, hdc);
1062 void VID_Init (void)
1065 int basenummodes, width, height = 0, bpp, findbpp, done;
1071 memset(&devmode, 0, sizeof(devmode));
1073 Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
1074 Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
1075 Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
1076 Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);
1078 VID_GetSystemGamma();
1080 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
1082 InitCommonControls();
1084 VID_InitDIB (global_hInstance);
1085 basenummodes = nummodes = 1;
1087 VID_InitFullDIB (global_hInstance);
1089 if (COM_CheckParm("-window"))
1093 if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
1094 Sys_Error ("Can't run in non-RGB mode");
1096 ReleaseDC (NULL, hdc);
1100 vid_default = MODE_WINDOWED;
1105 Sys_Error ("No RGB fullscreen modes available");
1109 if (COM_CheckParm("-mode"))
1110 vid_default = atoi(com_argv[COM_CheckParm("-mode")+1]);
1113 if (COM_CheckParm("-current"))
1115 modelist[MODE_FULLSCREEN_DEFAULT].width = GetSystemMetrics (SM_CXSCREEN);
1116 modelist[MODE_FULLSCREEN_DEFAULT].height = GetSystemMetrics (SM_CYSCREEN);
1117 vid_default = MODE_FULLSCREEN_DEFAULT;
1118 leavecurrentmode = 1;
1122 if (COM_CheckParm("-width"))
1123 width = atoi(com_argv[COM_CheckParm("-width")+1]);
1127 if (COM_CheckParm("-bpp"))
1129 bpp = atoi(com_argv[COM_CheckParm("-bpp")+1]);
1138 if (COM_CheckParm("-height"))
1139 height = atoi(com_argv[COM_CheckParm("-height")+1]);
1141 // if they want to force it, add the specified mode to the list
1142 if (COM_CheckParm("-force") && (nummodes < MAX_MODE_LIST))
1143 VID_AddMode(MS_FULLDIB, width, height, 0, 0, 1, 1, bpp);
1149 if (COM_CheckParm("-height"))
1151 height = atoi(com_argv[COM_CheckParm("-height")+1]);
1153 for (i=1, vid_default=0 ; i<nummodes ; i++)
1155 if ((modelist[i].width == width) && (modelist[i].height == height) && (modelist[i].bpp == bpp))
1165 for (i=1, vid_default=0 ; i<nummodes ; i++)
1167 if ((modelist[i].width == width) && (modelist[i].bpp == bpp))
1182 case 15: bpp = 16;break;
1183 case 16: bpp = 32;break;
1184 case 32: bpp = 24;break;
1185 case 24: done = 1;break;
1195 Sys_Error ("Specified video mode not available");
1200 vid_initialized = true;
1202 if ((i = COM_CheckParm("-conwidth")) != 0)
1203 vid.conwidth = atoi(com_argv[i+1]);
1207 vid.conwidth &= 0xfff8; // make it a multiple of eight
1209 if (vid.conwidth < 320)
1212 // pick a conheight that matches with correct aspect
1213 vid.conheight = vid.conwidth*3 / 4;
1215 if ((i = COM_CheckParm("-conheight")) != 0)
1216 vid.conheight = atoi(com_argv[i+1]);
1217 if (vid.conheight < 200)
1218 vid.conheight = 200;
1220 VID_SetMode (vid_default);
1222 maindc = GetDC(mainwindow);
1223 bSetupPixelFormat(maindc);
1225 baseRC = wglCreateContext( maindc );
1227 Sys_Error ("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.");
1228 if (!wglMakeCurrent( maindc, baseRC ))
1229 Sys_Error ("wglMakeCurrent failed");
1233 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
1234 if (strncasecmp(gl_vendor,"ATI",3)==0)
1236 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
1239 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
1242 vid_realmode = vid_modenum;
1244 vid_menudrawfn = VID_MenuDraw;
1245 vid_menukeyfn = VID_MenuKey;
1247 strcpy (badmode.modedesc, "Bad mode");
1248 vid_canalttab = true;
1254 //========================================================
1256 //========================================================
1258 extern void M_Menu_Options_f (void);
1259 extern void M_Print (float cx, float cy, char *str);
1260 extern void M_PrintWhite (float cx, float cy, char *str);
1261 extern void M_DrawCharacter (float cx, float cy, int num);
1262 extern void M_DrawPic (float cx, float cy, char *picname);
1264 static int vid_wmodes;
1273 #define MAX_COLUMN_SIZE 9
1274 #define MODE_AREA_HEIGHT (MAX_COLUMN_SIZE + 2)
1275 #define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
1277 static modedesc_t modedescs[MAX_MODEDESCS];
1284 void VID_MenuDraw (void)
1288 int lnummodes, i, k, column, row;
1291 p = Draw_CachePic ("gfx/vidmodes.lmp");
1292 M_DrawPic ( (320-p->width)/2, 4, "gfx/vidmodes.lmp");
1295 lnummodes = VID_NumModes ();
1297 for (i=1 ; (i<lnummodes) && (vid_wmodes < MAX_MODEDESCS) ; i++)
1299 ptr = VID_GetModeDescription (i);
1300 pv = VID_GetModePtr (i);
1304 modedescs[k].modenum = i;
1305 modedescs[k].desc = ptr;
1306 modedescs[k].iscur = 0;
1308 if (i == vid_modenum)
1309 modedescs[k].iscur = 1;
1317 M_Print (2*8, 36+0*8, "Fullscreen Modes (WIDTHxHEIGHTxBPP)");
1322 for (i=0 ; i<vid_wmodes ; i++)
1324 if (modedescs[i].iscur)
1325 M_PrintWhite (column, row, modedescs[i].desc);
1327 M_Print (column, row, modedescs[i].desc);
1331 if ((i % VID_ROW_SIZE) == (VID_ROW_SIZE - 1))
1339 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*2, "Video modes must be set from the");
1340 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*3, "command line with -width <width>");
1341 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*4, "and -bpp <bits-per-pixel>");
1342 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*6, "Select windowed mode with -window");
1351 void VID_MenuKey (int key)
1356 S_LocalSound ("misc/menu1.wav");
1357 M_Menu_Options_f ();