It is possible to use OpenGL and VCL/ LCL in the same time. All you need is a VCL control which has a handle. The very simple OpenGL form would look something like this
Code:
TGLForm = class(TForm)
private
FGLRC : HGLRC;
fGLDC : HDC;
fPFD : TPixelFormatDescriptor;
...
public
constructor Create(AOwner : TComponent);
destructor Destroy; override;
procedure InitGL;
...
end;
implementation
constructor TGLForm.Create(AOwner : TComponent);
var
formatIndex : integer;
begin
inherited;
//setup pixel format
with fPFD do begin
nSize := SizeOf(fPFD);
nVersion := 1;
dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
iPixelType := PFD_TYPE_RGBA;
cColorBits := 24; //bits per pixel
cDepthBits := 24; //size of depth buffer
cStencilBits := 8; //size of stencilbuffer
iLayerType := PFD_MAIN_PLANE;
end;
fGLDC := getDC(self.Handle);
FormatIndex := ChoosePixelFormat(fGLDC,@FPFD);
//if FormatIndex = 0 then error
SetPixelFormat(fGLDC,FormatInsex,@fPFD);
//create rendering context;
fGLRC := wglCreateContext(fGLDC);
wglMakeCurrent(fGLDC,fGLRC);
end;
destructor TGLForm.Destroy;
begin
//destroy rendering context;
wglMakeCurrent(fGLDC,0);
wglDeleteContext(fGLRC);
ReleaseDC(self.Handle,fGLDC);
inherited;
end;
procedure TGLForm.InitGL;
begin
glMatrixMode(GL_PROJECTION);
glOrtho(0,ClientWidth,0,ClientHeight,0,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glViewport(0,0,ClientWidth,ClientHeight);
end;
Drawing can be done in TGLForm.OnPaint event.
For more sophisticated example look there:
http://www.delphi3d.net/dot/
Bookmarks