5.9 Now we need the GL initiation split into 2 pieces, the part that needs done once vs. the setup that needs to occur duriing any video mode switch.
So the Locate GL_Init, Find this and ....
Code: Select all
/*
===============
GL_Init
===============
*/
void GL_Init (void)
{
gl_vendor = glGetString (GL_VENDOR);
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = glGetString (GL_RENDERER);
Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
gl_version = glGetString (GL_VERSION);
Con_Printf ("GL_VERSION: %s\n", gl_version);
gl_extensions = glGetString (GL_EXTENSIONS);
Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
// Con_Printf ("%s %s\n", gl_renderer, gl_version);
if (strnicmp(gl_renderer,"PowerVR",7)==0)
fullsbardraw = true;
if (strnicmp(gl_renderer,"Permedia",8)==0)
isPermedia = true;
CheckTextureExtensions ();
CheckMultiTextureExtensions ();
glClearColor (1,0,0,0);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.666);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glShadeModel (GL_FLAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#if 0
CheckArrayExtensions ();
glEnable (GL_VERTEX_ARRAY_EXT);
glEnable (GL_TEXTURE_COORD_ARRAY_EXT);
glVertexPointerEXT (3, GL_FLOAT, 0, 0, &glv.x);
glTexCoordPointerEXT (2, GL_FLOAT, 0, 0, &glv.s);
glColorPointerEXT (3, GL_FLOAT, 0, 0, &glv.r);
#endif
}
And replace with this:
Code: Select all
/*
===============
GL_SetupState -- johnfitz
does all the stuff from GL_Init that needs to be done every time a new GL render context is created
GL_Init will still do the stuff that only needs to be done once
===============
*/
void GL_SetupState (void) {
glClearColor (1,0,0,0);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.666);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glShadeModel (GL_FLAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
/*
===============
GL_Init
===============
*/
void GL_Init (void)
{
gl_vendor = glGetString (GL_VENDOR);
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = glGetString (GL_RENDERER);
Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
gl_version = glGetString (GL_VERSION);
Con_Printf ("GL_VERSION: %s\n", gl_version);
gl_extensions = glGetString (GL_EXTENSIONS);
Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
// Con_Printf ("%s %s\n", gl_renderer, gl_version);
if (strnicmp(gl_renderer,"PowerVR",7)==0)
fullsbardraw = true;
if (strnicmp(gl_renderer,"Permedia",8)==0)
isPermedia = true;
CheckTextureExtensions ();
CheckMultiTextureExtensions ();
#if 0
CheckArrayExtensions ();
glEnable (GL_VERTEX_ARRAY_EXT);
glEnable (GL_TEXTURE_COORD_ARRAY_EXT);
glVertexPointerEXT (3, GL_FLOAT, 0, 0, &glv.x);
glTexCoordPointerEXT (2, GL_FLOAT, 0, 0, &glv.s);
glColorPointerEXT (3, GL_FLOAT, 0, 0, &glv.r);
#endif
GL_SetupState (); //johnfitz
}
5.10 Find VID_InitDIB and add or match with the yellow:
void VID_InitDIB (HINSTANCE hInstance)
{
DEVMODE devmode; //johnfitz
WNDCLASS wc;
HDC hdc;
int i;
/* Register the frame class */
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = LoadCursor (NULL,IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = 0;
wc.lpszClassName = "WinQuake";
if (!RegisterClass (&wc) )
Sys_Error ("Couldn't register window class");
modelist[0].type = MS_WINDOWED;
if (COM_CheckParm("-width"))
modelist[0].width = Q_atoi(com_argv[COM_CheckParm("-width")+1]);
else
modelist[0].width = 640;
if (modelist[0].width < 320)
modelist[0].width = 320;
if (COM_CheckParm("-height"))
modelist[0].height= Q_atoi(com_argv[COM_CheckParm("-height")+1]);
else
modelist[0].height = modelist[0].width * 240/320;
if (modelist[0].height < 200) //johnfitz -- was 240
modelist[0].height = 200; //johnfitz -- was 240
//johnfitz -- get desktop bit depth
hdc = GetDC(NULL);
modelist[0].bpp = desktop_bpp = GetDeviceCaps(hdc, BITSPIXEL);
ReleaseDC(NULL, hdc);
//johnfitz
//johnfitz -- get refreshrate
if (EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &devmode))
modelist[0].refreshrate = devmode.dmDisplayFrequency;
//johnfitz
sprintf (modelist[0].modedesc, "%dx%dx%d %dHz", //johnfitz -- added bpp, refreshrate
modelist[0].width,
modelist[0].height,
modelist[0].bpp, //johnfitz -- added bpp
modelist[0].refreshrate); //johnfitz -- added refreshrate
modelist[0].modenum = MODE_WINDOWED;
modelist[0].dib = 1;
modelist[0].fullscreen = 0;
modelist[0].halfscreen = 0;
// modelist[0].bpp = 0; // Baker says <--- no! Keep same bpp!
nummodes = 1;
}
5.11 In "VID_InitFullDIB" add or change to the yellow:
This is to support our refreshrate hz.
/*
=================
VID_InitFullDIB
=================
*/
void VID_InitFullDIB (HINSTANCE hInstance)
{
DEVMODE devmode;
int i, modenum, cmodes, originalnummodes, existingmode, numlowresmodes;
int j, bpp, done;
BOOL stat;
// enumerate >8 bpp modes
originalnummodes = nummodes;
modenum = 0;
do
{
stat = EnumDisplaySettings (NULL, modenum, &devmode);
if ((devmode.dmBitsPerPel >= 15) &&
(devmode.dmPelsWidth <= MAXWIDTH) &&
(devmode.dmPelsHeight <= MAXHEIGHT) &&
(nummodes < MAX_MODE_LIST))
{
devmode.dmFields = DM_BITSPERPEL |
DM_PELSWIDTH |
DM_PELSHEIGHT |
DM_DISPLAYFREQUENCY; //johnfitz -- refreshrate
if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) ==
DISP_CHANGE_SUCCESSFUL)
{
modelist[nummodes].type = MS_FULLDIB;
modelist[nummodes].width = devmode.dmPelsWidth;
modelist[nummodes].height = devmode.dmPelsHeight;
modelist[nummodes].modenum = 0;
modelist[nummodes].halfscreen = 0;
modelist[nummodes].dib = 1;
modelist[nummodes].fullscreen = 1;
modelist[nummodes].bpp = devmode.dmBitsPerPel;
modelist[nummodes].refreshrate = devmode.dmDisplayFrequency; //johnfitz -- refreshrate
sprintf (modelist[nummodes].modedesc, "%dx%dx%d %dHz", //johnfitz -- refreshrate
devmode.dmPelsWidth,
devmode.dmPelsHeight,
devmode.dmBitsPerPel,
devmode.dmDisplayFrequency); //johnfitz -- refreshrate
// if the width is more than twice the height, reduce it by half because this
// is probably a dual-screen monitor
if (!COM_CheckParm("-noadjustaspect"))
{
if (modelist[nummodes].width > (modelist[nummodes].height << 1))
{
modelist[nummodes].width >>= 1;
modelist[nummodes].halfscreen = 1;
sprintf (modelist[nummodes].modedesc, "%dx%dx%d %dHz", //johnfitz -- refreshrate
modelist[nummodes].width,
modelist[nummodes].height,
modelist[nummodes].bpp,
modelist[nummodes].refreshrate); //johnfitz -- refreshrate
}
}
for (i=originalnummodes, existingmode = 0 ; i<nummodes ; i++)
{
if ((modelist[nummodes].width == modelist.width) &&
(modelist[nummodes].height == modelist.height) &&
(modelist[nummodes].bpp == modelist.bpp) &&
(modelist[nummodes].refreshrate == modelist.refreshrate)) //johnfitz -- refreshrate
{
existingmode = 1;
break;
}
}
if (!existingmode)
{
nummodes++;
}
}
}
modenum++;
} while (stat);
// see if there are any low-res modes that aren't being reported
numlowresmodes = sizeof(lowresmodes) / sizeof(lowresmodes[0]);
bpp = 16;
done = 0;
do
{
for (j=0 ; (j<numlowresmodes) && (nummodes < MAX_MODE_LIST) ; j++)
{
devmode.dmBitsPerPel = bpp;
devmode.dmPelsWidth = lowresmodes[j].width;
devmode.dmPelsHeight = lowresmodes[j].height;
devmode.dmFields = DM_BITSPERPEL |
DM_PELSWIDTH |
DM_PELSHEIGHT |
DM_DISPLAYFREQUENCY; //johnfitz -- refreshrate;
if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) ==
DISP_CHANGE_SUCCESSFUL)
{
modelist[nummodes].type = MS_FULLDIB;
modelist[nummodes].width = devmode.dmPelsWidth;
modelist[nummodes].height = devmode.dmPelsHeight;
modelist[nummodes].modenum = 0;
modelist[nummodes].halfscreen = 0;
modelist[nummodes].dib = 1;
modelist[nummodes].fullscreen = 1;
modelist[nummodes].bpp = devmode.dmBitsPerPel;
modelist[nummodes].refreshrate = devmode.dmDisplayFrequency; //johnfitz -- refreshrate
sprintf (modelist[nummodes].modedesc, "%dx%dx%d %dHz", //johnfitz -- refreshrate
devmode.dmPelsWidth,
devmode.dmPelsHeight,
devmode.dmBitsPerPel,
devmode.dmDisplayFrequency); //johnfitz -- refreshrate
for (i=originalnummodes, existingmode = 0 ; i<nummodes ; i++)
{
if ((modelist[nummodes].width == modelist.width) &&
(modelist[nummodes].height == modelist.height) &&
(modelist[nummodes].bpp == modelist.bpp) &&
(modelist[nummodes].refreshrate == modelist.refreshrate)) //johnfitz -- refreshrate
{
existingmode = 1;
break;
}
}
if (!existingmode)
{
nummodes++;
}
}
}
switch (bpp)
{
case 16:
bpp = 32;
break;
case 32:
bpp = 24;
break;
case 24:
done = 1;
break;
}
} while (!done);
if (nummodes == originalnummodes)
Con_SafePrintf ("No fullscreen DIB modes found\n");
}