How to ANGLE in Qt 6 OpenGL - c++

Qt 6 has removed the support for ANGLE for their OpenGL backend. Now I would still like to use ANGLE with Qt because I would like to run custom OpenGL code that is translated by ANGLE to Vulkan Linux and Direct3D on Windows. I've tried to use ANGLE in my Qt 6 application, but without success. What I have tried is:
Build ANGLE from source files (on Linux) as per instructions (ANGLE build instructions).
Copied the generated libGLESv2.so and libEGL.so files into application directory. Then in my CMakeFiles.txt I have added:
find_library(libGLESv2 GLESv2)
find_library(libEGL EGL)
target_link_libraries(MyApp PRIVATE ${libGLESv2} ${libEGL})
Then in my main file I have added
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
My project links and builds fine, but the ANGLE backend seems to have no effect. It appears that Qt is still using the standard OpenGL implementation rather than the one provided by ANGLE (running QOpenGLContext::currentContext()->hasExtension("EGL_ANGLE_platform_angle") returns false when I set up my context).
Using QT_LOGGING_RULES=qt.qpa.gl=true,the logs show:
qt.qpa.gl: Choosing xcb gl-integration based on following priority
("xcb_glx", "xcb_egl") qt.qpa.gl: Xcb GLX gl-integration created
qt.qpa.gl: Xcb GLX gl-integration successfully initialized qt.qpa.gl:
Requested format before FBConfig/Visual selection:
QSurfaceFormat(version 3.0, options
QFlagsQSurfaceFormat::FormatOption(), depthBufferSize 24,
redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize
-1, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 1, colorSpace
QSurfaceFormat::DefaultColorSpace, profile QSurfaceFormat::NoProfile)
How can I correctly setup Qt to rely on ANGLE?

Okay,
When I asked for a buildable project that reproduces the problem I didn't mean a snippet of source without the CMakeLists.txt that is causing the problem. I spent a good 4 hours trying to duplicate your environment blind. Nobody uses Qt 6 because it is horrible.
The first problem is you can't "just copy" libs.
GLES libs
EGL libs
After copy
the build and runtime system wants its series of links. When you copy you loose that because you get multiple copies of the same file rather than one copy with a bunch of links. If you are going to use these libraries you need to use them from an installed location or the original build location.
I wanted to prove this solution to you rather than just tell you, but I ran into the same problem 98.5% of all developers run into when anything Android is installed near Qt.
I wanted you to look at the CMakeLists.txt file for WaylandGUI not because it is some shining example of wonderful, rather so you see how to use message() to dump your cmake variables. This is the "default debugger" when troubleshooting cmake issues.
You aren't properly using find_library()
https://cmake.org/cmake/help/latest/command/find_library.html
Had you installed the ANGLE library you built there is a 50/50 chance find_library would have found it. One would need to dump the cmake variables to see where it looked and what it found and to do that you need message().
In particular read up on CMAKE_PREFIX_PATH and the PATHS option for find_library(). If the documentation seems clear as mud you can view this SO discussion on CMAKE_PREFIX_PATH.
cmake - find_library - custom library location
The other command you need to know is ldd. It's really shocking how many people developing on Linux that don't know this command.
What ldd does, from a high conceptual level, is tell you every library the loader is going to use when running your executable, at least from an initial load standpoint. The executable itself may be able to force load other libraries at run time. When an executable dies before it starts you can use ldd to track down what library (or library used by a library) cannot be found.
In your particular case, ldd will tell you what GLES and EGL libraries were used during link. By default find_library() looks in "the usual places" first which isn't your local build directory. The problem you are running into is you are trying to replace an existing system library in your link. Here's a very detailed write-up on how to use HINTS and such with find_library().
Without being able to replicate your build environment and without a complete buildable example replicating the problem I cannot be of further help.

Related

How to add Qt sources to QtCreator in Ubuntu?

Edit
The answers to this post either say compile yourself - which I don't want do to - or install qtbase5-dbg which is not part of Ubuntu releases anymore. So is there no way to achieve this without this package? And shouldn't there be different debug symbols for each Qt 5.X version?
I'm trying to add Qt sources - which I installed along Qt both using the Qt Maintenance tool - to QtCreator but am not able to get it to work. I've already looked at various websites for help but still no luck. I need to step into the Qt sources to see how Qt3D works since I'm trying to develop a Qt3D widget.
As for many others, when I go to Options > Debugger and there under Source Path Mappings click on Add Qt sources... it adds /home/qt/work/qt as Source Path and /home/[my username]/Qt/5.14.2/Src (the latter being the folder I selected).
Since I can't step into the Qt sources I assume the Source Path is wrong. I tried to follow the steps from this answer but when I move the mouse over a function call in the call stack after stopping at a breakpoint doesn't yield any path - just the function name and address.
Someone also pointed out that the compiled Qt libraries must not include stripped when getting info from them like this: file libQt.... But this is what file libQt53DCore.so.5.14.2 gave me:
libQt53DCore.so.5.14.2: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=d764882c0c26814e30d63a4d4719143e14e4c735, not stripped
So I assume that's fine. Although I built Qt myself and file libQt53DCore.so.5.15.0 yields
libQt53DCore.so.5.15.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=88eeb269ff68f0b71e3612d1a538503676da3790, with debug_info, not stripped
i.e. an additional with debug_info.
Unfortunately, building Qt results in a 20 something GB build and I would have to do this for multiple Qt versions. So how can I setup QtCreator properly so that I can step into Qt sources.
A few minor versions ago, Qt added "Qt debug information files" to the maintenance tool.
They contain the debug information of the libraries.
Which means, if you debug and want to step into human readable Qt library code you have to install them.

Packaging fonts and shaders with cmake

I am writing an OpenGL app which runs on windows, OSX and linux.
I have some free-for-commercial-use truetype fonts that I'm packaging with the app, so the user can choose their preferred font for the text part of my renders.
I have some glsl shaders of my own making, so that my rendering does just the right thing. I need to package these with the app, too
I build with cmake and build an installer with cpack. I use the install command to control where the fonts and shaders go, on the target machine.
I have C++ code which, given a path to a font file, will give me just the right font in the rendered image. Similarly, I have OpenGL code which needs to know where the shaders are, at runtime.
On the build machine I've used configure_file to handle OS/user variations. The fonts and shaders are relative to a directory where the code resides, so I can put their location into a header file as a namespace variable, and the shading and font code can always find them.
Now I'm trying to get the installed app to work I've hit a problem: I can put my fonts and shaders anywhere I like on the target machine, at install time, but am struggling to see how the runtime (installed) executable, on the target machine, can be made to understand where that location is.
Compiler flag? Environment variable? Target property? None of them seems to quite fit the bill. Or is that wrong? Any thoughts would be very much appreciated.
You have two possibilities here:
The application is installed to a directory chosen by the user, but you control everything within that directory (what CMake calls the install tree). Because of this, you know where all of the external files are located relatively to the executable, so you can use relative paths for addressing them (as was also suggested in the comments). This approach is very common for OS X and Windows, where each application is typically installed to its own distinct directory. It's a bit less common for Unix-y systems, where stuff is typically just dumped to /usr/bin.
If you are not comfortable with relative paths, you can always package all resources into the executable itself. This is typically done using a resource compiler, but CMake has built-in support for those. This approach is particularly popular with GUI applications that package their fonts and icons into the executable itself. Qt offers a cross-platform resource compiler for this purpose, that is also supported by CMake.
Linux has a really different installation philosophy. Resources are installed in standard locations, which are not at a fixed relative location from the binary itself (windows in somewhat moving in this direction with ProgramData and .AppData)
The Linux approach would be to use fontconfig to locate fonts, and then install your fonts system-wide in /usr/share/fonts/myapp or in the user directory (~/.fonts/myapp or even better the new XDG location)
For shaders it would be similar with /usr/share/myapp system-wide and XDG locations user-side (https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html)
Of course you can force whatever you want in your code, and install in /opt, it will never feel like an integrated linux app from the user POW though

How do I configure QT5 without Xlib

I am trying to configure (and build) QT5 static. I want it to draw to the framebuffer and use webkit. I searched the docs but I didn't find anything on how I can do this without X. Does anyone know a way of doing this ?
Building Qt statically is totally orthogonal to the platform selection. Depending on your target device, you can choose between using Wayland, EGLFS, LinuxFB/DirectFB, etc.
Just be sure when you run configure that the actual plugin you're interested in gets compiled. In other words, check configure's final output (or read the config.summary file generated). If the platform is not there, run configure -v and try to see what's missing (headers, libs, ...).
You can then make any application use a given plugin by simply starting the application and passing the argument -platform eglfs|wayland|... (or by setting the QT_QPA_PLATFORM environment variable; or you can make it the default by mangling with the device mkspecs). More info here.
When it actually comes to static linking: this multi-platform support is implemented via plugins. A statically linked application won't have plugin loading available, so you must actually link the platform plugin into the application itself by adding something like
QTPLUGIN.platforms = eglfs
into your .pro file. More info here.
The best way is to use the "minimal" plugin and blit it into the framebuffer (something similar to the discussion at http://lists.qt-project.org/pipermail/development/2015-April/021160.html). However, ask your Platform vendor - check if "eglfs with fb" is a supported option.
However be aware that things like Cursor, overlays, rotation, vsync handling, GPU acceleration, may not be fully supported in these non-mainstream options on Linux.

How build harfbuzz without dependencies

I want build latest harfbuzz-ng library on Windows 7. But in build system by default I must go through long quest to gain: ragel, pkg-config, gtkdocize and other stuff. Even in the end if I get all what need for build system I get errors (sorry cannot say which concrete errors), last time I tried to build this library 2 month ago). Maybe on Linux system it is easy to get and build all this stuff but on Windows always something doesn't want to be compiled. Or the problem is that I don't find instructions which guide me on Windows, only Linux.
What I want to get is simple instructions how build only harfbuzz-ng with freetype dependency (and maybe add ICU) by MinGW compiler on Windows.
Thanks you very much.
For anyone reading this, have a look at harfbuzz.cc in the project which makes you able to use harfbuzz without any build system, just include it in one of your sources, no build system is required, define HB_NO_MT or even HB_TINY (which brings a minimal harfbuzz) if you don't use harfbuzz in multithread mode.
I don't know i this is the answer you are looking for. I am trying to work with Harfbuzz as well and did this through several attempts which did not work out for various reasons.
One (old) example you could use as a starter is: HarfBuzz static lib. The .lib-file generated works with UCDN and just needs this file plus a source for the Freetype-functions to provide the necessary FT_Face-parameter (i did this by compiling another .lib via the freetype-sourcecode (freetype.org/download.html).
But I am unsure if this will work out for the MinGW-compiler (you don't use VC++ as IDE do you??).
You may find of interest the MSYS2 build system. It is essentially a linux-style packaging system built on top of Windows(TM). You can download and install binary packages with simple commands (including automatic dependency solving). If you want to download a source package you can do that as well. http://msys2.github.io

Setting up OpenGL library on windows

I'm totally new to OpenGL, so I'm trying to compile my application at home. At my university I have everything settle by my professor in the lab and there I use Linux. At home I'm using windows 8 with visual studio 2013.
I'm trying to build a sphere in my app which contain the includes below:
#include <GL/glut.h>
#include <math.h>
#include <iostream>
So, since it contains Glut.h I went to http://www.opengl.org/resources/libraries/glut/glut_downloads.php#2 to download the library and make it rock, but I had some problems.
I thought the windows version would come compiled and it didn't. The dlls are not inside the package as I expected to link them in my project properties so I tryed to use CMake to compile the glut but it didn't work. CMake returns to me the following log:
CMake Error: Cannot open file for write: C:/Program Files/Glut 3.7 Build/CMakeCache.txt.tmp
CMake Error: The source directory "C:/Program Files/Glut 3.7/glut-3.7" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
CMake Error: : System Error: No such file or directory
CMake Error: Unable to open cache file for save. C:/Program Files/Glut 3.7 Build/CMakeCache.txt
CMake Error: : System Error: No such file or directory
It says that the folder doesn't contain the CMake file.
My download link to glut (supposed to be windows, not sure cos of the error) is this http://www.opengl.org/resources/libraries/glut/glut37.zip
Normally I programm java, which I dont have so many headaches to setup the IDE..so take it easy please and now I ask:
What am I missing to make my OpenGL code run?
Your teacher should help you at the first place.
I would like to inform you that GLUT library was abandoned since 1998. Last version is [3.7].But you are lucky!
"freeglut" is alternative to the OpenGL Utility Toolkit (GLUT) library.
Everything you need is here, I recommend reading it all.
And to help you out, here you can find Windows binaries, look for link called: "Download freeglut 2.8.1-1 for MSVC".
After download, you must link the library folder, include folder and copy freeglut.dll to you project folder (inside Debug or Release folder). You can find dll files inside a bin folder.
And after that, you can call #include "GL/glut.h" with no problems.
Good luck!
It doesn't compile with CMake. Open a Visual Studio command prompt and type nmake in the top level directory of the glut source code.
At my university I have everything settle by my professor in the lab and there I use Linux. At home I'm using windows 8 with visual studio 2013.
Then the very first thing you absolutely must do is heading to your GPU maker's website, download the newest drivers from there and install them. That is, because the drivers installed by default with Windows 8 lack proper OpenGL functionality.
So, since it contains Glut.h
You mean glut.h – file names are case sensitive on most operating systems (Windows not among them). So for portability reasons you should care to write them with the proper spelling.
I went to http://www.opengl.org/resources/libraries/glut/glut_downloads.php#2 to download the library
The old GLUT library isn't maintained for over a decade. Use an alternative implementation like FreeGLUT and use that.
so I tryed to use CMake to compile the glut but it didn't work.
Okay, here you got no technical problem, but a lack of understanding. Essentially your brain got what I call "IDE rot": All those sugar coating and clicky-pointy action of IDEs obscure what actually is going on when a program is built. You'll have to bit the bullet there and understand how the interaction between the build control generators the build system the compiler and the linker works.
CMake is a build control generator: In CMake you describe the build dependencies of your program sources. From that CMake generates the actual build information for the build system used (GNU make and GCC on Linux; NMake and MSVC++ compiler on Windows for example).
Of course for CMake to work there must be an appropriate CMake configuration present. And in the case of GLUT that's definitely not there (the last official release of GLUT predates the first release of CMake.
Now you should really wonder: Why did you call "cmake" in the first place? I bet, because you always did it so far, or you read it somewhere, without even trying to understand what's going on.
What you did was folloing a Cargo Cult – it somehow resembles the actual process, it looks like it from the outside, but it doesn't yield results. Feynman's speech later coined the term Cargo Cult Programming; interesting enough I was using that term (consistently with its definition, just due to being familiar with Feynman's speech) without knowing that other people already had coined it in exactly the same way. Such a often it happens, that people will come up independently with the same term for it.
Normally I programm Java, which I don't have so many headaches to setup the IDE
Well, that's your problem right there. You only know how to click around in an IDE. Even when programming Java, with an IDE, you should get intimately familiar with the actual build process: Java compiler, JAR file creating, and so on.
What am I missing to make my OpenGL code run?
I bet not very much. It's a lack of understanding how the build process for software works and is controlled. You'll have to bite the bullet and learn that first. And for that I suggest you install Linux or FreeBSD, or at least Cygwin on your computer.
Windows is not a very good system to learn those things, because its been built around clicky GUIs. That is not to say that Windows was a bad operating system. It's juat that you want to have something you can experiment with and quickly go through various iterations of build tool option switches. A GUI can't give you that.