Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Opengl & FMX


This question is not answered. Helpful answers available: 0. Correct answers available: 1.


Permlink Replies: 15 - Last Post: Apr 11, 2017 2:34 AM Last Post By: Stelios Antoniou
Stelios Antoniou

Posts: 16
Registered: 5/13/06
Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 27, 2017 6:03 AM
Hello!

I am trying to convert my VCL program in FMX. It uses many of the OpenGL functions.
After research I found an example with a cubeman written for cross-platform : [https://forums.embarcadero.com/thread.jspa?messageID=705080&#705080]
Inside the code a class is created (TGLContext which hosts any opengl function)

Is there any way to create a visual component (in our case the tglcontext) so as to use it in forms and call opengl functions?
I tried to change the type of the class for TGLContext as TViewport3D but as it was expected , it could not appear any of the things I created with opengl functions.
Also I tested with TControl3D and TStyledControl but even if compiling & installing the package was successful , tool palette did not include it.

Any ideas?
Paul TOTH

Posts: 196
Registered: 1/2/17
Re: Opengl & FMX
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 27, 2017 6:34 AM   in response to: Stelios Antoniou in response to: Stelios Antoniou
Le 27/03/2017 à 15:03, Stelios Antoniou a écrit :
Hello!

I am trying to convert my VCL program in FMX. It uses many of the OpenGL functions.
After research I found an example with a cubeman written for cross-platform : [https://forums.embarcadero.com/thread.jspa?messageID=705080&#705080]
Inside the code a class is created (TGLContext which hosts any opengl function)

Is there any way to create a visual component (in our case the tglcontext) so as to use it in forms and call opengl functions?
I tried to change the type of the class for TGLContext as TViewport3D but as it was expected , it could not appear any of the things I created with opengl functions.
Also I tested with TControl3D and TStyledControl but even if compiling & installing the package was successful , tool palette did not include it.

Any ideas?

My demo do not use FMX at all.

Under Windows, FMX uses DirectX, not OpenGL...but it should be possible
to create a native control with an OpenGL context...I just don't know how :D
Stelios Antoniou

Posts: 16
Registered: 5/13/06
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 27, 2017 7:08 AM   in response to: Paul TOTH in response to: Paul TOTH
Thank you Paul for highlighting this.
Even if its not what I wanted to hear, its useful :)

Under those circumstances, I just started creating a package from scratch.
But I think I still need help for the way...
Stelios Antoniou

Posts: 16
Registered: 5/13/06
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 8:08 AM   in response to: Eli M in response to: Eli M
Thank you eli!

Your answer was very helpful.

I started creating mine component which inherits from class (TControl).
It was the only solution so as my component to be registered.

Bad news though : when I drag my new component from the tool palette , Delphi crashes! :o and I cannot find an easy way to debug it before installing it.
Stelios Antoniou

Posts: 16
Registered: 5/13/06
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 31, 2017 6:04 AM   in response to: Stelios Antoniou in response to: Stelios Antoniou
Hello !
As a sequel of my question and after the comments I received above,I started creating a new component :
TGLViewport = class (TControl)
which includes another class
Draw3D: TContext3D //lets say this is our opengl canvas

After I implemented all my functions & procedures that use opengl functions, I compiled it successfuly and new component registered with success.

The problem is that when I start a new multi-device application , I drag the component from the tool palette and suddenly delphi crashes!
A pop up window appears which informs me that software is not responding and the only solution is to close it.

can anyone help me with this?

Paul TOTH

Posts: 196
Registered: 1/2/17
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 31, 2017 6:18 AM   in response to: Stelios Antoniou in response to: Stelios Antoniou
Le 31/03/2017 à 15:04, Stelios Antoniou a écrit :
Hello !
As a sequel of my question and after the comments I received above,I started creating a new component :
TGLViewport = class (TControl)
which includes another class
Draw3D: TContext3D //lets say this is our opengl canvas

After I implemented all my functions & procedures that use opengl functions, I compiled it successfuly and new component registered with success.

The problem is that when I start a new multi-device application , I drag the component from the tool palette and suddenly delphi crashes!
A pop up window appears which informs me that software is not responding and the only solution is to close it.

can anyone help me with this?


you should first make all this work at runtime, then you'll take time to
make it work at designtime.
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 31, 2017 8:31 AM   in response to: Paul TOTH in response to: Paul TOTH
Am 31.03.2017 um 15:18 schrieb Paul TOTH:
Le 31/03/2017 à 15:04, Stelios Antoniou a écrit :
Hello !
As a sequel of my question and after the comments I received above,I started creating a new component :
TGLViewport = class (TControl)
which includes another class
Draw3D: TContext3D //lets say this is our opengl canvas

After I implemented all my functions & procedures that use opengl functions, I compiled it successfuly and new component registered with success.

The problem is that when I start a new multi-device application , I drag the component from the tool palette and suddenly delphi crashes!
A pop up window appears which informs me that software is not responding and the only solution is to close it.

can anyone help me with this?


you should first make all this work at runtime, then you'll take time to
make it work at designtime.

Hm, from his post we do not know this, but your advice is correct though.

=> the poster should mention whether it works at runtime and if not
which error messages it throws or writes into the log.

Greetings

Markus
Paul TOTH

Posts: 196
Registered: 1/2/17
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 2:42 AM   in response to: Stelios Antoniou in response to: Stelios Antoniou
Le 27/03/2017 à 15:03, Stelios Antoniou a écrit :
Hello!

I am trying to convert my VCL program in FMX. It uses many of the OpenGL functions.
After research I found an example with a cubeman written for cross-platform : [https://forums.embarcadero.com/thread.jspa?messageID=705080&#705080]
Inside the code a class is created (TGLContext which hosts any opengl function)

Is there any way to create a visual component (in our case the tglcontext) so as to use it in forms and call opengl functions?
I tried to change the type of the class for TGLContext as TViewport3D but as it was expected , it could not appear any of the things I created with opengl functions.
Also I tested with TControl3D and TStyledControl but even if compiling & installing the package was successful , tool palette did not include it.

Any ideas?

I've made the Windows "presentation" of a TGLPanel

https://github.com/tothpaul/Firemonkey/tree/master/GLPanel

not sure how to implement it under other OS, not for the OpenGL part but
for the initialisation part...under Windows the GLPanel is just a new
Window as a native control...I can probably make the same for OSX but
not sure how to do that under Android or iOS and even if it's required
because they do not use DirectX at all.
Stelios Antoniou

Posts: 16
Registered: 5/13/06
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 7:19 AM   in response to: Paul TOTH in response to: Paul TOTH
Hi Paul!

First of all I want to thank you for all your replies! They are very helpful and encouraging.

I downloaded your source code and I am trying to make all modifications needed.
I hope I will have obvious results soon.
Just a quick question : Is it an issue , the fact that I am writing code in Delphi Berlin and your code is in Tokyo?
I heard that Tokyo version has a lot of improvements but I do not know If those affect also our project for the opengl component.
Paul TOTH

Posts: 196
Registered: 1/2/17
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 7:40 AM   in response to: Stelios Antoniou in response to: Stelios Antoniou
Le 03/04/2017 à 16:19, Stelios Antoniou a écrit :
Hi Paul!

First of all I want to thank you for all your replies! They are very helpful and encouraging.

thanks :)

I downloaded your source code and I am trying to make all modifications needed.
I hope I will have obvious results soon.
Just a quick question : Is it an issue , the fact that I am writing code in Delphi Berlin and your code is in Tokyo?
I heard that Tokyo version has a lot of improvements but I do not know If those affect also our project for the opengl component.

well, I've made this "presented" component from a blog about XE10 so it
should work the same way under Berlin
Stelios Antoniou

Posts: 16
Registered: 5/13/06
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 6, 2017 5:11 AM   in response to: Paul TOTH in response to: Paul TOTH
Hello again Paul!

I am in the middle of a trial for building a component based on the TGLPanel of your code.
Compilation and installation is completed succesfully, but when I drag it to a new form for a multi-device application,
delphi appears a pop-up window which informs me for access violation.
After reading the details of error logs, it seems like a destructor of TMessageSender fails.

Do you have any thought about?

ps: I suppose it is necessary to have a distinct .pas file for Windows platform.
So here what I am thinking..what if we could change the type of the class of TGLPanel for Windows case from TWinPresentation to something else like TWinControl...?
Paul TOTH

Posts: 196
Registered: 1/2/17
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 6, 2017 5:45 AM   in response to: Stelios Antoniou in response to: Stelios Antoniou
Le 06/04/2017 à 14:11, Stelios Antoniou a écrit :
Hello again Paul!

I am in the middle of a trial for building a component based on the TGLPanel of your code.
Compilation and installation is completed succesfully, but when I drag it to a new form for a multi-device application,
delphi appears a pop-up window which informs me for access violation.
After reading the details of error logs, it seems like a destructor of TMessageSender fails.

Do you have any thought about?

I didn't try to install the component, but it's always joyfull to
refactor the code that work just perfectly at runtime because of
designtime requirements :)

ps: I suppose it is necessary to have a distinct .pas file for Windows platform.
So here what I am thinking..what if we could change the type of the class of TGLPanel for Windows case from TWinPresentation to something else like TWinControl...?

no, the purpose of PresentedControl is to have the same class (TGLPanel)
everywhere and a presentation (TWinGLPanel in
Execute.FMX.GLPanels.Win.pas) specific to Windows.

I've tried to create a TMacGLPanel for OSX but it fails for now, and
there's no FMX.Presentation.Mac unit because Delphi do not provide any
OSX native control.

BTW, you can try to change this:

procedure TGLPanel.Invalidate;
begin
PresentationProxy.SendMessage(PM_INVALIDE);
end;

by

procedure TGLPanel.Invalidate;
begin
if Assigned(PresentationProxy) then
PresentationProxy.SendMessage(PM_INVALIDE);
end;

it's possible that at DesignTime the presentation proxy is null
Stelios Antoniou

Posts: 16
Registered: 5/13/06
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 11, 2017 1:59 AM   in response to: Paul TOTH in response to: Paul TOTH
Hi Paul! Good and bad news!

With the help of your code , I managed to build mine.
Compilation and running in Windows succeeds.
So now I tried to change platform and run it to MacOS (using passerver)
Compilation is successful but running fails and error log appears in passerver terminal:

"Exception EAccessViolation in module <myprogram> at 00036F5F.
Access violation at adress 003886CD, accessing address 00000004"

So, I was wondering if you tried to run GLPanelDemo in mac os and had same behavior.
Paul TOTH

Posts: 196
Registered: 1/2/17
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 11, 2017 2:19 AM   in response to: Stelios Antoniou in response to: Stelios Antoniou
Hi,

with this

procedure TGLPanel.Invalidate;
begin
if Assigned(PresentationProxy) then
PresentationProxy.SendMessage(PM_INVALIDE);
end;

I can build my project under OSX without error...but without OpenGL
rendering :)

I'm not sure if it's possible to setup OpenGL on a FMX Object under OSX,
or if we have to put a Native NSOpenGLView like I did for Windows with a
new WINDOW

https://developer.apple.com/reference/appkit/nsopenglview

no time to try this until end of month at least.

Le 11/04/2017 à 10:59, Stelios Antoniou a écrit :
Hi Paul! Good and bad news!

With the help of your code , I managed to build mine.
Compilation and running in Windows succeeds.
So now I tried to change platform and run it to MacOS (using passerver)
Compilation is successful but running fails and error log appears in passerver terminal:

"Exception EAccessViolation in module <myprogram> at 00036F5F.
Access violation at adress 003886CD, accessing address 00000004"

So, I was wondering if you tried to run GLPanelDemo in mac os and had same behavior.
Stelios Antoniou

Posts: 16
Registered: 5/13/06
Re: Opengl & FMX  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 11, 2017 2:34 AM   in response to: Paul TOTH in response to: Paul TOTH
True story...I made the change in Invalidate function.

Application run without error logs but opengl scene (TGLPanel) is nowhere..
Thanks for you clarification. I will keep up the work with my findings. :)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02