📄 glw_imp.pas
字号:
procedure GLimp_Shutdown;
begin
if (Assigned(qwglMakeCurrent) and (not qwglMakeCurrent(0, 0))) then
ri.Con_Printf(PRINT_ALL, 'ref_gl::R_Shutdown() - wglMakeCurrent failed'#10);
if (glw_state. {h} GLRC <> 0) then
begin
if (Assigned(qwglDeleteContext) and (not qwglDeleteContext(glw_state. {h} GLRC))) then
ri.Con_Printf(PRINT_ALL, 'ref_gl::R_Shutdown() - wglDeleteContext failed'#10);
glw_state. {h} GLRC := 0;
end;
if (glw_state. {h} DC <> 0) then
begin
if (ReleaseDC(glw_state. {h} Wnd, glw_state. {h} DC) = 0) then
ri.Con_Printf(PRINT_ALL, 'ref_gl::R_Shutdown() - ReleaseDC failed'#10, []); //Y:
glw_state. {h} DC := 0;
end;
if (glw_state. {h} Wnd <> 0) then
begin
DestroyWindow(glw_state. {h} Wnd);
glw_state. {h} Wnd := 0;
end;
{ if ( glw_state.log_fp ) then
begin
fclose( glw_state.log_fp );
glw_state.log_fp := 0;
end;}
if (TTextRec(glw_state.log_fp).Mode <> fmClosed) and
(TTextRec(glw_state.log_fp).Name <> '') then
CloseFile(glw_state.log_fp);
UnregisterClass(WINDOW_CLASS_NAME, glw_state.hInstance);
if (gl_state.fullscreen) then
begin
//Y: ChangeDisplaySettings (0, 0);
ChangeDisplaySettings(devmode(nil^), 0);
gl_state.fullscreen := false;
end;
end; //procedure
{*
** GLimp_Init
**
** This routine is responsible for initializing the OS specific portions
** of OpenGL. Under Win32 this means dealing with the pixelformats and
** doing the wgl interface stuff.
*}
//function GLimp_Init (void *hinstance, void *wndproc) : qboolean;
function GLimp_Init(hinstance: HINST; wndproc: pointer): qboolean; //add info: glw_win.inc: glwstate_t
const
OSR2_BUILD_NUMBER = 1111;
var
vinfo: OSVERSIONINFO;
begin
vinfo.dwOSVersionInfoSize := sizeof(vinfo);
glw_state.allowdisplaydepthchange := false;
if (GetVersionEx({&} vinfo)) then
begin
if (vinfo.dwMajorVersion > 4) then
glw_state.allowdisplaydepthchange := true
else
if (vinfo.dwMajorVersion = 4) then
if (vinfo.dwPlatformId = VER_PLATFORM_WIN32_NT) then
glw_state.allowdisplaydepthchange := true
else
if (vinfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS) then
if (LOWORD(vinfo.dwBuildNumber) >= OSR2_BUILD_NUMBER) then
glw_state.allowdisplaydepthchange := true;
end
else
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - GetVersionEx failed'#10, []); //Y:
Result := false;
Exit;
end;
glw_state.hInstance := {( HINSTANCE )} hinstance;
glw_state.wndproc := wndproc;
Result := true;
end; //function
function GLimp_InitGL: qboolean; //only imp
var
pfd: TPIXELFORMATDESCRIPTOR;
(* PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};*)
pixelformat: integer;
stereo: cvar_p;
label
fail;
begin
with pfd do
begin
nSize := sizeof(PIXELFORMATDESCRIPTOR); // size of this pfd
nVersion := 1; // version number
dwFlags := PFD_DRAW_TO_WINDOW or // support window
PFD_SUPPORT_OPENGL or // support OpenGL
PFD_DOUBLEBUFFER; // double buffered
iPixelType := PFD_TYPE_RGBA; // RGBA type
cColorBits := 24; // 24-bit color depth
cRedBits := 0; // color bits ignored
cRedShift := 0;
cGreenBits := 0;
cGreenShift := 0;
cBlueBits := 0;
cBlueShift := 0;
cAlphaBits := 0; // no alpha buffer
cAlphaShift := 0; // shift bit ignored
cAccumBits := 0; // no accumulation buffer
cAccumRedBits := 0; // accum bits ignored
cAccumGreenBits := 0;
cAccumBlueBits := 0;
cAccumAlphaBits := 0;
cDepthBits := 32; // 32-bit z-buffer
cStencilBits := 0; // no stencil buffer
cAuxBuffers := 0; // no auxiliary buffer
iLayerType := PFD_MAIN_PLANE; // main layer
bReserved := 0; // reserved
dwLayerMask := 0; // layer masks ignored
dwVisibleMask := 0;
dwDamageMask := 0;
end;
stereo := ri.Cvar_Get('cl_stereo', '0', 0);
{*
** set PFD_STEREO if necessary
*}
if (stereo.value <> 0) then
begin
ri.Con_Printf(PRINT_ALL, '...attempting to use stereo'#10);
pfd.dwFlags := pfd.dwFlags or PFD_STEREO;
gl_state.stereo_enabled := true;
end
else
gl_state.stereo_enabled := false;
{*
** figure out if we're running on a minidriver or not
*}
if (strstr(gl_driver.string_, 'opengl32') <> nil) then
glw_state.minidriver := false
else
glw_state.minidriver := true;
{*
** Get a DC for the specified window
*}
if (glw_state. {h} DC <> 0) then
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - non-NULL DC exists'#10);
// if ( ( glw_state.hDC = GetDC( glw_state.hWnd ) ) == NULL ) then
glw_state. {h} DC := GetDC(glw_state. {h} Wnd);
if (glw_state. {h} DC = 0) then
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - GetDC failed'#10, []); //Y:
Result := false;
Exit;
end;
if (glw_state.minidriver) then
begin
pixelformat := qwglChoosePixelFormat(glw_state. {h} DC, {&}@pfd);
if (pixelformat = 0) then
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - qwglChoosePixelFormat failed'#10, []); //Y:
Result := false;
Exit;
end;
if (qwglSetPixelFormat(glw_state. {h} DC, pixelformat, {&}@pfd) = FALSE) then
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - qwglSetPixelFormat failed'#10, []); //Y
Result := false;
Exit;
end;
qwglDescribePixelFormat(glw_state. {h} DC, pixelformat, sizeof(pfd), {&} pfd);
end
else
begin
pixelformat := ChoosePixelFormat(glw_state. {h} DC, {&}@pfd);
if (pixelformat = 0) then
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - ChoosePixelFormat failed'#10, []); //Y:
Result := false;
Exit;
end;
if (SetPixelFormat(glw_state. {h} DC, pixelformat, {&}@pfd) = FALSE) then
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - SetPixelFormat failed'#10, []); //Y:
Result := false;
Exit;
end;
DescribePixelFormat(glw_state. {h} DC, pixelformat, sizeof(pfd), {&} pfd);
if ((pfd.dwFlags and PFD_GENERIC_ACCELERATED) = 0) then
begin
if (gl_allow_software.value <> 0) then
glw_state.mcd_accelerated := true
else
glw_state.mcd_accelerated := false;
glw_state.mcd_accelerated := (gl_allow_software.value <> 0);
end
else
glw_state.mcd_accelerated := true;
end;
{*
** report if stereo is desired but unavailable
*}
if ((pfd.dwFlags and PFD_STEREO) = 0) and (stereo.value <> 0) then
begin
ri.Con_Printf(PRINT_ALL, '...failed to select stereo pixel format'#10, []); //Y:
ri.Cvar_SetValue('cl_stereo', 0);
gl_state.stereo_enabled := false;
end;
{*
** startup the OpenGL subsystem by creating a context and making
** it current
*}
glw_state. {h} GLRC := qwglCreateContext(glw_state. {h} DC);
if (glw_state. {h} GLRC = 0) then
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - qwglCreateContext failed'#10, []); //Y:
goto fail;
end;
if not qwglMakeCurrent(glw_state. {h} DC, glw_state. {h} GLRC) then
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - qwglMakeCurrent failed'#10, []); //Y:
goto fail;
end;
if not VerifyDriver() then
begin
ri.Con_Printf(PRINT_ALL, 'GLimp_Init() - no hardware acceleration detected'#10, []); //Y:
goto fail;
end;
{*
** print out PFD specifics
*}
ri.Con_Printf(PRINT_ALL, 'GL PFD: color(%d-bits) Z(%d-bit)'#10, Trunc(pfd.cColorBits), Trunc(pfd.cDepthBits)); //Y:
Result := true;
Exit;
fail:
if (glw_state. {h} GLRC <> 0) then
begin
qwglDeleteContext(glw_state. {h} GLRC);
glw_state. {h} GLRC := 0;
end;
if (glw_state. {h} DC <> 0) then
begin
ReleaseDC(glw_state. {h} Wnd, glw_state. {h} DC);
glw_state. {h} DC := 0;
end;
Result := false;
end;
{*
** GLimp_BeginFrame
*}
procedure GLimp_BeginFrame(camera_separation: Single);
begin
if (gl_bitdepth.modified) then
begin
if (gl_bitdepth.value <> 0) and (not glw_state.allowdisplaydepthchange) then
begin
ri.Cvar_SetValue('gl_bitdepth', 0);
ri.Con_Printf(PRINT_ALL, 'gl_bitdepth requires Win95 OSR2.x or WinNT 4.x'#10, []); //Y:
end;
gl_bitdepth.modified := false;
end;
if (camera_separation < 0) and (gl_state.stereo_enabled) then
qglDrawBuffer(GL_BACK_LEFT)
else
if (camera_separation > 0) and (gl_state.stereo_enabled) then
qglDrawBuffer(GL_BACK_RIGHT)
else
qglDrawBuffer(GL_BACK);
end;
{*
** GLimp_EndFrame
**
** Responsible for doing a swapbuffers and possibly for other stuff
** as yet to be determined. Probably better not to make this a GLimp
** function and instead do a call to GLimp_SwapBuffers.
*}
procedure GLimp_EndFrame; cdecl;
var
err: integer;
begin
err := qglGetError();
assert(err = GL_NO_ERROR);
if (strcmp(gl_drawbuffer^.string_, 'GL_BACK') = 0) then
if not qwglSwapBuffers(glw_state. {h} DC) then
ri.Sys_Error(ERR_FATAL, 'GLimp_EndFrame() - SwapBuffers() failed!'#10, []);
end;
{*
** GLimp_AppActivate
*}
procedure GLimp_AppActivate(active: qboolean);
begin
if (active) then
begin
SetForegroundWindow(glw_state. {h} Wnd);
ShowWindow(glw_state. {h} Wnd, SW_RESTORE);
end
else
if (vid_fullscreen^.value <> 0) then
ShowWindow(glw_state. {h} Wnd, SW_MINIMIZE);
end;
end.
My current problems:
- - - - - - - - - - - - - - - - - - - -
1)C - code:
if (strstr(gl_driver.string, 'opengl32')! = 0)
PAS:
if Pos('opengl32', gl_driver.string) > 0 then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -