PDA

View Full Version : OpenGL and Delphi Problem



hermes
09-19-2000, 08:48 AM
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.

SEB
09-22-2000, 05:53 AM
Hi,

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

Seb.

JohnHutch
09-24-2000, 01:16 PM
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.

hermes
09-25-2000, 02:44 AM
Here is my Constructor and stuff for my component:
constructor TGLImage.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

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

DC := Picture.Bitmap.Canvas.Handle;
CreateRC;

end;

procedure TGLImage.CreateRC;
var
PFD: TPixelFormatDescriptor;
PFI: Integer; { PixelFormatIndex }
NewRC: HGLRC;
begin
FillChar(PFD, SizeOf(PFD), 0);
with PFD do
begin
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
end;
PFI := ChoosePixelFormat(DC, @PFD);
SetPixelFormat(DC, PFI, @PFD);
NewRC := wglCreateContext(DC);
if NewRC = 0 then
raise Exception.Create('Invalid rendering context value');
RC := NewRC;
end;
destructor TGLImage.Destroy;
begin
wglDeleteContext(RC);
inherited Destroy;
end;

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

hermes
09-25-2000, 05:44 AM
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

hermes
09-25-2000, 09:32 AM
thank you for your help. I combined both your solutions and figured out the other part on my own

Thanks again