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 const char *gl_vendor;
61 const char *gl_renderer;
62 const char *gl_version;
63 const char *gl_extensions;
65 qboolean scr_skipupdate;
67 static vmode_t modelist[MAX_MODE_LIST];
69 static vmode_t badmode;
71 static DEVMODE gdevmode;
72 static qboolean vid_initialized = false;
73 static qboolean windowed, leavecurrentmode;
74 static qboolean vid_canalttab = false;
75 static qboolean vid_wassuspended = false;
76 static int usingmouse;
77 extern qboolean mouseactive; // from in_win.c
80 int DIBWidth, DIBHeight;
82 DWORD WindowStyle, ExWindowStyle;
86 int vid_modenum = NO_MODE;
88 int vid_default = MODE_WINDOWED;
89 static int windowed_default;
90 unsigned char vid_curpal[256*3];
95 HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
97 viddef_t vid; // global video state
99 modestate_t modestate = MS_UNINIT;
101 void VID_MenuDraw (void);
102 void VID_MenuKey (int key);
104 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
105 void AppActivate(BOOL fActive, BOOL minimize);
106 char *VID_GetModeDescription (int mode);
107 void ClearAllStates (void);
108 void VID_UpdateWindowStatus (void);
110 //====================================
112 int window_center_x, window_center_y, window_x, window_y, window_width, window_height;
115 // direct draw software compatability stuff
117 void CenterWindow(HWND hWndCenter, int width, int height, BOOL lefttopjustify)
119 int CenterX, CenterY;
121 CenterX = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
122 CenterY = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
123 if (CenterX > CenterY*2)
124 CenterX >>= 1; // dual screens
125 CenterX = (CenterX < 0) ? 0: CenterX;
126 CenterY = (CenterY < 0) ? 0: CenterY;
127 SetWindowPos (hWndCenter, NULL, CenterX, CenterY, 0, 0,
128 SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
131 qboolean VID_SetWindowedMode (int modenum)
133 int lastmodestate, width, height;
136 lastmodestate = modestate;
138 WindowRect.top = WindowRect.left = 0;
140 WindowRect.right = modelist[modenum].width;
141 WindowRect.bottom = modelist[modenum].height;
143 DIBWidth = modelist[modenum].width;
144 DIBHeight = modelist[modenum].height;
146 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
150 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
152 width = rect.right - rect.left;
153 height = rect.bottom - rect.top;
155 // Create the DIB window
156 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
159 Sys_Error ("Couldn't create DIB window");
161 // Center and show the DIB window
162 CenterWindow(mainwindow, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, false);
164 ShowWindow (mainwindow, SW_SHOWDEFAULT);
165 UpdateWindow (mainwindow);
167 modestate = MS_WINDOWED;
169 if (vid.conheight > modelist[modenum].height)
170 vid.conheight = modelist[modenum].height;
171 if (vid.conwidth > modelist[modenum].width)
172 vid.conwidth = modelist[modenum].width;
174 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
175 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
181 qboolean VID_SetFullDIBMode (int modenum)
183 int lastmodestate, width, height;
186 if (!leavecurrentmode)
188 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
189 gdevmode.dmBitsPerPel = modelist[modenum].bpp;
190 gdevmode.dmPelsWidth = modelist[modenum].width <<
191 modelist[modenum].halfscreen;
192 gdevmode.dmPelsHeight = modelist[modenum].height;
193 gdevmode.dmSize = sizeof (gdevmode);
195 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
196 Sys_Error ("Couldn't set fullscreen DIB mode");
199 lastmodestate = modestate;
200 modestate = MS_FULLDIB;
202 WindowRect.top = WindowRect.left = 0;
204 WindowRect.right = modelist[modenum].width;
205 WindowRect.bottom = modelist[modenum].height;
207 DIBWidth = modelist[modenum].width;
208 DIBHeight = modelist[modenum].height;
210 WindowStyle = WS_POPUP;
214 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
216 width = rect.right - rect.left;
217 height = rect.bottom - rect.top;
219 // Create the DIB window
220 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
223 Sys_Error ("Couldn't create DIB window");
225 ShowWindow (mainwindow, SW_SHOWDEFAULT);
226 UpdateWindow (mainwindow);
228 if (vid.conheight > modelist[modenum].height)
229 vid.conheight = modelist[modenum].height;
230 if (vid.conwidth > modelist[modenum].width)
231 vid.conwidth = modelist[modenum].width;
233 // needed because we're not getting WM_MOVE messages fullscreen on NT
237 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
238 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
244 int VID_SetMode (int modenum)
250 if ((windowed && (modenum != 0)) || (!windowed && (modenum < 1)) || (!windowed && (modenum >= nummodes)))
251 Sys_Error ("Bad video mode\n");
255 if (vid_modenum == NO_MODE)
256 original_mode = windowed_default;
258 original_mode = vid_modenum;
260 // Set either the fullscreen or windowed mode
261 if (modelist[modenum].type == MS_WINDOWED)
262 stat = VID_SetWindowedMode(modenum);
263 else if (modelist[modenum].type == MS_FULLDIB)
264 stat = VID_SetFullDIBMode(modenum);
266 Sys_Error ("VID_SetMode: Bad mode type in modelist");
268 window_width = DIBWidth;
269 window_height = DIBHeight;
270 VID_UpdateWindowStatus ();
275 Sys_Error ("Couldn't set video mode");
277 // now we try to make sure we get the focus on the mode switch, because
278 // sometimes in some systems we don't. We grab the foreground, then
279 // finish setting up, pump all our messages, and sleep for a little while
280 // to let messages finish bouncing around the system, then we put
281 // ourselves at the top of the z order, then grab the foreground again,
282 // Who knows if it helps, but it probably doesn't hurt
283 SetForegroundWindow (mainwindow);
284 vid_modenum = modenum;
285 Cvar_SetValue ("vid_mode", (float)vid_modenum);
287 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
289 TranslateMessage (&msg);
290 DispatchMessage (&msg);
295 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
297 SetForegroundWindow (mainwindow);
299 // fix the leftover Alt from any Alt-Tab or the like that switched us away
303 Con_SafePrintf ("Video mode %s initialized.\n", VID_GetModeDescription (vid_modenum));
311 VID_UpdateWindowStatus
314 void VID_UpdateWindowStatus (void)
317 window_rect.left = window_x;
318 window_rect.top = window_y;
319 window_rect.right = window_x + window_width;
320 window_rect.bottom = window_y + window_height;
321 window_center_x = (window_rect.left + window_rect.right) / 2;
322 window_center_y = (window_rect.top + window_rect.bottom) / 2;
324 IN_UpdateClipCursor ();
328 //====================================
335 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
338 *width = WindowRect.right - WindowRect.left;
339 *height = WindowRect.bottom - WindowRect.top;
343 void VID_Finish (void)
346 if (r_render.integer && !scr_skipupdate)
352 // handle the mouse state when windowed if that's changed
354 if (vid_mouse.integer && key_dest == key_game)
356 if (modestate == MS_FULLDIB)
374 IN_DeactivateMouse ();
380 void VID_SetDefaultMode (void)
382 IN_DeactivateMouse ();
385 void VID_RestoreSystemGamma(void);
387 void VID_Shutdown (void)
396 vid_canalttab = false;
397 hRC = wglGetCurrentContext();
398 hDC = wglGetCurrentDC();
400 wglMakeCurrent(NULL, NULL);
402 // LordHavoc: free textures before closing (may help NVIDIA)
403 for (i = 0;i < 8192;i++)
405 qglDeleteTextures(8192, temp);
408 wglDeleteContext(hRC);
410 if (hDC && mainwindow)
411 ReleaseDC(mainwindow, hDC);
413 if (modestate == MS_FULLDIB)
414 ChangeDisplaySettings (NULL, 0);
416 if (maindc && mainwindow)
417 ReleaseDC (mainwindow, maindc);
419 AppActivate(false, false);
421 VID_RestoreSystemGamma();
426 //==========================================================================
429 BOOL bSetupPixelFormat(HDC hDC)
431 static PIXELFORMATDESCRIPTOR pfd = {
432 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
434 PFD_DRAW_TO_WINDOW // support window
435 | PFD_SUPPORT_OPENGL // support OpenGL
436 | PFD_DOUBLEBUFFER , // double buffered
437 PFD_TYPE_RGBA, // RGBA type
438 24, // 24-bit color depth
439 0, 0, 0, 0, 0, 0, // color bits ignored
440 0, // no alpha buffer
441 0, // shift bit ignored
442 0, // no accumulation buffer
443 0, 0, 0, 0, // accum bits ignored
444 32, // 32-bit z-buffer
445 0, // no stencil buffer
446 0, // no auxiliary buffer
447 PFD_MAIN_PLANE, // main layer
449 0, 0, 0 // layer masks ignored
453 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
455 MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
459 if (SetPixelFormat(hDC, pixelformat, &pfd) == false)
461 MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
470 qbyte scantokey[128] =
472 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
473 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
474 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
475 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
476 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
477 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
478 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
479 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
480 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
488 Map from windows to quake keynums
491 int MapKey (int key, int virtualkey)
496 if (scantokey[key] == 0)
497 Con_DPrintf("key 0x%02x has no translation\n", key);
498 return scantokey[key];
502 ===================================================================
506 ===================================================================
514 void ClearAllStates (void)
518 // send an up event for each key, to make sure the server clears them all
519 for (i=0 ; i<256 ; i++)
521 Key_Event (i, false);
528 void VID_RestoreGameGamma(void);
529 extern qboolean host_loopactive;
531 void AppActivate(BOOL fActive, BOOL minimize)
532 /****************************************************************************
534 * Function: AppActivate
535 * Parameters: fActive - True if app is activating
537 * Description: If the application is activating, then swap the system
538 * into SYSPAL_NOSTATIC mode so that our palettes will display
541 ****************************************************************************/
543 static BOOL sound_active;
546 Minimized = minimize;
548 // enable/disable sound on focus gain/loss
549 if (!ActiveApp && sound_active)
552 sound_active = false;
554 else if (ActiveApp && !sound_active)
562 if (modestate == MS_FULLDIB)
564 if (vid_canalttab && vid_wassuspended)
566 vid_wassuspended = false;
567 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
568 ShowWindow(mainwindow, SW_SHOWNORMAL);
571 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
572 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
575 VID_RestoreGameGamma();
581 IN_DeactivateMouse ();
583 if (modestate == MS_FULLDIB && vid_canalttab)
585 ChangeDisplaySettings (NULL, 0);
586 vid_wassuspended = true;
588 VID_RestoreSystemGamma();
592 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
594 /* main window procedure */
595 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
598 int fActive, fMinimized, temp;
599 extern unsigned int uiWheelMessage;
601 if ( uMsg == uiWheelMessage )
602 uMsg = WM_MOUSEWHEEL;
607 if (modestate == MS_FULLDIB)
608 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
615 window_x = (int) LOWORD(lParam);
616 window_y = (int) HIWORD(lParam);
617 VID_UpdateWindowStatus ();
622 Key_Event (MapKey(lParam, wParam), true);
627 Key_Event (MapKey(lParam, wParam), false);
631 // keep Alt-Space from happening
634 // this is complicated because Win32 seems to pack multiple mouse events into
635 // one update sometimes, so we always check all states and look for events
645 if (wParam & MK_LBUTTON)
648 if (wParam & MK_RBUTTON)
651 if (wParam & MK_MBUTTON)
654 IN_MouseEvent (temp);
658 // JACK: This is the mouse wheel with the Intellimouse
659 // Its delta is either positive or neg, and we generate the proper
662 if ((short) HIWORD(wParam) > 0) {
663 Key_Event(K_MWHEELUP, true);
664 Key_Event(K_MWHEELUP, false);
666 Key_Event(K_MWHEELDOWN, true);
667 Key_Event(K_MWHEELDOWN, false);
675 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
681 fActive = LOWORD(wParam);
682 fMinimized = (BOOL) HIWORD(wParam);
683 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
685 // fix the leftover Alt from any Alt-Tab or the like that switched us away
693 DestroyWindow (mainwindow);
700 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
704 /* pass all unhandled messages to DefWindowProc */
705 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
709 /* return 1 if handled message, 0 if not */
719 int VID_NumModes (void)
730 vmode_t *VID_GetModePtr (int modenum)
733 if ((modenum >= 0) && (modenum < nummodes))
734 return &modelist[modenum];
742 VID_GetModeDescription
745 char *VID_GetModeDescription (int mode)
749 static char temp[100];
751 if ((mode < 0) || (mode >= nummodes))
754 if (!leavecurrentmode)
756 pv = VID_GetModePtr (mode);
757 pinfo = pv->modedesc;
761 sprintf (temp, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
769 // KJB: Added this to return the mode driver name in description for console
771 char *VID_GetExtModeDescription (int mode)
773 static char pinfo[40];
776 if ((mode < 0) || (mode >= nummodes))
779 pv = VID_GetModePtr (mode);
780 if (modelist[mode].type == MS_FULLDIB)
782 if (!leavecurrentmode)
783 sprintf(pinfo,"%s fullscreen", pv->modedesc);
785 sprintf (pinfo, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
789 if (modestate == MS_WINDOWED)
790 sprintf(pinfo, "%s windowed", pv->modedesc);
792 sprintf(pinfo, "windowed");
801 VID_DescribeCurrentMode_f
804 void VID_DescribeCurrentMode_f (void)
806 Con_Printf ("%s\n", VID_GetExtModeDescription (vid_modenum));
815 void VID_NumModes_f (void)
818 Con_Printf ("%d video mode is available\n", nummodes);
820 Con_Printf ("%d video modes are available\n", nummodes);
829 void VID_DescribeMode_f (void)
833 modenum = atoi (Cmd_Argv(1));
835 t = leavecurrentmode;
836 leavecurrentmode = 0;
838 Con_Printf ("%s\n", VID_GetExtModeDescription (modenum));
840 leavecurrentmode = t;
849 void VID_DescribeModes_f (void)
855 lnummodes = VID_NumModes ();
857 t = leavecurrentmode;
858 leavecurrentmode = 0;
860 for (i=1 ; i<lnummodes ; i++)
862 pv = VID_GetModePtr (i);
863 pinfo = VID_GetExtModeDescription (i);
864 Con_Printf ("%2d: %s\n", i, pinfo);
867 leavecurrentmode = t;
870 void VID_AddMode(int type, int width, int height, int modenum, int halfscreen, int dib, int fullscreen, int bpp)
873 if (nummodes >= MAX_MODE_LIST)
875 modelist[nummodes].type = type;
876 modelist[nummodes].width = width;
877 modelist[nummodes].height = height;
878 modelist[nummodes].modenum = modenum;
879 modelist[nummodes].halfscreen = halfscreen;
880 modelist[nummodes].dib = dib;
881 modelist[nummodes].fullscreen = fullscreen;
882 modelist[nummodes].bpp = bpp;
884 sprintf (modelist[nummodes].modedesc, "%dx%d", width, height);
886 sprintf (modelist[nummodes].modedesc, "%dx%dx%d", width, height, bpp);
887 for (i = 0;i < nummodes;i++)
889 if (!memcmp(&modelist[i], &modelist[nummodes], sizeof(vmode_t)))
895 void VID_InitDIB (HINSTANCE hInstance)
900 // Register the frame class
902 wc.lpfnWndProc = (WNDPROC)MainWndProc;
905 wc.hInstance = hInstance;
907 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
908 wc.hbrBackground = NULL;
910 wc.lpszClassName = gamename;
912 if (!RegisterClass (&wc) )
913 Sys_Error ("Couldn't register window class");
915 if (COM_CheckParm("-width"))
916 w = atoi(com_argv[COM_CheckParm("-width")+1]);
923 if (COM_CheckParm("-height"))
924 h = atoi(com_argv[COM_CheckParm("-height")+1]);
931 VID_AddMode(MS_WINDOWED, w, h, 0, 0, 1, 0, 0);
940 void VID_InitFullDIB (HINSTANCE hInstance)
944 int originalnummodes;
951 // enumerate >8 bpp modes
952 originalnummodes = nummodes;
957 stat = EnumDisplaySettings (NULL, modenum, &devmode);
959 if ((devmode.dmBitsPerPel >= 15) && (devmode.dmPelsWidth <= MAXWIDTH) && (devmode.dmPelsHeight <= MAXHEIGHT) && (nummodes < MAX_MODE_LIST))
961 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
963 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
965 // if the width is more than twice the height, reduce it by half because this
966 // is probably a dual-screen monitor
967 if ((!COM_CheckParm("-noadjustaspect")) && (devmode.dmPelsWidth > (devmode.dmPelsHeight << 1)))
968 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth >> 1, devmode.dmPelsHeight, 0, 1, 1, 1, devmode.dmBitsPerPel);
970 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
978 // see if there are any low-res modes that aren't being reported
979 numlowresmodes = sizeof(lowresmodes) / sizeof(lowresmodes[0]);
985 for (j=0 ; (j<numlowresmodes) && (nummodes < MAX_MODE_LIST) ; j++)
987 devmode.dmBitsPerPel = bpp;
988 devmode.dmPelsWidth = lowresmodes[j].width;
989 devmode.dmPelsHeight = lowresmodes[j].height;
990 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
992 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
993 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
1012 if (nummodes == originalnummodes)
1013 Con_SafePrintf ("No fullscreen DIB modes found\n");
1016 //static int grabsysgamma = true;
1017 WORD systemgammaramps[3][256], currentgammaramps[3][256];
1019 int VID_SetGamma(float prescale, float gamma, float scale, float base)
1025 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
1026 for (i = 0;i < 256;i++)
1027 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
1029 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
1031 ReleaseDC (NULL, hdc);
1032 return i; // return success or failure
1035 void VID_RestoreGameGamma(void)
1037 VID_UpdateGamma(true);
1040 void VID_GetSystemGamma(void)
1045 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1047 ReleaseDC (NULL, hdc);
1050 void VID_RestoreSystemGamma(void)
1055 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1057 ReleaseDC (NULL, hdc);
1065 void VID_Init (void)
1068 int basenummodes, width, height = 0, bpp, findbpp, done;
1072 memset(&devmode, 0, sizeof(devmode));
1074 Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
1075 Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
1076 Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
1077 Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);
1079 VID_GetSystemGamma();
1081 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
1083 InitCommonControls();
1085 VID_InitDIB (global_hInstance);
1086 basenummodes = nummodes = 1;
1088 VID_InitFullDIB (global_hInstance);
1090 if (COM_CheckParm("-window"))
1094 if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
1095 Sys_Error ("Can't run in non-RGB mode");
1097 ReleaseDC (NULL, hdc);
1101 vid_default = MODE_WINDOWED;
1106 Sys_Error ("No RGB fullscreen modes available");
1110 if (COM_CheckParm("-mode"))
1111 vid_default = atoi(com_argv[COM_CheckParm("-mode")+1]);
1114 if (COM_CheckParm("-current"))
1116 modelist[MODE_FULLSCREEN_DEFAULT].width = GetSystemMetrics (SM_CXSCREEN);
1117 modelist[MODE_FULLSCREEN_DEFAULT].height = GetSystemMetrics (SM_CYSCREEN);
1118 vid_default = MODE_FULLSCREEN_DEFAULT;
1119 leavecurrentmode = 1;
1123 if (COM_CheckParm("-width"))
1124 width = atoi(com_argv[COM_CheckParm("-width")+1]);
1128 if (COM_CheckParm("-bpp"))
1130 bpp = atoi(com_argv[COM_CheckParm("-bpp")+1]);
1139 if (COM_CheckParm("-height"))
1140 height = atoi(com_argv[COM_CheckParm("-height")+1]);
1142 // if they want to force it, add the specified mode to the list
1143 if (COM_CheckParm("-force") && (nummodes < MAX_MODE_LIST))
1144 VID_AddMode(MS_FULLDIB, width, height, 0, 0, 1, 1, bpp);
1150 if (COM_CheckParm("-height"))
1152 height = atoi(com_argv[COM_CheckParm("-height")+1]);
1154 for (i=1, vid_default=0 ; i<nummodes ; i++)
1156 if ((modelist[i].width == width) && (modelist[i].height == height) && (modelist[i].bpp == bpp))
1166 for (i=1, vid_default=0 ; i<nummodes ; i++)
1168 if ((modelist[i].width == width) && (modelist[i].bpp == bpp))
1183 case 15: bpp = 16;break;
1184 case 16: bpp = 32;break;
1185 case 32: bpp = 24;break;
1186 case 24: done = 1;break;
1196 Sys_Error ("Specified video mode not available");
1201 vid_initialized = true;
1203 if ((i = COM_CheckParm("-conwidth")) != 0)
1204 vid.conwidth = atoi(com_argv[i+1]);
1208 vid.conwidth &= 0xfff8; // make it a multiple of eight
1210 if (vid.conwidth < 320)
1213 // pick a conheight that matches with correct aspect
1214 vid.conheight = vid.conwidth*3 / 4;
1216 if ((i = COM_CheckParm("-conheight")) != 0)
1217 vid.conheight = atoi(com_argv[i+1]);
1218 if (vid.conheight < 200)
1219 vid.conheight = 200;
1221 VID_SetMode (vid_default);
1223 maindc = GetDC(mainwindow);
1224 bSetupPixelFormat(maindc);
1226 baseRC = wglCreateContext( maindc );
1228 Sys_Error ("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.");
1229 if (!wglMakeCurrent( maindc, baseRC ))
1230 Sys_Error ("wglMakeCurrent failed");
1234 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
1235 if (strncasecmp(gl_vendor,"ATI",3)==0)
1237 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
1240 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
1243 vid_realmode = vid_modenum;
1245 vid_menudrawfn = VID_MenuDraw;
1246 vid_menukeyfn = VID_MenuKey;
1248 strcpy (badmode.modedesc, "Bad mode");
1249 vid_canalttab = true;
1253 //========================================================
1255 //========================================================
1257 extern void M_Menu_Options_f (void);
1258 extern void M_Print (int cx, int cy, char *str);
1259 extern void M_PrintWhite (int cx, int cy, char *str);
1260 extern void M_DrawCharacter (int cx, int line, int num);
1261 extern void M_DrawPic (int x, int y, 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 ();