OpenGL and Delphi Problem

I have just gotten into programing openGL in Delphi and when I run the application it says that it has performed too many consecutive access violations. here’s what I’m doing:

I have a TImage which I setup its bitmap to be my RC, do the openGL, display the bitmap and then Destroy the RC. I have a timer going to make a simple tetrahedron rotate (it goes through the entire process again)and after a while it comes up with that error message – too many consecutive access violations.

Does anyone have any ideas on what’s happening and how to fix it.


Try with the handle of TPanel in place of the bitmap of TImage


Hold on to the RC and the DC (Canvas handle) for the “life” of the TImage (or TPanel). Make sure the DC has the correct pixel format etc.

Here is my Constructor and stuff for my component:
constructor TGLImage.Create(AOwner: TComponent);
inherited Create(AOwner);

Picture.Bitmap.PixelFormat := pf24Bit;
Picture.Bitmap.Width := Width;
Picture.Bitmap.Height := Height;

DC := Picture.Bitmap.Canvas.Handle;


procedure TGLImage.CreateRC;
PFD: TPixelFormatDescriptor;
PFI: Integer; { PixelFormatIndex }
FillChar(PFD, SizeOf(PFD), 0);
with PFD do
nSize := SizeOf(PFD); // Size of this structure
nVersion := 1; // Version of this structure
dwFlags := PFD_SUPPORT_OPENGL; // Support OpenGL calls
dwFlags := dwFlags or PFD_DRAW_TO_BITMAP; // Draw into a bitmap
iPixelType := PFD_TYPE_RGBA; // RGBA color mode
cColorBits := 24;
cDepthBits := 24; // Size of depth buffer
iLayerType := PFD_MAIN_PLANE; // Draw in main plane
PFI := ChoosePixelFormat(DC, @PFD);
SetPixelFormat(DC, PFI, @PFD);
NewRC := wglCreateContext(DC);
if NewRC = 0 then
raise Exception.Create(‘Invalid rendering context value’);
RC := NewRC;
destructor TGLImage.Destroy;
inherited Destroy;

When I created the RC in the constructor nothing got drawn. Any Ideas on how to fix up my code?

I am having trouble making the TPanel. When I set my DC to the handle of the Panel and call createDC it gives me an invalid context

Could you please provide me with a little more info on how to do this

thank you for your help. I combined both your solutions and figured out the other part on my own

Thanks again