Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup OpenGL1.4 environment in Firemonkey App?

In older days I would create a TForm, place a TMyPanel on it (with overriden WM_PAINT message) and pass its Handle to a bunch of WGL functions that find a compatible pixelformat and create rendering context. Just like NeHe tutorials did it.

Now there comes FireMonkey application. How to get OpenGL 1.4 rendering context there that is working on Win and iOS?

EDIT: Been trying to make it to work by passing TForm.Handle (which is NativeUInt). Good news - no errors from OpenGL end, but bad news - no output on TForm either.. I'm obviously missing some critical piece here, does anyone has a working OpenGL in FireMonkey application?

like image 517
Kromster Avatar asked Oct 12 '11 18:10

Kromster


2 Answers

Firemonkey provides an abstraction layer.

So on Windows your using DirectX and on OSX and iOS your using OpenGL/Quartz. On windows it's also possible for things to fall back to GDI+

Given this one must take into account that the rendering destination may not always be OpenGL, and it may not always be the same even on the same platform.

TCanvas in part of this abstraction layer.

There are 3 current implementations of TCanvas, your application may be using any of these.

  • FMX.Canvas.D2D.pas - Direct2d
  • FMX.Canvas.GDIP.pas - GDI+
  • FMX.Canvas.Mac.pas - Mac

The platform implementation details are typically hidden in private sections are are not accessible.

You also have TPlatform in FMX.Platform.pas which hides the implementation details and publishes a single API (limited in scope) that is designed to work on all platforms.

If you use FMX.Platform.Win.pas you can get the windows handle for a given TFmxHandle

If you use FMX.Platform.Mac.pas you can get the IObjectiveC for a given TFmxHandle

However on IOS there is no equivalent function in FMX_Platform_iOS.pas

like image 131
Robert Love Avatar answered Oct 20 '22 02:10

Robert Love


After some investigations I have managed to create OpenGL context in FireMonkey on Windows platform. I don't have access to iOS yet, but I'm sure something can be done there as well.

To the solution: add FMX.Platform.Win to uses clause (might need to wrap it into IFDEF's for iOS). Now we can use FmxHandleToHWND(Form1.Handle) to get valid HWND. Thats it. On MacOS the same is done by adding FMX.Platform.Win and through H_WND := FmxHandleToObjC(AHandle); call.

like image 28
Kromster Avatar answered Oct 20 '22 02:10

Kromster