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 vid_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);
100 modestate_t modestate = MS_UNINIT;
102 void VID_MenuDraw (void);
103 void VID_MenuKey (int key);
105 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
106 void AppActivate(BOOL fActive, BOOL minimize);
107 char *VID_GetModeDescription (int mode);
108 void ClearAllStates (void);
109 void VID_UpdateWindowStatus (void);
111 //====================================
113 int window_center_x, window_center_y, window_x, window_y, window_width, window_height;
116 // direct draw software compatability stuff
118 void CenterWindow(HWND hWndCenter, int width, int height, BOOL lefttopjustify)
120 int CenterX, CenterY;
122 CenterX = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
123 CenterY = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
124 if (CenterX > CenterY*2)
125 CenterX >>= 1; // dual screens
126 CenterX = (CenterX < 0) ? 0: CenterX;
127 CenterY = (CenterY < 0) ? 0: CenterY;
128 SetWindowPos (hWndCenter, NULL, CenterX, CenterY, 0, 0,
129 SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
132 qboolean VID_SetWindowedMode (int modenum)
134 int lastmodestate, width, height;
137 lastmodestate = modestate;
139 WindowRect.top = WindowRect.left = 0;
141 WindowRect.right = modelist[modenum].width;
142 WindowRect.bottom = modelist[modenum].height;
144 DIBWidth = modelist[modenum].width;
145 DIBHeight = modelist[modenum].height;
147 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
151 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
153 width = rect.right - rect.left;
154 height = rect.bottom - rect.top;
156 // Create the DIB window
157 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
160 Sys_Error ("Couldn't create DIB window");
162 // Center and show the DIB window
163 CenterWindow(mainwindow, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, false);
165 ShowWindow (mainwindow, SW_SHOWDEFAULT);
166 UpdateWindow (mainwindow);
168 modestate = MS_WINDOWED;
170 if (vid.conheight > modelist[modenum].height)
171 vid.conheight = modelist[modenum].height;
172 if (vid.conwidth > modelist[modenum].width)
173 vid.conwidth = modelist[modenum].width;
175 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
176 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
182 qboolean VID_SetFullDIBMode (int modenum)
184 int lastmodestate, width, height;
187 if (!leavecurrentmode)
189 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
190 gdevmode.dmBitsPerPel = modelist[modenum].bpp;
191 gdevmode.dmPelsWidth = modelist[modenum].width << 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)
316 window_rect.left = window_x;
317 window_rect.top = window_y;
318 window_rect.right = window_x + window_width;
319 window_rect.bottom = window_y + window_height;
320 window_center_x = (window_rect.left + window_rect.right) / 2;
321 window_center_y = (window_rect.top + window_rect.bottom) / 2;
323 IN_UpdateClipCursor ();
327 //====================================
334 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
337 *width = WindowRect.right - WindowRect.left;
338 *height = WindowRect.bottom - WindowRect.top;
342 void VID_Finish (void)
345 if (r_render.integer && !scr_skipupdate)
351 // handle the mouse state when windowed if that's changed
352 vid_usemouse = false;
353 if (vid_mouse.integer && key_dest == key_game)
355 if (modestate == MS_FULLDIB)
357 if (!vid_activewindow)
358 vid_usemouse = false;
363 vid_usingmouse = true;
372 vid_usingmouse = false;
373 IN_DeactivateMouse ();
379 void VID_SetDefaultMode (void)
381 IN_DeactivateMouse ();
384 void VID_RestoreSystemGamma(void);
386 void VID_Shutdown (void)
395 vid_canalttab = false;
396 hRC = wglGetCurrentContext();
397 hDC = wglGetCurrentDC();
399 wglMakeCurrent(NULL, NULL);
401 // LordHavoc: free textures before closing (may help NVIDIA)
402 for (i = 0;i < 8192;i++)
404 qglDeleteTextures(8192, temp);
407 wglDeleteContext(hRC);
409 if (hDC && mainwindow)
410 ReleaseDC(mainwindow, hDC);
412 if (modestate == MS_FULLDIB)
413 ChangeDisplaySettings (NULL, 0);
415 if (maindc && mainwindow)
416 ReleaseDC (mainwindow, maindc);
418 AppActivate(false, false);
420 VID_RestoreSystemGamma();
425 //==========================================================================
428 BOOL bSetupPixelFormat(HDC hDC)
430 static PIXELFORMATDESCRIPTOR pfd = {
431 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
433 PFD_DRAW_TO_WINDOW // support window
434 | PFD_SUPPORT_OPENGL // support OpenGL
435 | PFD_DOUBLEBUFFER , // double buffered
436 PFD_TYPE_RGBA, // RGBA type
437 24, // 24-bit color depth
438 0, 0, 0, 0, 0, 0, // color bits ignored
439 0, // no alpha buffer
440 0, // shift bit ignored
441 0, // no accumulation buffer
442 0, 0, 0, 0, // accum bits ignored
443 32, // 32-bit z-buffer
444 0, // no stencil buffer
445 0, // no auxiliary buffer
446 PFD_MAIN_PLANE, // main layer
448 0, 0, 0 // layer masks ignored
452 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
454 MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
458 if (SetPixelFormat(hDC, pixelformat, &pfd) == false)
460 MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
469 qbyte scantokey[128] =
471 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
472 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
473 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
474 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
475 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
476 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
477 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
478 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
479 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
487 Map from windows to quake keynums
490 int MapKey (int key, int virtualkey)
495 if (scantokey[key] == 0)
496 Con_DPrintf("key 0x%02x has no translation\n", key);
497 return scantokey[key];
501 ===================================================================
505 ===================================================================
513 void ClearAllStates (void)
517 // send an up event for each key, to make sure the server clears them all
518 for (i=0 ; i<256 ; i++)
520 Key_Event (i, false);
527 void VID_RestoreGameGamma(void);
528 extern qboolean host_loopactive;
530 void AppActivate(BOOL fActive, BOOL minimize)
531 /****************************************************************************
533 * Function: AppActivate
534 * Parameters: fActive - True if app is activating
536 * Description: If the application is activating, then swap the system
537 * into SYSPAL_NOSTATIC mode so that our palettes will display
540 ****************************************************************************/
542 static BOOL sound_active;
544 vid_activewindow = fActive;
545 Minimized = minimize;
547 // enable/disable sound on focus gain/loss
548 if (!vid_activewindow && sound_active)
551 sound_active = false;
553 else if (vid_activewindow && !sound_active)
561 if (modestate == MS_FULLDIB)
563 if (vid_canalttab && vid_wassuspended)
565 vid_wassuspended = false;
566 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
567 ShowWindow(mainwindow, SW_SHOWNORMAL);
570 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
571 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
574 VID_RestoreGameGamma();
579 vid_usingmouse = false;
580 IN_DeactivateMouse ();
582 if (modestate == MS_FULLDIB && vid_canalttab)
584 ChangeDisplaySettings (NULL, 0);
585 vid_wassuspended = true;
587 VID_RestoreSystemGamma();
591 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
593 /* main window procedure */
594 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
597 int fActive, fMinimized, temp;
598 extern unsigned int uiWheelMessage;
600 if ( uMsg == uiWheelMessage )
601 uMsg = WM_MOUSEWHEEL;
606 if (modestate == MS_FULLDIB)
607 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
614 window_x = (int) LOWORD(lParam);
615 window_y = (int) HIWORD(lParam);
616 VID_UpdateWindowStatus ();
621 Key_Event (MapKey(lParam, wParam), true);
626 Key_Event (MapKey(lParam, wParam), false);
630 // keep Alt-Space from happening
633 // this is complicated because Win32 seems to pack multiple mouse events into
634 // one update sometimes, so we always check all states and look for events
644 if (wParam & MK_LBUTTON)
647 if (wParam & MK_RBUTTON)
650 if (wParam & MK_MBUTTON)
653 IN_MouseEvent (temp);
657 // JACK: This is the mouse wheel with the Intellimouse
658 // Its delta is either positive or neg, and we generate the proper
661 if ((short) HIWORD(wParam) > 0) {
662 Key_Event(K_MWHEELUP, true);
663 Key_Event(K_MWHEELUP, false);
665 Key_Event(K_MWHEELDOWN, true);
666 Key_Event(K_MWHEELDOWN, false);
674 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
680 fActive = LOWORD(wParam);
681 fMinimized = (BOOL) HIWORD(wParam);
682 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
684 // fix the leftover Alt from any Alt-Tab or the like that switched us away
692 DestroyWindow (mainwindow);
699 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
703 /* pass all unhandled messages to DefWindowProc */
704 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
708 /* return 1 if handled message, 0 if not */
718 int VID_NumModes (void)
729 vmode_t *VID_GetModePtr (int modenum)
732 if ((modenum >= 0) && (modenum < nummodes))
733 return &modelist[modenum];
741 VID_GetModeDescription
744 char *VID_GetModeDescription (int mode)
748 static char temp[100];
750 if ((mode < 0) || (mode >= nummodes))
753 if (!leavecurrentmode)
755 pv = VID_GetModePtr (mode);
756 pinfo = pv->modedesc;
760 sprintf (temp, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
768 // KJB: Added this to return the mode driver name in description for console
770 char *VID_GetExtModeDescription (int mode)
772 static char pinfo[40];
775 if ((mode < 0) || (mode >= nummodes))
778 pv = VID_GetModePtr (mode);
779 if (modelist[mode].type == MS_FULLDIB)
781 if (!leavecurrentmode)
782 sprintf(pinfo,"%s fullscreen", pv->modedesc);
784 sprintf (pinfo, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
788 if (modestate == MS_WINDOWED)
789 sprintf(pinfo, "%s windowed", pv->modedesc);
791 sprintf(pinfo, "windowed");
800 VID_DescribeCurrentMode_f
803 void VID_DescribeCurrentMode_f (void)
805 Con_Printf ("%s\n", VID_GetExtModeDescription (vid_modenum));
814 void VID_NumModes_f (void)
817 Con_Printf ("%d video mode is available\n", nummodes);
819 Con_Printf ("%d video modes are available\n", nummodes);
828 void VID_DescribeMode_f (void)
832 modenum = atoi (Cmd_Argv(1));
834 t = leavecurrentmode;
835 leavecurrentmode = 0;
837 Con_Printf ("%s\n", VID_GetExtModeDescription (modenum));
839 leavecurrentmode = t;
848 void VID_DescribeModes_f (void)
854 lnummodes = VID_NumModes ();
856 t = leavecurrentmode;
857 leavecurrentmode = 0;
859 for (i=1 ; i<lnummodes ; i++)
861 pv = VID_GetModePtr (i);
862 pinfo = VID_GetExtModeDescription (i);
863 Con_Printf ("%2d: %s\n", i, pinfo);
866 leavecurrentmode = t;
869 void VID_AddMode(int type, int width, int height, int modenum, int halfscreen, int dib, int fullscreen, int bpp)
872 if (nummodes >= MAX_MODE_LIST)
874 modelist[nummodes].type = type;
875 modelist[nummodes].width = width;
876 modelist[nummodes].height = height;
877 modelist[nummodes].modenum = modenum;
878 modelist[nummodes].halfscreen = halfscreen;
879 modelist[nummodes].dib = dib;
880 modelist[nummodes].fullscreen = fullscreen;
881 modelist[nummodes].bpp = bpp;
883 sprintf (modelist[nummodes].modedesc, "%dx%d", width, height);
885 sprintf (modelist[nummodes].modedesc, "%dx%dx%d", width, height, bpp);
886 for (i = 0;i < nummodes;i++)
888 if (!memcmp(&modelist[i], &modelist[nummodes], sizeof(vmode_t)))
894 void VID_InitDIB (HINSTANCE hInstance)
899 // Register the frame class
901 wc.lpfnWndProc = (WNDPROC)MainWndProc;
904 wc.hInstance = hInstance;
906 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
907 wc.hbrBackground = NULL;
909 wc.lpszClassName = gamename;
911 if (!RegisterClass (&wc) )
912 Sys_Error ("Couldn't register window class");
914 if (COM_CheckParm("-width"))
915 w = atoi(com_argv[COM_CheckParm("-width")+1]);
922 if (COM_CheckParm("-height"))
923 h = atoi(com_argv[COM_CheckParm("-height")+1]);
930 VID_AddMode(MS_WINDOWED, w, h, 0, 0, 1, 0, 0);
939 void VID_InitFullDIB (HINSTANCE hInstance)
943 int originalnummodes;
950 // enumerate >8 bpp modes
951 originalnummodes = nummodes;
956 stat = EnumDisplaySettings (NULL, modenum, &devmode);
958 if ((devmode.dmBitsPerPel >= 15) && (devmode.dmPelsWidth <= MAXWIDTH) && (devmode.dmPelsHeight <= MAXHEIGHT) && (nummodes < MAX_MODE_LIST))
960 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
962 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
964 // if the width is more than twice the height, reduce it by half because this
965 // is probably a dual-screen monitor
966 if ((!COM_CheckParm("-noadjustaspect")) && (devmode.dmPelsWidth > (devmode.dmPelsHeight << 1)))
967 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth >> 1, devmode.dmPelsHeight, 0, 1, 1, 1, devmode.dmBitsPerPel);
969 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
977 // see if there are any low-res modes that aren't being reported
978 numlowresmodes = sizeof(lowresmodes) / sizeof(lowresmodes[0]);
984 for (j=0 ; (j<numlowresmodes) && (nummodes < MAX_MODE_LIST) ; j++)
986 devmode.dmBitsPerPel = bpp;
987 devmode.dmPelsWidth = lowresmodes[j].width;
988 devmode.dmPelsHeight = lowresmodes[j].height;
989 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
991 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
992 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
1011 if (nummodes == originalnummodes)
1012 Con_SafePrintf ("No fullscreen DIB modes found\n");
1015 //static int grabsysgamma = true;
1016 WORD systemgammaramps[3][256], currentgammaramps[3][256];
1018 int VID_SetGamma(float prescale, float gamma, float scale, float base)
1024 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
1025 for (i = 0;i < 256;i++)
1026 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
1028 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
1030 ReleaseDC (NULL, hdc);
1031 return i; // return success or failure
1034 void VID_RestoreGameGamma(void)
1036 VID_UpdateGamma(true);
1039 void VID_GetSystemGamma(void)
1044 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1046 ReleaseDC (NULL, hdc);
1049 void VID_RestoreSystemGamma(void)
1054 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1056 ReleaseDC (NULL, hdc);
1064 void VID_Init (void)
1067 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 ();