+
+static HINSTANCE gldll;
+
+int GL_OpenLibrary(const char *name)
+{
+ Con_Printf("Loading GL driver %s\n", name);
+ GL_CloseLibrary();
+ if (!(gldll = LoadLibrary(name)))
+ {
+ Con_Printf("Unable to LoadLibrary %s\n", name);
+ return false;
+ }
+ strcpy(gl_driver, name);
+ return true;
+}
+
+void GL_CloseLibrary(void)
+{
+ FreeLibrary(gldll);
+ gldll = 0;
+ gl_driver[0] = 0;
+ qwglGetProcAddress = NULL;
+ gl_extensions = "";
+ gl_platform = "";
+ gl_platformextensions = "";
+}
+
+void *GL_GetProcAddress(const char *name)
+{
+ void *p = NULL;
+ if (qwglGetProcAddress != NULL)
+ p = (void *) qwglGetProcAddress(name);
+ if (p == NULL)
+ p = (void *) GetProcAddress(gldll, name);
+ return p;
+}
+/*
+===================
+VID_Init
+===================
+*/
+void VID_Init (int fullscreen, int width, int height, int bpp)
+{
+ int i, bestmode;
+ double rating, bestrating;
+ int basenummodes, done;
+ HDC hdc;
+ DEVMODE devmode;
+
+ if (!GL_OpenLibrary("opengl32.dll"))
+ Sys_Error("Unable to load GL driver\n");
+
+ memset(&devmode, 0, sizeof(devmode));
+
+ Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
+ Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
+ Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
+ Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);
+
+ VID_GetSystemGamma();
+
+ hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
+
+ InitCommonControls();
+
+ VID_InitDIB (global_hInstance);
+ basenummodes = nummodes = 1;
+
+ VID_InitFullDIB (global_hInstance);
+
+ if (!fullscreen)
+ {
+ hdc = GetDC (NULL);
+
+ if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
+ Sys_Error ("Can't run in non-RGB mode");
+
+ ReleaseDC (NULL, hdc);
+
+ windowed = true;
+
+ vid_default = MODE_WINDOWED;
+ }
+ else
+ {
+ if (nummodes == 1)
+ Sys_Error ("No RGB fullscreen modes available");
+
+ windowed = false;
+
+ done = 0;
+
+ bestmode = -1;
+ bestrating = 1000000000;
+ for (i = 0;i < nummodes;i++)
+ {
+ if (fullscreen == modelist[i].fullscreen)
+ {
+ rating = VID_CompareMode(width, height, bpp, modelist[i].width, modelist[i].height, modelist[i].bpp);
+ if (bestrating > rating)
+ {
+ bestrating = rating;
+ bestmode = i;
+ }
+ }
+ }
+
+ if (bestmode < 0)
+ Sys_Error ("Specified video mode not available");
+ }
+
+ vid_initialized = true;
+
+ VID_SetMode (vid_default);
+
+ maindc = GetDC(mainwindow);
+ bSetupPixelFormat(maindc);
+
+ if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
+ Sys_Error("wgl functions not found\n");
+
+ baseRC = qwglCreateContext( maindc );
+ if (!baseRC)
+ Sys_Error ("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.");
+ if (!qwglMakeCurrent( maindc, baseRC ))
+ Sys_Error ("wglMakeCurrent failed");
+
+ gl_renderer = qglGetString(GL_RENDERER);
+ gl_vendor = qglGetString(GL_VENDOR);
+ gl_version = qglGetString(GL_VERSION);
+ gl_extensions = qglGetString(GL_EXTENSIONS);
+ gl_platform = "WGL";
+ gl_platformextensions = "";
+
+ if (GL_CheckExtension("WGL_ARB_extensions_string", getextensionsstringfuncs, NULL, false))
+ gl_platformextensions = qwglGetExtensionsStringARB(maindc);
+
+ gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, NULL, false);
+
+ GL_Init ();
+
+ // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
+ if (strncasecmp(gl_vendor,"ATI",3)==0)
+ {
+ if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
+ isRagePro = true;
+ }
+ if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
+ isG200 = true;
+
+ vid_realmode = vid_modenum;
+
+ vid_menudrawfn = VID_MenuDraw;
+ vid_menukeyfn = VID_MenuKey;
+
+ strcpy (badmode.modedesc, "Bad mode");
+ vid_canalttab = true;
+
+ vid_hidden = false;
+}
+