Código:
function CreateRenderingContext(DC: HDC; Options: TRCOptions; ColorDepth: Integer; StencilBits: Byte): HGLRC;
// Set the OpenGL properties required to draw to the given canvas and
// create a rendering context for it.
var PFDescriptor : TPixelFormatDescriptor;
PixelFormat : Integer;
begin
FillChar(PFDescriptor,SizeOf(PFDescriptor),0);
with PFDescriptor do
begin
nSize:=sizeof(PFDescriptor);
nVersion:=1;
dwFlags:=PFD_SUPPORT_OPENGL;
if GetObjectType(DC) in [OBJ_MEMDC,OBJ_METADC,OBJ_ENHMETADC]
then dwFlags:=dwFlags or PFD_DRAW_TO_BITMAP
else dwFlags:=dwFlags or PFD_DRAW_TO_WINDOW;
if opDoubleBuffered in Options then dwFlags:=dwFlags or PFD_DOUBLEBUFFER;
if opGDI in Options then dwFlags:=dwFlags or PFD_SUPPORT_GDI;
if opStereo in Options then dwFlags:=dwFlags or PFD_STEREO;
iPixelType:=PFD_TYPE_RGBA;
cColorBits:=ColorDepth;
cDepthBits:=32;
cStencilBits:=StencilBits;
iLayerType:=Byte(PFD_MAIN_PLANE);
end;
InitOpenGL; // just in case it didn't happen already
PixelFormat:=ChoosePixelFormat(DC,@PFDescriptor);
SetPixelFormat(DC,PixelFormat,@PFDescriptor);
// check the properties just set
DescribePixelFormat(DC,PixelFormat,SizeOf(PFDescriptor),@PFDescriptor);
with PFDescriptor do
if (dwFlags and PFD_NEED_PALETTE) <> 0 then SetupPalette(DC,PFDescriptor);
Result:=wglCreateContext(DC);
// read implementation properties
if FirstContext and (Result > 0) then
begin
wglMakeCurrent(DC,Result);
ReadImplementationProperties;
FirstContext:=False;
wglMakeCurrent(0,0);
end;
end;
Si quieres bajarte la Unit completa la tienes en la DelphiSuperpage.
Un Saludo.