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 cl_available = true;
29 int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
30 int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
31 //int (WINAPI *qwglGetPixelFormat)(HDC);
32 BOOL (WINAPI *qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
33 BOOL (WINAPI *qwglSwapBuffers)(HDC);
34 HGLRC (WINAPI *qwglCreateContext)(HDC);
35 BOOL (WINAPI *qwglDeleteContext)(HGLRC);
36 HGLRC (WINAPI *qwglGetCurrentContext)(VOID);
37 HDC (WINAPI *qwglGetCurrentDC)(VOID);
38 PROC (WINAPI *qwglGetProcAddress)(LPCSTR);
39 BOOL (WINAPI *qwglMakeCurrent)(HDC, HGLRC);
40 BOOL (WINAPI *qwglSwapIntervalEXT)(int interval);
41 const char *(WINAPI *qwglGetExtensionsStringARB)(HDC hdc);
43 static gl_extensionfunctionlist_t getextensionsstringfuncs[] =
45 {"wglGetExtensionsString", (void **) &qwglGetExtensionsStringARB},
49 static gl_extensionfunctionlist_t wglfuncs[] =
51 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
52 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
53 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
54 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
55 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
56 {"wglCreateContext", (void **) &qwglCreateContext},
57 {"wglDeleteContext", (void **) &qwglDeleteContext},
58 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
59 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
63 static gl_extensionfunctionlist_t wglswapintervalfuncs[] =
65 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
69 #define MAX_MODE_LIST 30
70 #define VID_ROW_SIZE 3
71 #define MAXWIDTH 10000
72 #define MAXHEIGHT 10000
74 #define MODE_WINDOWED 0
75 #define NO_MODE (MODE_WINDOWED - 1)
76 #define MODE_FULLSCREEN_DEFAULT (MODE_WINDOWED + 1)
94 lmode_t lowresmodes[] = {
101 qboolean scr_skipupdate;
103 static vmode_t modelist[MAX_MODE_LIST];
105 static vmode_t badmode;
107 static DEVMODE gdevmode;
108 static qboolean vid_initialized = false;
109 static qboolean windowed, leavecurrentmode;
110 static qboolean vid_canalttab = false;
111 static qboolean vid_wassuspended = false;
112 static int vid_usingmouse;
113 extern qboolean mouseactive; // from in_win.c
116 int DIBWidth, DIBHeight;
118 DWORD WindowStyle, ExWindowStyle;
122 int vid_modenum = NO_MODE;
124 int vid_default = MODE_WINDOWED;
125 static int windowed_default;
126 unsigned char vid_curpal[256*3];
131 HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
133 // global video state
136 modestate_t modestate = MS_UNINIT;
138 void VID_MenuDraw (void);
139 void VID_MenuKey (int key);
141 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
142 void AppActivate(BOOL fActive, BOOL minimize);
143 char *VID_GetModeDescription (int mode);
144 void ClearAllStates (void);
145 void VID_UpdateWindowStatus (void);
147 //====================================
149 int window_center_x, window_center_y, window_x, window_y, window_width, window_height;
152 // direct draw software compatability stuff
154 void CenterWindow(HWND hWndCenter, int width, int height, BOOL lefttopjustify)
156 int CenterX, CenterY;
158 CenterX = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
159 CenterY = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
160 if (CenterX > CenterY*2)
161 CenterX >>= 1; // dual screens
162 CenterX = (CenterX < 0) ? 0: CenterX;
163 CenterY = (CenterY < 0) ? 0: CenterY;
164 SetWindowPos (hWndCenter, NULL, CenterX, CenterY, 0, 0,
165 SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
168 qboolean VID_SetWindowedMode (int modenum)
170 int lastmodestate, width, height;
173 lastmodestate = modestate;
175 WindowRect.top = WindowRect.left = 0;
177 WindowRect.right = modelist[modenum].width;
178 WindowRect.bottom = modelist[modenum].height;
180 DIBWidth = modelist[modenum].width;
181 DIBHeight = modelist[modenum].height;
183 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
187 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
189 width = rect.right - rect.left;
190 height = rect.bottom - rect.top;
192 // Create the DIB window
193 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
196 Sys_Error ("Couldn't create DIB window");
198 // Center and show the DIB window
199 CenterWindow(mainwindow, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, false);
201 ShowWindow (mainwindow, SW_SHOWDEFAULT);
202 UpdateWindow (mainwindow);
204 modestate = MS_WINDOWED;
206 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
207 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
213 qboolean VID_SetFullDIBMode (int modenum)
215 int lastmodestate, width, height;
218 if (!leavecurrentmode)
220 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
221 gdevmode.dmBitsPerPel = modelist[modenum].bpp;
222 gdevmode.dmPelsWidth = modelist[modenum].width;
223 gdevmode.dmPelsHeight = modelist[modenum].height;
224 gdevmode.dmSize = sizeof (gdevmode);
226 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
227 Sys_Error ("Couldn't set fullscreen DIB mode");
230 lastmodestate = modestate;
231 modestate = MS_FULLDIB;
233 WindowRect.top = WindowRect.left = 0;
235 WindowRect.right = modelist[modenum].width;
236 WindowRect.bottom = modelist[modenum].height;
238 DIBWidth = modelist[modenum].width;
239 DIBHeight = modelist[modenum].height;
241 WindowStyle = WS_POPUP;
245 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
247 width = rect.right - rect.left;
248 height = rect.bottom - rect.top;
250 // Create the DIB window
251 mainwindow = CreateWindowEx (ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
254 Sys_Error ("Couldn't create DIB window");
256 ShowWindow (mainwindow, SW_SHOWDEFAULT);
257 UpdateWindow (mainwindow);
259 // needed because we're not getting WM_MOVE messages fullscreen on NT
263 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
264 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
270 int VID_SetMode (int modenum)
276 if ((windowed && (modenum != 0)) || (!windowed && (modenum < 1)) || (!windowed && (modenum >= nummodes)))
277 Sys_Error ("Bad video mode\n");
281 if (vid_modenum == NO_MODE)
282 original_mode = windowed_default;
284 original_mode = vid_modenum;
286 // Set either the fullscreen or windowed mode
287 if (modelist[modenum].type == MS_WINDOWED)
288 stat = VID_SetWindowedMode(modenum);
289 else if (modelist[modenum].type == MS_FULLDIB)
290 stat = VID_SetFullDIBMode(modenum);
292 Sys_Error ("VID_SetMode: Bad mode type in modelist");
294 window_width = DIBWidth;
295 window_height = DIBHeight;
296 VID_UpdateWindowStatus ();
301 Sys_Error ("Couldn't set video mode");
303 // now we try to make sure we get the focus on the mode switch, because
304 // sometimes in some systems we don't. We grab the foreground, then
305 // finish setting up, pump all our messages, and sleep for a little while
306 // to let messages finish bouncing around the system, then we put
307 // ourselves at the top of the z order, then grab the foreground again,
308 // Who knows if it helps, but it probably doesn't hurt
309 SetForegroundWindow (mainwindow);
310 vid_modenum = modenum;
311 Cvar_SetValue ("vid_mode", (float)vid_modenum);
313 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
315 TranslateMessage (&msg);
316 DispatchMessage (&msg);
321 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
323 SetForegroundWindow (mainwindow);
325 // fix the leftover Alt from any Alt-Tab or the like that switched us away
329 Con_SafePrintf ("Video mode %s initialized.\n", VID_GetModeDescription (vid_modenum));
337 VID_UpdateWindowStatus
340 void VID_UpdateWindowStatus (void)
342 window_rect.left = window_x;
343 window_rect.top = window_y;
344 window_rect.right = window_x + window_width;
345 window_rect.bottom = window_y + window_height;
346 window_center_x = (window_rect.left + window_rect.right) / 2;
347 window_center_y = (window_rect.top + window_rect.bottom) / 2;
349 IN_UpdateClipCursor ();
353 //====================================
360 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
363 *width = WindowRect.right - WindowRect.left;
364 *height = WindowRect.bottom - WindowRect.top;
368 void VID_Finish (void)
371 if (r_render.integer && !scr_skipupdate)
377 // handle the mouse state when windowed if that's changed
378 vid_usemouse = false;
379 if (vid_mouse.integer && !key_consoleactive)
381 if (modestate == MS_FULLDIB)
383 if (!vid_activewindow)
384 vid_usemouse = false;
389 vid_usingmouse = true;
398 vid_usingmouse = false;
399 IN_DeactivateMouse ();
405 void VID_SetDefaultMode (void)
407 IN_DeactivateMouse ();
410 void VID_RestoreSystemGamma(void);
412 void VID_Shutdown (void)
421 vid_canalttab = false;
422 hRC = qwglGetCurrentContext();
423 hDC = qwglGetCurrentDC();
425 qwglMakeCurrent(NULL, NULL);
427 // LordHavoc: free textures before closing (may help NVIDIA)
428 for (i = 0;i < 8192;i++)
430 qglDeleteTextures(8192, temp);
433 qwglDeleteContext(hRC);
435 // close the library before we get rid of the window
438 if (hDC && mainwindow)
439 ReleaseDC(mainwindow, hDC);
441 if (modestate == MS_FULLDIB)
442 ChangeDisplaySettings (NULL, 0);
444 if (maindc && mainwindow)
445 ReleaseDC (mainwindow, maindc);
447 AppActivate(false, false);
449 VID_RestoreSystemGamma();
454 //==========================================================================
457 BOOL bSetupPixelFormat(HDC hDC)
459 static PIXELFORMATDESCRIPTOR pfd = {
460 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
462 PFD_DRAW_TO_WINDOW // support window
463 | PFD_SUPPORT_OPENGL // support OpenGL
464 | PFD_DOUBLEBUFFER , // double buffered
465 PFD_TYPE_RGBA, // RGBA type
466 24, // 24-bit color depth
467 0, 0, 0, 0, 0, 0, // color bits ignored
468 0, // no alpha buffer
469 0, // shift bit ignored
470 0, // no accumulation buffer
471 0, 0, 0, 0, // accum bits ignored
472 32, // 32-bit z-buffer
473 0, // no stencil buffer
474 0, // no auxiliary buffer
475 PFD_MAIN_PLANE, // main layer
477 0, 0, 0 // layer masks ignored
481 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
483 MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
487 if (SetPixelFormat(hDC, pixelformat, &pfd) == false)
489 MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
498 qbyte scantokey[128] =
500 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
501 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
502 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
503 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
504 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
505 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
506 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
507 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
508 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
516 Map from windows to quake keynums
519 int MapKey (int key, int virtualkey)
524 if (scantokey[key] == 0)
525 Con_DPrintf("key 0x%02x has no translation\n", key);
526 return scantokey[key];
530 ===================================================================
534 ===================================================================
542 void ClearAllStates (void)
546 // send an up event for each key, to make sure the server clears them all
547 for (i=0 ; i<256 ; i++)
549 Key_Event (i, false);
556 void VID_RestoreGameGamma(void);
557 extern qboolean host_loopactive;
559 void AppActivate(BOOL fActive, BOOL minimize)
560 /****************************************************************************
562 * Function: AppActivate
563 * Parameters: fActive - True if app is activating
565 * Description: If the application is activating, then swap the system
566 * into SYSPAL_NOSTATIC mode so that our palettes will display
569 ****************************************************************************/
571 static BOOL sound_active;
573 vid_activewindow = fActive;
574 vid_hidden = minimize;
576 // enable/disable sound on focus gain/loss
577 if (!vid_activewindow && sound_active)
580 sound_active = false;
582 else if (vid_activewindow && !sound_active)
590 if (modestate == MS_FULLDIB)
592 if (vid_canalttab && vid_wassuspended)
594 vid_wassuspended = false;
595 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
596 ShowWindow(mainwindow, SW_SHOWNORMAL);
599 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
600 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
603 VID_RestoreGameGamma();
608 vid_usingmouse = false;
609 IN_DeactivateMouse ();
611 if (modestate == MS_FULLDIB && vid_canalttab)
613 ChangeDisplaySettings (NULL, 0);
614 vid_wassuspended = true;
616 VID_RestoreSystemGamma();
620 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
622 /* main window procedure */
623 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
626 int fActive, fMinimized, temp;
627 extern unsigned int uiWheelMessage;
629 if ( uMsg == uiWheelMessage )
630 uMsg = WM_MOUSEWHEEL;
635 if (modestate == MS_FULLDIB)
636 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
643 window_x = (int) LOWORD(lParam);
644 window_y = (int) HIWORD(lParam);
645 VID_UpdateWindowStatus ();
650 Key_Event (MapKey(lParam, wParam), true);
655 Key_Event (MapKey(lParam, wParam), false);
659 // keep Alt-Space from happening
662 // this is complicated because Win32 seems to pack multiple mouse events into
663 // one update sometimes, so we always check all states and look for events
673 if (wParam & MK_LBUTTON)
676 if (wParam & MK_RBUTTON)
679 if (wParam & MK_MBUTTON)
682 IN_MouseEvent (temp);
686 // JACK: This is the mouse wheel with the Intellimouse
687 // Its delta is either positive or neg, and we generate the proper
690 if ((short) HIWORD(wParam) > 0) {
691 Key_Event(K_MWHEELUP, true);
692 Key_Event(K_MWHEELUP, false);
694 Key_Event(K_MWHEELDOWN, true);
695 Key_Event(K_MWHEELDOWN, false);
703 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
709 fActive = LOWORD(wParam);
710 fMinimized = (BOOL) HIWORD(wParam);
711 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
713 // fix the leftover Alt from any Alt-Tab or the like that switched us away
721 DestroyWindow (mainwindow);
728 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
732 /* pass all unhandled messages to DefWindowProc */
733 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
737 /* return 1 if handled message, 0 if not */
747 int VID_NumModes (void)
758 vmode_t *VID_GetModePtr (int modenum)
761 if ((modenum >= 0) && (modenum < nummodes))
762 return &modelist[modenum];
770 VID_GetModeDescription
773 char *VID_GetModeDescription (int mode)
777 static char temp[100];
779 if ((mode < 0) || (mode >= nummodes))
782 if (!leavecurrentmode)
784 pv = VID_GetModePtr (mode);
785 pinfo = pv->modedesc;
789 sprintf (temp, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
797 // KJB: Added this to return the mode driver name in description for console
799 char *VID_GetExtModeDescription (int mode)
801 static char pinfo[40];
804 if ((mode < 0) || (mode >= nummodes))
807 pv = VID_GetModePtr (mode);
808 if (modelist[mode].type == MS_FULLDIB)
810 if (!leavecurrentmode)
811 sprintf(pinfo,"%s fullscreen", pv->modedesc);
813 sprintf (pinfo, "Desktop resolution (%dx%d)", modelist[MODE_FULLSCREEN_DEFAULT].width, modelist[MODE_FULLSCREEN_DEFAULT].height);
817 if (modestate == MS_WINDOWED)
818 sprintf(pinfo, "%s windowed", pv->modedesc);
820 sprintf(pinfo, "windowed");
829 VID_DescribeCurrentMode_f
832 void VID_DescribeCurrentMode_f (void)
834 Con_Printf ("%s\n", VID_GetExtModeDescription (vid_modenum));
843 void VID_NumModes_f (void)
846 Con_Printf ("%d video mode is available\n", nummodes);
848 Con_Printf ("%d video modes are available\n", nummodes);
857 void VID_DescribeMode_f (void)
861 modenum = atoi (Cmd_Argv(1));
863 t = leavecurrentmode;
864 leavecurrentmode = 0;
866 Con_Printf ("%s\n", VID_GetExtModeDescription (modenum));
868 leavecurrentmode = t;
877 void VID_DescribeModes_f (void)
883 lnummodes = VID_NumModes ();
885 t = leavecurrentmode;
886 leavecurrentmode = 0;
888 for (i=1 ; i<lnummodes ; i++)
890 pv = VID_GetModePtr (i);
891 pinfo = VID_GetExtModeDescription (i);
892 Con_Printf ("%2d: %s\n", i, pinfo);
895 leavecurrentmode = t;
898 void VID_AddMode(int type, int width, int height, int modenum, int dib, int fullscreen, int bpp)
901 if (nummodes >= MAX_MODE_LIST)
903 modelist[nummodes].type = type;
904 modelist[nummodes].width = width;
905 modelist[nummodes].height = height;
906 modelist[nummodes].modenum = modenum;
907 modelist[nummodes].dib = dib;
908 modelist[nummodes].fullscreen = fullscreen;
909 modelist[nummodes].bpp = bpp;
911 sprintf (modelist[nummodes].modedesc, "%dx%d", width, height);
913 sprintf (modelist[nummodes].modedesc, "%dx%dx%d", width, height, bpp);
914 for (i = 0;i < nummodes;i++)
916 if (!memcmp(&modelist[i], &modelist[nummodes], sizeof(vmode_t)))
922 void VID_InitDIB (HINSTANCE hInstance)
927 // Register the frame class
929 wc.lpfnWndProc = (WNDPROC)MainWndProc;
932 wc.hInstance = hInstance;
934 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
935 wc.hbrBackground = NULL;
937 wc.lpszClassName = gamename;
939 if (!RegisterClass (&wc) )
940 Sys_Error ("Couldn't register window class");
942 if (COM_CheckParm("-width"))
943 w = atoi(com_argv[COM_CheckParm("-width")+1]);
950 if (COM_CheckParm("-height"))
951 h = atoi(com_argv[COM_CheckParm("-height")+1]);
958 VID_AddMode(MS_WINDOWED, w, h, 0, 1, 0, 0);
967 void VID_InitFullDIB (HINSTANCE hInstance)
971 int originalnummodes;
978 // enumerate >8 bpp modes
979 originalnummodes = nummodes;
984 stat = EnumDisplaySettings (NULL, modenum, &devmode);
986 if ((devmode.dmBitsPerPel >= 15) && (devmode.dmPelsWidth <= MAXWIDTH) && (devmode.dmPelsHeight <= MAXHEIGHT) && (nummodes < MAX_MODE_LIST))
988 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
990 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
991 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 1, 1, devmode.dmBitsPerPel);
998 // see if there are any low-res modes that aren't being reported
999 numlowresmodes = sizeof(lowresmodes) / sizeof(lowresmodes[0]);
1005 for (j=0 ; (j<numlowresmodes) && (nummodes < MAX_MODE_LIST) ; j++)
1007 devmode.dmBitsPerPel = bpp;
1008 devmode.dmPelsWidth = lowresmodes[j].width;
1009 devmode.dmPelsHeight = lowresmodes[j].height;
1010 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
1012 if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
1013 VID_AddMode(MS_FULLDIB, devmode.dmPelsWidth, devmode.dmPelsHeight, 0, 1, 1, devmode.dmBitsPerPel);
1032 if (nummodes == originalnummodes)
1033 Con_SafePrintf ("No fullscreen DIB modes found\n");
1036 //static int grabsysgamma = true;
1037 WORD systemgammaramps[3][256], currentgammaramps[3][256];
1039 int VID_SetGamma(float prescale, float gamma, float scale, float base)
1045 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
1046 for (i = 0;i < 256;i++)
1047 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
1049 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
1051 ReleaseDC (NULL, hdc);
1052 return i; // return success or failure
1055 void VID_RestoreGameGamma(void)
1057 VID_UpdateGamma(true);
1060 void VID_GetSystemGamma(void)
1065 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1067 ReleaseDC (NULL, hdc);
1070 void VID_RestoreSystemGamma(void)
1075 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
1077 ReleaseDC (NULL, hdc);
1080 //========================================================
1082 //========================================================
1084 extern void M_Menu_Options_f (void);
1085 extern void M_Print (float cx, float cy, char *str);
1086 extern void M_PrintWhite (float cx, float cy, char *str);
1087 extern void M_DrawCharacter (float cx, float cy, int num);
1088 extern void M_DrawPic (float cx, float cy, char *picname);
1090 static int vid_wmodes;
1099 #define MAX_COLUMN_SIZE 9
1100 #define MODE_AREA_HEIGHT (MAX_COLUMN_SIZE + 2)
1101 #define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
1103 static modedesc_t modedescs[MAX_MODEDESCS];
1110 void VID_MenuDraw (void)
1114 int lnummodes, i, k, column, row;
1117 p = Draw_CachePic ("gfx/vidmodes.lmp");
1118 M_DrawPic ( (320-p->width)/2, 4, "gfx/vidmodes.lmp");
1121 lnummodes = VID_NumModes ();
1123 for (i=1 ; (i<lnummodes) && (vid_wmodes < MAX_MODEDESCS) ; i++)
1125 ptr = VID_GetModeDescription (i);
1126 pv = VID_GetModePtr (i);
1130 modedescs[k].modenum = i;
1131 modedescs[k].desc = ptr;
1132 modedescs[k].iscur = 0;
1134 if (i == vid_modenum)
1135 modedescs[k].iscur = 1;
1143 M_Print (2*8, 36+0*8, "Fullscreen Modes (WIDTHxHEIGHTxBPP)");
1148 for (i=0 ; i<vid_wmodes ; i++)
1150 if (modedescs[i].iscur)
1151 M_PrintWhite (column, row, modedescs[i].desc);
1153 M_Print (column, row, modedescs[i].desc);
1157 if ((i % VID_ROW_SIZE) == (VID_ROW_SIZE - 1))
1165 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*2, "Video modes must be set from the");
1166 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*3, "command line with -width <width>");
1167 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*4, "and -bpp <bits-per-pixel>");
1168 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*6, "Select windowed mode with -window");
1177 void VID_MenuKey (int key)
1182 S_LocalSound ("misc/menu1.wav");
1183 M_Menu_Options_f ();
1191 static HINSTANCE gldll;
1193 int GL_OpenLibrary(const char *name)
1195 Con_Printf("Loading GL driver %s\n", name);
1197 if (!(gldll = LoadLibrary(name)))
1199 Con_Printf("Unable to LoadLibrary %s\n", name);
1202 strcpy(gl_driver, name);
1206 void GL_CloseLibrary(void)
1211 qwglGetProcAddress = NULL;
1214 gl_platformextensions = "";
1217 void *GL_GetProcAddress(const char *name)
1220 if (qwglGetProcAddress != NULL)
1221 p = (void *) qwglGetProcAddress(name);
1223 p = (void *) GetProcAddress(gldll, name);
1231 void VID_Init (int fullscreen, int width, int height, int bpp)
1234 double rating, bestrating;
1235 int basenummodes, done;
1239 if (!GL_OpenLibrary("opengl32.dll"))
1240 Sys_Error("Unable to load GL driver\n");
1242 memset(&devmode, 0, sizeof(devmode));
1244 Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
1245 Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
1246 Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
1247 Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);
1249 VID_GetSystemGamma();
1251 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
1253 InitCommonControls();
1255 VID_InitDIB (global_hInstance);
1256 basenummodes = nummodes = 1;
1258 VID_InitFullDIB (global_hInstance);
1264 if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
1265 Sys_Error ("Can't run in non-RGB mode");
1267 ReleaseDC (NULL, hdc);
1271 vid_default = MODE_WINDOWED;
1276 Sys_Error ("No RGB fullscreen modes available");
1283 bestrating = 1000000000;
1284 for (i = 0;i < nummodes;i++)
1286 if (fullscreen == modelist[i].fullscreen)
1288 rating = VID_CompareMode(width, height, bpp, modelist[i].width, modelist[i].height, modelist[i].bpp);
1289 if (bestrating > rating)
1291 bestrating = rating;
1298 Sys_Error ("Specified video mode not available");
1301 vid_initialized = true;
1303 VID_SetMode (vid_default);
1305 maindc = GetDC(mainwindow);
1306 bSetupPixelFormat(maindc);
1308 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
1309 Sys_Error("wgl functions not found\n");
1311 baseRC = qwglCreateContext( maindc );
1313 Sys_Error ("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.");
1314 if (!qwglMakeCurrent( maindc, baseRC ))
1315 Sys_Error ("wglMakeCurrent failed");
1317 gl_renderer = qglGetString(GL_RENDERER);
1318 gl_vendor = qglGetString(GL_VENDOR);
1319 gl_version = qglGetString(GL_VERSION);
1320 gl_extensions = qglGetString(GL_EXTENSIONS);
1321 gl_platform = "WGL";
1322 gl_platformextensions = "";
1324 if (GL_CheckExtension("WGL_ARB_extensions_string", getextensionsstringfuncs, NULL, false))
1325 gl_platformextensions = qwglGetExtensionsStringARB(maindc);
1327 gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, NULL, false);
1331 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
1332 if (strncasecmp(gl_vendor,"ATI",3)==0)
1334 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
1337 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
1340 vid_realmode = vid_modenum;
1342 vid_menudrawfn = VID_MenuDraw;
1343 vid_menukeyfn = VID_MenuKey;
1345 strcpy (badmode.modedesc, "Bad mode");
1346 vid_canalttab = true;