Evo kako ja radim:
Code:
procedure SetupGLWindow(AWindow: TWinControl);
var
DC:HDC;
RC:HGLRC;
begin
DC:=GetDC(AWindow.Handle);
SetupPixelFormat(DC);
RC:=wglCreateContext(DC);
wglMakeCurrent(DC, RC);
end;
procedure SetupPixelFormat(DC:HDC);
const
pfd:TPIXELFORMATDESCRIPTOR = (
nSize:sizeof(TPIXELFORMATDESCRIPTOR); // size
nVersion:1; // version
dwFlags:PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER;
// support double-buffering
iPixelType:PFD_TYPE_RGBA; // color type
cColorBits:24; // prefered color depth
cRedBits:0;
cRedShift:0; // color bits (ignored)
cGreenBits:0;
cGreenShift:0;
cBlueBits:0;
cBlueShift:0;
cAlphaBits:0;
cAlphaShift:0; // no alpha buffer
cAccumBits: 0;
cAccumRedBits: 0; // no accumulation buffer,
cAccumGreenBits: 0; // accum bits (ignored)
cAccumBlueBits: 0;
cAccumAlphaBits: 0;
cDepthBits:24; // depth buffer
cStencilBits:0; // no stencil buffer
cAuxBuffers:0; // no auxiliary buffers
iLayerType:PFD_MAIN_PLANE; // main layer
bReserved: 0;
dwLayerMask: 0;
dwVisibleMask: 0;
dwDamageMask: 0; // no layer, visible, damage masks */
);
var pixelFormat:integer;
begin
pixelFormat := ChoosePixelFormat(DC, @pfd);
if (pixelFormat = 0) then begin
MessageBox(WindowFromDC(DC), 'ChoosePixelFormat failed.', 'Error',
MB_ICONERROR or MB_OK);
exit;
end;
if (SetPixelFormat(DC, pixelFormat, @pfd) <> TRUE) then begin
MessageBox(WindowFromDC(DC), 'SetPixelFormat failed.', 'Error',
MB_ICONERROR or MB_OK);
exit;
end;
end;
i kod kreiranja forme pozoves
SetupGLWindow(Panel1);