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 int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
28 int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
29 //int (WINAPI *qwglGetPixelFormat)(HDC);
30 BOOL (WINAPI *qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
31 BOOL (WINAPI *qwglSwapBuffers)(HDC);
32 HGLRC (WINAPI *qwglCreateContext)(HDC);
33 BOOL (WINAPI *qwglDeleteContext)(HGLRC);
34 PROC (WINAPI *qwglGetProcAddress)(LPCSTR);
35 BOOL (WINAPI *qwglMakeCurrent)(HDC, HGLRC);
36 BOOL (WINAPI *qwglSwapIntervalEXT)(int interval);
37 const char *(WINAPI *wglGetExtensionsStringARB)(HDC hdc);
39 static gl_extensionfunctionlist_t getextensionsstringfuncs[] =
41 {"wglGetExtensionsString", (void **) &qwglGetExtensionsString},
45 static gl_extensionfunctionlist_t wglfuncs[] =
47 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
48 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
49 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
50 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
51 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
52 {"wglCreateContext", (void **) &qwglCreateContext},
53 {"wglDeleteContext", (void **) &qwglDeleteContext},
54 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
55 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
59 static gl_extensionfunctionlist_t wglswapintervalfuncs[] =
61 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
65 #define MAX_MODE_LIST 30
66 #define VID_ROW_SIZE 3
67 #define MAXWIDTH 10000
68 #define MAXHEIGHT 10000
70 #define MODE_WINDOWED 0
71 #define NO_MODE (MODE_WINDOWED - 1)
72 #define MODE_FULLSCREEN_DEFAULT (MODE_WINDOWED + 1)
90 lmode_t lowresmodes[] = {
97 qboolean scr_skipupdate;
99 static vmode_t modelist[MAX_MODE_LIST];
101 static vmode_t badmode;
103 static DEVMODE gdevmode;
104 static qboolean vid_initialized = false;
105 static qboolean windowed, leavecurrentmode;
106 static qboolean vid_canalttab = false;
107 static qboolean vid_wassuspended = false;
108 static int vid_usingmouse;
109 extern qboolean mouseactive; // from in_win.c
112 int DIBWidth, DIBHeight;
114 DWORD WindowStyle, ExWindowStyle;
118 int vid_modenum = NO_MODE;
120 int vid_default = MODE_WINDOWED;
121 static int windowed_default;
122 unsigned char vid_curpal[256*3];
127 HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
129 // global video state
132 modestate_t modestate = MS_UNINIT;
134 void VID_MenuDraw (void);
135 void VID_MenuKey (int key);
137 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
138 void AppActivate(BOOL fActive, BOOL minimize);
139 char *VID_GetModeDescription (int mode);
140 void ClearAllStates (void);
141 void VID_UpdateWindowStatus (void);
143 //====================================
145 int window_center_x, window_center_y, window_x, window_y, window_width, window_height;
148 // direct draw software compatability stuff
150 void CenterWindow(HWND hWndCenter, int width, int height, BOOL lefttopjustify)
152 int CenterX, CenterY;
154 CenterX = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
155 CenterY = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
156 if (CenterX > CenterY*2)
157 CenterX >>= 1; // dual screens
158 CenterX = (CenterX < 0) ? 0: CenterX;
159 CenterY = (CenterY < 0) ? 0: CenterY;
160 SetWindowPos (hWndCenter, NULL, CenterX, CenterY, 0, 0,
161 SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
164 qboolean VID_SetWindowedMode (int modenum)
166 int lastmodestate, width, height;
169 lastmodestate = modestate;
171 WindowRect.top = WindowRect.left = 0;
173 WindowRect.right = modelist[modenum].width;
174 WindowRect.bottom = modelist[modenum].height;
176 DIBWidth = modelist[modenum].width;
177 DIBHeight = modelist[modenum].height;
179 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
183 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
185 width = rect.right - rect.left;
186 height = rect.bottom - rect.top;
188 // Create the DIB window
189 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
192 Sys_Error ("Couldn't create DIB window");
194 // Center and show the DIB window
195 CenterWindow(mainwindow, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, false);
197 ShowWindow (mainwindow, SW_SHOWDEFAULT);
198 UpdateWindow (mainwindow);
200 modestate = MS_WINDOWED;
202 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
203 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
209 qboolean VID_SetFullDIBMode (int modenum)
211 int lastmodestate, width, height;
214 if (!leavecurrentmode)
216 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
217 gdevmode.dmBitsPerPel = modelist[modenum].bpp;
218 gdevmode.dmPelsWidth = modelist[modenum].width;
219 gdevmode.dmPelsHeight = modelist[modenum].height;
220 gdevmode.dmSize = sizeof (gdevmode);
222 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
223 Sys_Error ("Couldn't set fullscreen DIB mode");
226 lastmodestate = modestate;
227 modestate = MS_FULLDIB;
229 WindowRect.top = WindowRect.left = 0;
231 WindowRect.right = modelist[modenum].width;
232 WindowRect.bottom = modelist[modenum].height;
234 DIBWidth = modelist[modenum].width;
235 DIBHeight = modelist[modenum].height;
237 WindowStyle = WS_POPUP;
241 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
243 width = rect.right - rect.left;
244 height = rect.bottom - rect.top;
246 // Create the DIB window
247 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
250 Sys_Error ("Couldn't create DIB window");
252 ShowWindow (mainwindow, SW_SHOWDEFAULT);
253 UpdateWindow (mainwindow);
255 // needed because we're not getting WM_MOVE messages fullscreen on NT
259 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
260 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
266 int VID_SetMode (int modenum)
272 if ((windowed && (modenum != 0)) || (!windowed && (modenum < 1)) || (!windowed && (modenum >= nummodes)))
273 Sys_Error ("Bad video mode\n");
277 if (vid_modenum == NO_MODE)
278 original_mode = windowed_default;
280 original_mode = vid_modenum;
282 // Set either the fullscreen or windowed mode
283 if (modelist[modenum].type == MS_WINDOWED)
284 stat = VID_SetWindowedMode(modenum);
285 else if (modelist[modenum].type == MS_FULLDIB)
286 stat = VID_SetFullDIBMode(modenum);
288 Sys_Error ("VID_SetMode: Bad mode type in modelist");
290 window_width = DIBWidth;
291 window_height = DIBHeight;
292 VID_UpdateWindowStatus ();
297 Sys_Error ("Couldn't set video mode");
299 // now we try to make sure we get the focus on the mode switch, because
300 // sometimes in some systems we don't. We grab the foreground, then
301 // finish setting up, pump all our messages, and sleep for a little while
302 // to let messages finish bouncing around the system, then we put
303 // ourselves at the top of the z order, then grab the foreground again,
304 // Who knows if it helps, but it probably doesn't hurt
305 SetForegroundWindow (mainwindow);
306 vid_modenum = modenum;
307 Cvar_SetValue ("vid_mode", (float)vid_modenum);
309 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
311 TranslateMessage (&msg);
312 DispatchMessage (&msg);
317 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
319 SetForegroundWindow (mainwindow);
321 // fix the leftover Alt from any Alt-Tab or the like that switched us away
325 Con_SafePrintf ("Video mode %s initialized.\n", VID_GetModeDescription (vid_modenum));
333 VID_UpdateWindowStatus
336 void VID_UpdateWindowStatus (void)
338 window_rect.left = window_x;
339 window_rect.top = window_y;
340 window_rect.right = window_x + window_width;
341 window_rect.bottom = window_y + window_height;
342 window_center_x = (window_rect.left + window_rect.right) / 2;
343 window_center_y = (window_rect.top + window_rect.bottom) / 2;
345 IN_UpdateClipCursor ();
349 //====================================
356 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
359 *width = WindowRect.right - WindowRect.left;
360 *height = WindowRect.bottom - WindowRect.top;
364 void VID_Finish (void)
367 if (r_render.integer && !scr_skipupdate)
373 // handle the mouse state when windowed if that's changed
374 vid_usemouse = false;
375 if (vid_mouse.integer && !key_consoleactive)
377 if (modestate == MS_FULLDIB)
379 if (!vid_activewindow)
380 vid_usemouse = false;
385 vid_usingmouse = true;
394 vid_usingmouse = false;
395 IN_DeactivateMouse ();
401 void VID_SetDefaultMode (void)
403 IN_DeactivateMouse ();
406 void VID_RestoreSystemGamma(void);
408 void VID_Shutdown (void)
417 vid_canalttab = false;
418 hRC = qwglGetCurrentContext();
419 hDC = qwglGetCurrentDC();
421 qwglMakeCurrent(NULL, NULL);
423 // LordHavoc: free textures before closing (may help NVIDIA)
424 for (i = 0;i < 8192;i++)
426 qglDeleteTextures(8192, temp);
429 qwglDeleteContext(hRC);
431 // close the library before we get rid of the window
434 if (hDC && mainwindow)
435 ReleaseDC(mainwindow, hDC);
437 if (modestate == MS_FULLDIB)
438 ChangeDisplaySettings (NULL, 0);
440 if (maindc && mainwindow)
441 ReleaseDC (mainwindow, maindc);
443 AppActivate(false, false);
445 VID_RestoreSystemGamma();
450 //==========================================================================
453 BOOL bSetupPixelFormat(HDC hDC)
455 static PIXELFORMATDESCRIPTOR pfd = {
456 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
458 PFD_DRAW_TO_WINDOW // support window
459 | PFD_SUPPORT_OPENGL // support OpenGL
460 | PFD_DOUBLEBUFFER , // double buffered
461 PFD_TYPE_RGBA, // RGBA type
462 24, // 24-bit color depth
463 0, 0, 0, 0, 0, 0, // color bits ignored
464 0, // no alpha buffer
465 0, // shift bit ignored
466 0, // no accumulation buffer
467 0, 0, 0, 0, // accum bits ignored
468 32, // 32-bit z-buffer
469 0, // no stencil buffer
470 0, // no auxiliary buffer
471 PFD_MAIN_PLANE, // main layer
473 0, 0, 0 // layer masks ignored
477 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
479 MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
483 if (SetPixelFormat(hDC, pixelformat, &pfd) == false)
485 MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
494 qbyte scantokey[128] =
496 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
497 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
498 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
499 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
500 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
501 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
502 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
503 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
504 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
512 Map from windows to quake keynums
515 int MapKey (int key, int virtualkey)
520 if (scantokey[key] == 0)
521 Con_DPrintf("key 0x%02x has no translation\n", key);
522 return scantokey[key];
526 ===================================================================
530 ===================================================================
538 void ClearAllStates (void)
542 // send an up event for each key, to make sure the server clears them all
543 for (i=0 ; i<256 ; i++)
545 Key_Event (i, false);
552 void VID_RestoreGameGamma(void);
553 extern qboolean host_loopactive;
555 void AppActivate(BOOL fActive, BOOL minimize)
556 /****************************************************************************
558 * Function: AppActivate
559 * Parameters: fActive - True if app is activating
561 * Description: If the application is activating, then swap the system
562 * into SYSPAL_NOSTATIC mode so that our palettes will display
565 ****************************************************************************/
567 static BOOL sound_active;
569 vid_activewindow = fActive;
570 vid_hidden = minimize;
572 // enable/disable sound on focus gain/loss
573 if (!vid_activewindow && sound_active)
576 sound_active = false;
578 else if (vid_activewindow && !sound_active)
586 if (modestate == MS_FULLDIB)
588 if (vid_canalttab && vid_wassuspended)
590 vid_wassuspended = false;
591 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
592 ShowWindow(mainwindow, SW_SHOWNORMAL);
595 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
596 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
599 VID_RestoreGameGamma();
604 vid_usingmouse = false;
605 IN_DeactivateMouse ();
607 if (modestate == MS_FULLDIB && vid_canalttab)
609 ChangeDisplaySettings (NULL, 0);
610 vid_wassuspended = true;
612 VID_RestoreSystemGamma();
616 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
618 /* main window procedure */
619 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
622 int fActive, fMinimized, temp;
623 extern unsigned int uiWheelMessage;
625 if ( uMsg == uiWheelMessage )
626 uMsg = WM_MOUSEWHEEL;
631 if (modestate == MS_FULLDIB)
632 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
639 window_x = (int) LOWORD(lParam);
640 window_y = (int) HIWORD(lParam);
641 VID_UpdateWindowStatus ();
646 Key_Event (MapKey(lParam, wParam), true);
651 Key_Event (MapKey(lParam, wParam), false);
655 // keep Alt-Space from happening
658 // this is complicated because Win32 seems to pack multiple mouse events into
659 // one update sometimes, so we always check all states and look for events
669 if (wParam & MK_LBUTTON)
672 if (wParam & MK_RBUTTON)
675 if (wParam & MK_MBUTTON)
678 IN_MouseEvent (temp);
682 // JACK: This is the mouse wheel with the Intellimouse
683 // Its delta is either positive or neg, and we generate the proper
686 if ((short) HIWORD(wParam) > 0) {
687 Key_Event(K_MWHEELUP, true);
688 Key_Event(K_MWHEELUP, false);
690 Key_Event(K_MWHEELDOWN, true);
691 Key_Event(K_MWHEELDOWN, false);
699 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
705 fActive = LOWORD(wParam);
706 fMinimized = (BOOL) HIWORD(wParam);
707 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
709 // fix the leftover Alt from any Alt-Tab or the like that switched us away
717 DestroyWindow (mainwindow);
724 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
728 /* pass all unhandled messages to DefWindowProc */
729 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
733 /* return 1 if handled message, 0 if not */
743 int VID_NumModes (void)
754 vmode_t *VID_GetModePtr (int modenum)
757 if ((modenum >= 0) && (modenum < nummodes))
758 return &modelist[modenum];
766 VID_GetModeDescription
769 char *VID_GetModeDescription (int mode)
773 static char temp[100];
775 if ((mode < 0) || (mode >= nummodes))
778 if (!leavecurrentmode)
780 pv = VID_GetModePtr (mode);
781 pinfo = pv->modedesc;
785 sprintf (temp, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
793 // KJB: Added this to return the mode driver name in description for console
795 char *VID_GetExtModeDescription (int mode)
797 static char pinfo[40];
800 if ((mode < 0) || (mode >= nummodes))
803 pv = VID_GetModePtr (mode);
804 if (modelist[mode].type == MS_FULLDIB)
806 if (!leavecurrentmode)
807 sprintf(pinfo,"%s fullscreen", pv->modedesc);
809 sprintf (pinfo, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
813 if (modestate == MS_WINDOWED)
814 sprintf(pinfo, "%s windowed", pv->modedesc);
816 sprintf(pinfo, "windowed");
825 VID_DescribeCurrentMode_f
828 void VID_DescribeCurrentMode_f (void)
830 Con_Printf ("%s\n", VID_GetExtModeDescription (vid_modenum));
839 void VID_NumModes_f (void)
842 Con_Printf ("%d video mode is available\n", nummodes);
844 Con_Printf ("%d video modes are available\n", nummodes);
853 void VID_DescribeMode_f (void)
857 modenum = atoi (Cmd_Argv(1));
859 t = leavecurrentmode;
860 leavecurrentmode = 0;
862 Con_Printf ("%s\n", VID_GetExtModeDescription (modenum));
864 leavecurrentmode = t;
873 void VID_DescribeModes_f (void)
879 lnummodes = VID_NumModes ();
881 t = leavecurrentmode;
882 leavecurrentmode = 0;
884 for (i=1 ; i<lnummodes ; i++)
886 pv = VID_GetModePtr (i);
887 pinfo = VID_GetExtModeDescription (i);
888 Con_Printf ("%2d: %s\n", i, pinfo);
891 leavecurrentmode = t;
894 void VID_AddMode(int type, int width, int height, int modenum, int dib, int fullscreen, int bpp)
897 if (nummodes >= MAX_MODE_LIST)
899 modelist[nummodes].type = type;
900 modelist[nummodes].width = width;
901 modelist[nummodes].height = height;
902 modelist[nummodes].modenum = modenum;
903 modelist[nummodes].dib = dib;
904 modelist[nummodes].fullscreen = fullscreen;
905 modelist[nummodes].bpp = bpp;
907 sprintf (modelist[nummodes].modedesc, "%dx%d", width, height);
909 sprintf (modelist[nummodes].modedesc, "%dx%dx%d", width, height, bpp);
910 for (i = 0;i < nummodes;i++)
912 if (!memcmp(&modelist[i], &modelist[nummodes], sizeof(vmode_t)))
918 void VID_InitDIB (HINSTANCE hInstance)
923 // Register the frame class
925 wc.lpfnWndProc = (WNDPROC)MainWndProc;
928 wc.hInstance = hInstance;
930 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
931 wc.hbrBackground = NULL;
933 wc.lpszClassName = gamename;
935 if (!RegisterClass (&wc) )
936 Sys_Error ("Couldn't register window class");
938 if (COM_CheckParm("-width"))
939 w = atoi(com_argv[COM_CheckParm("-width")+1]);
946 if (COM_CheckParm("-height"))
947 h = atoi(com_argv[COM_CheckParm("-height")+1]);
954 VID_AddMode(MS_WINDOWED, w, h, 0, 1, 0, 0);
963 void VID_InitFullDIB (HINSTANCE hInstance)
967 int originalnummodes;
974 // enumerate >8 bpp modes
975 originalnummodes = nummodes;
980 stat = EnumDisplaySettings (NULL, modenum, &devmode);
982 if ((devmode.dmBitsPerPel >= 15) && (devmode.dmPelsWidth <= MAXWIDTH) && (devmode.dmPelsHeight <= MAXHEIGHT) && (nummodes < MAX_MODE_LIST))
984 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
986 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
988 // if the width is more than twice the height, reduce it by half because this
989 // is probably a dual-screen monitor
990 if ((!COM_CheckParm("-noadjustaspect")) && (devmode.dmPelsWidth > (devmode.dmPelsHeight << 1)))
991 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth >> 1, devmode.dmPelsHeight, 0, 1, 1, 1, devmode.dmBitsPerPel);
993 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
1001 // see if there are any low-res modes that aren't being reported
1002 numlowresmodes = sizeof(lowresmodes) / sizeof(lowresmodes[0]);
1008 for (j=0 ; (j<numlowresmodes) && (nummodes < MAX_MODE_LIST) ; j++)
1010 devmode.dmBitsPerPel = bpp;
1011 devmode.dmPelsWidth = lowresmodes[j].width;
1012 devmode.dmPelsHeight = lowresmodes[j].height;
1013 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
1015 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
1016 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 0, 1, 1, devmode.dmBitsPerPel);
1035 if (nummodes == originalnummodes)
1036 Con_SafePrintf ("No fullscreen DIB modes found\n");
1039 //static int grabsysgamma = true;
1040 WORD systemgammaramps[3][256], currentgammaramps[3][256];
1042 int VID_SetGamma(float prescale, float gamma, float scale, float base)
1048 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
1049 for (i = 0;i < 256;i++)
1050 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
1052 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
1054 ReleaseDC (NULL, hdc);
1055 return i; // return success or failure
1058 void VID_RestoreGameGamma(void)
1060 VID_UpdateGamma(true);
1063 void VID_GetSystemGamma(void)
1068 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1070 ReleaseDC (NULL, hdc);
1073 void VID_RestoreSystemGamma(void)
1078 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1080 ReleaseDC (NULL, hdc);
1083 //========================================================
1085 //========================================================
1087 extern void M_Menu_Options_f (void);
1088 extern void M_Print (float cx, float cy, char *str);
1089 extern void M_PrintWhite (float cx, float cy, char *str);
1090 extern void M_DrawCharacter (float cx, float cy, int num);
1091 extern void M_DrawPic (float cx, float cy, char *picname);
1093 static int vid_wmodes;
1102 #define MAX_COLUMN_SIZE 9
1103 #define MODE_AREA_HEIGHT (MAX_COLUMN_SIZE + 2)
1104 #define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
1106 static modedesc_t modedescs[MAX_MODEDESCS];
1113 void VID_MenuDraw (void)
1117 int lnummodes, i, k, column, row;
1120 p = Draw_CachePic ("gfx/vidmodes.lmp");
1121 M_DrawPic ( (320-p->width)/2, 4, "gfx/vidmodes.lmp");
1124 lnummodes = VID_NumModes ();
1126 for (i=1 ; (i<lnummodes) && (vid_wmodes < MAX_MODEDESCS) ; i++)
1128 ptr = VID_GetModeDescription (i);
1129 pv = VID_GetModePtr (i);
1133 modedescs[k].modenum = i;
1134 modedescs[k].desc = ptr;
1135 modedescs[k].iscur = 0;
1137 if (i == vid_modenum)
1138 modedescs[k].iscur = 1;
1146 M_Print (2*8, 36+0*8, "Fullscreen Modes (WIDTHxHEIGHTxBPP)");
1151 for (i=0 ; i<vid_wmodes ; i++)
1153 if (modedescs[i].iscur)
1154 M_PrintWhite (column, row, modedescs[i].desc);
1156 M_Print (column, row, modedescs[i].desc);
1160 if ((i % VID_ROW_SIZE) == (VID_ROW_SIZE - 1))
1168 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*2, "Video modes must be set from the");
1169 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*3, "command line with -width <width>");
1170 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*4, "and -bpp <bits-per-pixel>");
1171 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*6, "Select windowed mode with -window");
1180 void VID_MenuKey (int key)
1185 S_LocalSound ("misc/menu1.wav");
1186 M_Menu_Options_f ();
1194 static HINSTANCE gldll;
1196 int GL_OpenLibrary(const char *name)
1198 Con_Printf("Loading GL driver %s\n", name);
1200 if (!(gldll = LoadLibrary(name)))
1202 Con_Printf("Unable to LoadLibrary %s\n", name);
1205 strcpy(gl_driver, name);
1209 void GL_CloseLibrary(void)
1214 qwglGetProcAddress = NULL;
1217 gl_platformextensions = "";
1220 void *GL_GetProcAddress(const char *name)
1223 if (qwglGetProcAddress != NULL)
1224 p = (void *) qwglGetProcAddress(name);
1226 p = (void *) GetProcAddress(gldll, name);
1234 void VID_Init (int fullscreen, int width, int height)
1237 int basenummodes, bpp, findbpp, done;
1241 if (!GL_OpenLibrary("opengl32.dll"))
1242 Sys_Error("Unable to load GL driver\n");
1244 memset(&devmode, 0, sizeof(devmode));
1246 Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
1247 Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
1248 Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
1249 Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);
1251 VID_GetSystemGamma();
1253 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
1255 InitCommonControls();
1257 VID_InitDIB (global_hInstance);
1258 basenummodes = nummodes = 1;
1260 VID_InitFullDIB (global_hInstance);
1266 if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
1267 Sys_Error ("Can't run in non-RGB mode");
1269 ReleaseDC (NULL, hdc);
1273 vid_default = MODE_WINDOWED;
1278 Sys_Error ("No RGB fullscreen modes available");
1285 bestrating = 1000000000;
1286 for (i = 0;i < nummodes;i++)
1288 rating = VID_CompareMode(fullscreen, width, height, bpp, modelist[i].fullscreen, modelist[i].width, modelist[i].height, modelist[i].bpp);
1289 if (bestrating > rating)
1291 bestrating = rating;
1297 Sys_Error ("Specified video mode not available");
1300 vid_initialized = true;
1302 VID_SetMode (vid_default);
1304 maindc = GetDC(mainwindow);
1305 bSetupPixelFormat(maindc);
1307 if (!gl_checkextension("wgl", wglfuncs, NULL, false))
1308 Sys_Error("wgl functions not found\n");
1310 baseRC = qwglCreateContext( maindc );
1312 Sys_Error ("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.");
1313 if (!qwglMakeCurrent( maindc, baseRC ))
1314 Sys_Error ("wglMakeCurrent failed");
1316 gl_renderer = qglGetString(GL_RENDERER);
1317 gl_vendor = qglGetString(GL_VENDOR);
1318 gl_version = qglGetString(GL_VERSION);
1319 gl_extensions = qglGetString(GL_EXTENSIONS);
1320 gl_platformname = "WGL";
1321 gl_platformextensions = "";
1323 if (gl_checkextension("WGL_ARB_extensions_string", extensionsstringfuncs, NULL, false))
1324 gl_platformextensions = qwglGetExtensionsStringARB(maindc);
1326 gl_videosyncavailable = gl_checkextension("WGL_EXT_swap_control", wglswapintervalfuncs, NULL, false);
1330 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
1331 if (strncasecmp(gl_vendor,"ATI",3)==0)
1333 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
1336 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
1339 vid_realmode = vid_modenum;
1341 vid_menudrawfn = VID_MenuDraw;
1342 vid_menukeyfn = VID_MenuKey;
1344 strcpy (badmode.modedesc, "Bad mode");
1345 vid_canalttab = true;