代码拉取完成,页面将自动刷新
{
GLA中的基本窗口操作函数
}
{$IFDEF GLA_INTERFACE}
{$IFDEF GLA_DEBUG}
{$INFO Compiling gla_base::interface}
{$ENDIF}
const
GLACLASSNAME='GLAWNDCLS';
type
TGLACallback=procedure(wp,lp:DWord);
TGLALess=specialize TLess<DWord>;
TGLACallbackMap=specialize TMap<DWord,TGLACallback,TGLALess>;
TGLACallbackMapIterator=TGLACallbackMap.TIterator;
function glaInit:boolean;
function glaCreateWindow(x,y,w,h:DWord;s:PChar):DWord;
procedure glaBindFunc(msg:DWord;func:TGLACallback);
procedure glaLoop;
procedure glaRedisplay;
procedure glaFlush;
{$ENDIF}
{$IFDEF GLA_IMPLEMENTATION}
{$IFDEF GLA_DEBUG}
{$INFO Compiling gla_base::inplementation}
{$ENDIF}
var
__map:TGLACallbackMap;
__dc,__hw:DWord;
function __WindowProc(wnd,msg,wp,lp:DWord):DWord;stdcall;export;
var
i:TGLACallbackMapIterator;
begin
i:=__map.Find(msg);
if i=NIL then
exit(DefWindowProc(wnd,msg,wp,lp))
else begin
i.Value(wp,lp);
exit(0);
end;
end;
procedure __EnableOpenGL(var hw,dc,rc:DWord);
var
pfd:PIXELFORMATDESCRIPTOR;
iFormat:longint;
begin
dc:=GetDC(hw);
FillChar(pfd,sizeof(pfd),0);
pfd.nSize:=sizeof(pfd);
pfd.nVersion:=1;
pfd.dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
pfd.iPixelType:=PFD_TYPE_RGBA;
pfd.cColorBits:=24;
pfd.cDepthBits:=16;
pfd.iLayerType:=PFD_MAIN_PLANE;
iFormat:=ChoosePixelFormat(dc,pfd);
SetPixelFormat(dc,iFormat,@pfd);
rc:=wglCreateContext(dc);
wglMakeCurrent(dc,rc);
end;
function glaInit:boolean;
var
cls:WNDCLASS;
begin
__map:=TGLACallbackMap.Create;
with cls do begin
Style:=CS_HREDRAW or CS_VREDRAW;
lpfnWndProc:=WndProc(@__WindowProc);
cbClsExtra:=0;
cbWndExtra:=0;
hInstance:=system.MainInstance;
hIcon:=LoadIcon(0,IDI_APPLICATION);
hCursor:=LoadCursor(0,IDC_ARROW);
hbrBackground:=0;
lpszMenuName:=NIL;
lpszClassName:=GLACLASSNAME;
end;
exit(RegisterClass(cls)<>0);
end;
function glaCreateWindow(x,y,w,h:DWord;s:PChar):DWord;
var
hw,dc,rc:DWord;
begin
hw:=CreateWindow(GLACLASSNAME,s,WS_OVERLAPPEDWINDOW,x,y,
w,h,0,0,system.MainInstance,NIL);
__hw:=hw;
if hw<>0 then begin
__EnableOpenGL(hw,dc,rc);
__dc:=dc;
ShowWindow(hw,SW_SHOW);
UpdateWindow(hw);
end;
exit(hw);
end;
procedure glaBindFunc(msg:DWord;func:TGLACallback);
begin
__map.Items[msg]:=func;
end;
procedure glaLoop;
var
amsg:MSG;
begin
glaRedisplay;
while GetMessage(@amsg,0,0,0) do begin
TranslateMessage(amsg);
DispatchMessage(amsg);
end;
end;
procedure glaRedisplay;
begin
InvalidateRect(__hw,NIL,TRUE);
UpdateWindow(__hw);
end;
procedure glaFlush;
begin
SwapBuffers(__dc);
end;
{$ENDIF}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。