Appmethod, RAD Studio, Delphi and C++Builder XE6 all make it really easy to work with OpenGL ES on mobile devices. Under the covers FireMonkey is implemented with OpenGL ES on mobile (iOS & Android), OpenGL on OS X and DirectX on Windows. It provides a number of useful abstractions for working with 2D and 3D graphics, but sometimes you just want to get down to a lower level.
Here is all you need to access an OpenGL ES rendering context in your FireMonkey mobile application. This example is in Object Pascal, but should be easy enough to adapt to C++.
- Create a new FireMonkey Mobile application
- Select 3D application
- Add FMX.Types3D to the Interface uses clause
- In the Object Inspector, create a new event handler for the OnRender event for your form
- You now have access to the OpenGL render context.
You can work with the TContext3D that is passed in via a parameter, and your code will work across platforms automatically. If you want to work with the OpenGL ES APIs directly you can do that too with the following uses clause in your Implementation section:
uses // Gives you access to the FMX wrappers for GLES FMX.Context.GLES, {$IFDEF ANDROID} // Direct access to the Android GLES implementation Androidapi.Gles, FMX.Context.GLES.Android; // More useful units for Android //, FMX.Platform.Android, Androidapi.Gles2, Androidapi.JNI.OpenGL, // Androidapi.Glesext, Androidapi.Gles2ext; {$ENDIF} {$IFDEF IOS} // Direct access to the iOS GLES implementation iOSapi.OpenGLES, FMX.Context.GLES.iOS; // More useful units for iOS //, iOSapi.GLKIT, FMX.Platform.iOS; {$ENDIF}
And here is an example event handler with a couple calls to the OpenGL ES APIs:
procedure TForm1.Form3DRender(Sender: TObject; Context: TContext3D); begin glClearColor(1, 1, 0, 1); glClear(GL_COLOR_BUFFER_BIT); end;
This accesses the iOS and Android equivalents of the same OpenGL ES APIs. Thanks to the compiler directives, and the cross platform nature of OpenGL ES, this code just works. I’m not an OpenGL expert, but I looked through the OpenGL ES API and all the routines I tested worked, but I never did anything interesting with them.
11 replies on “OpenGL ES Support on Mobile with XE6”
I think that http://www.fmxexpress.com/box2d-physics-engine-for-delphi-xe6-firemonkey-on-android-ios-windows-and-osx/ included OpenGL canvas for Windows in they source code
Great, Radek.
This could be a big adventage for games creators.
Can imagine to prefer using cross platform developing with delphi to build games, not application. Maybe this is more accurate path for delphi than making application? In case of games the size of executables don’t scary..
Definitely. Supporting OpenGL on most platforms but Direct3D on Windows makes it very difficult to do anything that requires custom shaders if you want your project to be cross-platform. Having an OpenGL canvas for Windows is a necessity in a case like that.
Printing is NOT working on Android 4.4? (sorry out of topic)
Can you please open the ShareSheet program from Mobile Snippets folder. (C:\Users\Public\Documents\Embarcadero\Studio\14.0\Samples\Object Pascal\Mobile Snippets\ShareSheet)
Please click the “Share” button to open the ShareSheet, the CloudPrint option should be in the list; but it is NOT in android 4.4.
Can you please help in finding a way to print images from android 4.4 devices?
Thank you
ray
[…] Appmethod, RAD Studio, Delphi and C++Builder XE6 all make it really easy to work with OpenGL ES on mobile devices. Under the covers FireMonkey is implemented with OpenGL ES on mobile (iOS & Android), OpenGL on OS X and DirectX on Windows. […]
Many companies in India are developing applications for ios, android, web and windows. Especially in Bangalore are best to developing apps in various purpose like social media, games, ticket booking, etc. Most of the companies like pacewisdom are first prefer to develop mobile apps . This is a development company have many experts to develop the apps within the certain period with good quality.
[…] demo for IOS. If you want to do drawing using OpenGL directly and not just the Firemonkey functions Jim McKeeth has a blog post up with a roundup of using OpenGL with Delphi XE6. Lastly the Box2D physics engine for Firemonkey has extensive drawing examples using a […]
Do you have any function other the glClear working? I tried to port GLES Triangle sample but nothing is visible except changed color of the backround
This is not working in C++. I include the right files:
#include
#include
#include
#include
and this is my Form3DRender function:
void __fastcall TForm3D2::Form3DRender(TObject *Sender, TContext3D *Context)
{
glClearColor(1, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
}
But I get the errors: use of undeclared identifier ‘glClearColor’,
and: use of undeclared identifier ‘GL_COLOR_BUFFER_BIT’
With the undeclared identifier error it sounds like you need an additional include.
[…] […]