[fpc-pascal] dglOpenGL <-> GL, GLu, GLExt
Juha Manninen
juha.manninen62 at gmail.com
Sat Feb 23 14:45:46 CET 2013
On Sun, Feb 17, 2013 at 11:12 PM, Marco van de Voort <marcov at stack.nl> wrote:
>> Q: how am I supposed to initialize OpenGL when using units provided by FPC?
>
> The unit does it at startup. That has as disadvantage that the filename
> can't be changed (or at least that first try can't be avoided).
>
> After that, you iirc need to do load<something with glversion> from unit
> glext to load the extensions for later versions.
Thanks Marco.
I didn't quite understand what is load<something with glversion>.
My experiments advance slowly. The original DeleD code validate OpenGL
by checking if
@glActiveTextureARB, @glClientActiveTextureARB and @glMultiTexCoord2fARB
are assigned.
With dglopengl it stops working when I replace
H_RC := wglCreateContext(H_DC);
with the cross-platform OpenGLContext:
fOpenGLControl1:=TOpenGLControl.Create(Self);
and replace
wglMakeCurrent(H_DC, H_RC);
with
OpenGLControl1.MakeCurrent;
When using GLExt (provided by FPC), the test still fails but then I
can remove it and the code does not crash later.
So, maybe it is better to use GL and GLExt.
If I put the same test in the OpenGlControl demo in Lazarus, it does
not fail! I don't see what makes the difference.
Cross-platform OpenGL still does not work though. Deled 3-D uses form
inheritance and all forms needing OpenGL drawing window inherit from
TOGLForm. I copy below the Create method where I had to comment out
most code to make it compile.
I create fOpenGLControl1 the same way than in the Lazarus example, but
I don't know what to put into the OnPaint and OnResize event handlers.
Now the code does not crash but obviously does not draw anything either.
I guess I must study the topic more. I will commit my code to the
DeleD SVN branch although it is broken. Maybe someone could have a
look at it.
Regards,
Juha
----------------------------
constructor TOGLForm.Create(AOwner: TComponent);
//var PixelFormat: Integer;
// our windows pixel format
// PFD: PixelFormatDescriptor;
// describes the pixel format
begin
inherited;
Initialize;
Set8087CW($133f); // disable fpu exceptions when doing OpenGL rendering
//ZeroMemory(@PFD, SizeOf(PFD));
// describe our Pixel Format Descriptor
//with PFD do begin
// nSize := SizeOf(PFD);
// nVersion := 1;
// dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or
PFD_DOUBLEBUFFER or 0;
// iPixelType := PFD_TYPE_RGBA;
// cColorBits := 16;
// cDepthBits := 16;
//end;
// now set pixel format + initialize rendering context
//H_DC := Canvas.Handle;
//PixelFormat := ChoosePixelFormat(H_DC, @PFD);
// choose a pixel format based on our description
//if PixelFormat = 0 then begin
// KillWindow;
// MessageBox(0, 'Unable to choose pixel format', 'Error',
MB_OK or MB_ICONERROR);
// Exit;
//end;
//if not SetPixelFormat(H_DC, PixelFormat, @PFD) then begin
// attach the pixel format to the window
// KillWindow;
// MessageBox(0, 'Unable to set pixel format', 'Error', MB_OK
or MB_ICONERROR);
// Exit;
//end;
//H_RC := wglCreateContext(H_DC);
// get the rendering context handle
//if H_RC = 0 then begin
// KillWindow;
// MessageBox(0, 'Unable to create rendering context', 'Error',
MB_OK or MB_ICONERROR);
// Exit;
//end;
//ActivateRenderingContext(H_DC,H_RC);
fOpenGLControl1:=TOpenGLControl.Create(Self);
with fOpenGLControl1 do begin
Name:='OpenGLControl1';
Parent:=Self;
SetBounds(10,90,380,200);
//OnPaint:=@OpenGLControl1Paint;
//OnResize:=@OpenGLControl1Resize;
end;
if not fOpenGLControl1.MakeCurrent then begin
// initialize the endering context
KillWindow;
MessageBox(0, 'Unable to activate rendering context', 'Error',
MB_OK or MB_ICONERROR);
Exit;
end;
end;
More information about the fpc-pascal
mailing list