How to use OpenGL in QT Creator - qt

I am working on OpenGL to create a GUI .I want to create some tabs which will help me to display different things in different windows. How is this possible using OpenGL? I read in some articles that we can use QT for that. Since I have already developed some of the GUI part in OpenGL using GLUT library ,is it possible to use the same code in QT? If so brief me how to make settings for OpenGL libraries in QT creator.
In my GUI I am trying to create a Car which is following a track.

I think you might be mixing some things up: OpenGL is a API with which you can instruct drivers to draw visual primitives, like lines, boxes, 3D triangles, pictures from buffer onto a render plane.
GLUT is a library that gives you a minimal environment around that, ie. it handles creating a window etc.
Neither of them are high-level UI description tools. Qt is really most likely what you want, as it will not only give you things like tab widgets etc, but also a feature-rich framework to do things like defining what should happen when you click a button, close a window etc.
There's a lot of examples of OpenGL usage within Qt widgets. In fact, a lot of visualization frontends use Qt and OpenGL. Qt has extensive documentation on how to generate OpenGL contextes and draw inside Qt applications.

Related

Drawing with EGL in Qt

I'm trying to get Qt and EGL to work together. I'm working on a program that uses EGL to draw, and I have to use Qt to create a GUI overlay.
The current solution was to turn a QWidget into a native window, and pass it's window handle to EGL. This works, but it's difficult to work with. Qt isn't aware that the widget is being drawn in by something else. So when another widget is overlaid, even if it's transparent, the image drawn by EGL is erased. The only way to get them to work is if I jigsaw the buttons and other GUI elements in a way that they don't overlap the parts of the native window I want to show. However this means that I can't use layouts or QML or any of the tools that would make creating different GUIs easy.
So my question is, how can I draw with EGL into Qt in a more usable way.
I'm working with Qt 5.4.2 by the way. If absolutely necessary, I might be able to upgrade to 5.5, but newer versions won't work.
I was looking into QOpenGLContext, and ways to make it use the context created by EGL, but I can't seem to find any good examples on how to actually go about doing this.

Modern looking UI with QT

I have an wizard application written in C++/MFC that I want to improve the UI. Different buttons, change the dialog background color, etc. Could I use QT to improve the appearance or should I change to WPF and C#?
Qt 5 gives you essentially five (5!) UI toolkits:
The Gui module that is similar to what you got with a very good 2D graphics library in the late 1980s/early 1990s. You have access to the buffer of the window and to key/mouse events. Everything else is up to you. This would be the fastest way to port an existing application from "back then". The graphical primitives are neat, with fonts, painter paths, gradients, etc. but there's no notion of a widget, only of a top-level window. You draw everything where you want it to be within that window.
The provided concepts are at a higher level of abstraction than typical platform toolkits like winapi or xlib. In terms of graphical primitives it is more akin in spirit to Cairo or PDF.
It is possible to parallelize the painting of a QRasterWindow in the same way as it is done for QWidget.
The Widgets module gives you Qt4-style widgets and layouts, with customize-able styles. This is the model perhaps most like MFC, although it has much more functionality. The widgets are so-called alien widgets - it means they don't have native window handles. This keeps things fast. You have a multitude of pre-written widgets to do user input/output of all kinds. It is possible to parallelize the painting of a widget..
The Declarative module, a.k.a. Qt Quick 1, uses the QGraphicsView widget from the widgets module to display a graphical scene. This scene is described using QML. The controls are fairly rudimentary and there's no platform-specific styling. It will look all the same no matter where you run it. There is good support for animations/fluidity in the interface.
The Quick module, a.k.a. Qt Quick 2, uses a new OpenGL ES-based scene graph and can run on top of either a widget from the widgets module, or a raw window from the gui module. The scene is described using QML. There is a desktop components set that gives you platform-styled controls like combo boxes, text inputs, tables, etc. The new scene graph can really leverage the hardware and will outperform both widgets and Qt Quick 1 when you have heavy animated UIs. This is the way to go for the future. Qt 5.2 brings in an entirely new Javascript engine and a new scene graph renderer, with even better performance. Qt 5.11 brings in a new Javascript engine again, twice as fast.
The 3D module, exposed both via C++ and QML APIs, is a high-level 3D object and scene rendering system, tailored for interactive applications. It makes it easy to implement user interaction with 3D objects. The C++ and QML APIs are peers and can be used per your preference - this is in contrast to Qt Quick, where the only the QML API offers the full functionality.
Both Qt Quick 1 and Qt Quick 2 can wrap existing widgets at very modest performance cost, but you do lose out on some of the niceties of "native" QML objects.
Do note that there's a separation between the need for an OpenGL implementation and there being one provided on your system. On post-Windows-XP systems (Vista, 7, 8, etc.) you should normally use Qt 5 with its own ANGLE implementation of OpenGL ES 2 that runs on top of DirectX. Only on Windows XP you're forced to use the system OpenGL drivers.
Qt is a generally very nice framework to work with even for non-gui applications. It has good cross-platform abstractions of networking and file I/O, time/date, and provides a bunch of other general-purpose goodies. It is relatively easy to use it alongside ncurses, for example.
The fastest way to port existing MFC code would be to stay with C++ and use Qt with the qtwinmigrate solution. The latter is a BSD-licensed shim layer that can get you up and running very quickly.

Qt 5 General Questions about QT / QML and Widget customizations

I am an iOS / Cocoa developer looking to port one of my apps to PC platform. I don't care to code multiplatform and maintain one app. I will continue using cocoa and cocoa touch for iOS Mac Development.
I have chosen to use QT 5 for PC, I am not sure if its wise choice but its easy and I can understand c++. If its not please point me to the correct direction.
My App is not hugely complicated, but needs some special customization e.g. ListView that looks like an iOS Table View, uses custom rounded windows with twitter bootstrap style search box and I want to monitor some global OS events like keystrokes, and what other applications the user is currently working with. I also use SQLite and AES encryption.
My questions is regarding UI customization.
Should I start studying and use QML for that? I am not sure what exactly it is, seems extremely simple CSS like, but I have the feeling is more designed for embedded devices and have limitations...
Do I have access to the entire power of QT if I use QML ?
What other options I have to customise widgets instead using QML (e.g. in objective C we use subclassing and drawing whatever we want or handling events...)
I am inexperienced in windows platform. Should I use VisualStudio C++ instead of QT5? With the changes in ownership I feel somehow insecure.
Yes you should. QML is declarative language which allows javascript to be executed within it. And you can do almost anything UI related with QML. If you don't have some particular UI element you can draw it in plain C++(Qt) and use it in the QML. So QML is the best choice for Qt development at the moment. It is not like CSS though, it is much more powerful.
Yes you have all the power Qt has and additional power which declarative language may offer - simplification of UI development process as well as modern decomposition of UI&logic.
You have this option in plain C++ Qt, you may subclass widget, redraw them, change behavior etc. This approach is inferior to the QML one.
This point doesn't make sense. Some people count Visual C++ like separate language which is wrong. You may count Visual C++ as C++ + some minor extensions MS compiler has. But it is as ridiculous to refer as GCC C++. So basically you can use Visual Studio with Qt almost without a pain if you use Qt integration add-in which is freely available. Or you can choose Qt creator, which some people count as superior to MSVS. It is up to you what to choose, but I believe for the novice it is much simpler to use Qt creator with Qt. But note you will need to have some compiler because Qt creator is just an IDE it should use some 3rd party compiler(either MS or GNU one)
You can use QML Desktop Components to build easily your application:
https://web.archive.org/web/20121203050945/http://blog.qt.digia.com/blog/2012/06/06/desktop-components-for-qt-5/
http://qt-project.org/wiki/Qt_Quick_Components
Anyway I recommend you use Qt Widgets and Qt Style Sheets to costume your widgets:
http://qt-project.org/doc/qt-4.8/stylesheet-reference.html

Embedding Qt GUI into existing OpenGL program

I'm currently trying to get Qt working with my existing program.
I'm using SFML for creating my OpenGL rendering context and creating the window. The things I tried out so far however always create a separate window by Qt instead of just rendering into the existing context.
Is there any way I can force Qt to render to an already existing OpenGL context?
I've not looked into the specifics, but this has been done for openage.
I think looking at the documentation for QQuickRenderControl might be a good place to start.
Qt wants full control over the windows and the event loop, so this will not work (unless you put a lot of effort into it). Your best bet is using a QGLWidget and emulate the event management of SFML with that, so that your application effectively runs on Qt. It is very well possible to render Qt widgets into a OpenGL window (Qt has a OpenGL widget backend) but this must be still managed by Qt itself.

Qt+OpenGl+SimpleGl

I have enabled qt+OpenGl+SimpleGl on one of the ARM platform and was able to run opengl example programs.
I also has a qt+Webkit, which is working with a graphic plugin.
I wanted to use simpleGl context for every thing, instead of using the normal graphic screen. So, when I try to run Qt+Webkit with simpleGl, I just get a blank screen.
Does QT support this? If so how can we make it?
Yes, this is correct. OpenGL draws directly to the framebuffer. The simplegl driver doesn't handle what is drawn using the raster paint engine of the QWS, so you may see only black.
Using simplegl for "everything" means you want everything to be drawn using OpenGL in your EGL full-screen window? This is possible under some assumptions. You have to write all your applications to be rendered using the Qt OpenGL paint engine (using the opengl graphics system is not supported under Qt/E). This is possible also for QtWebKit, I'm doing it now. Note that this does not mean that everything is rendered using hardware acceleration. You'll have to write your applications "the right way" to get all actually hardware accelerated. Consider that you'll have to handle the mouse pointer some other way in this case.
The other way is to just modify the simplegl driver to allow for the use of Qt applications using the raster paint engine. This is possible as well with some limitations. Qt can use blit to place its own windows over OpenGL. Look for the framebuffer driver inside the Qt source tree to know how to do this. You can then have common Qt applications and OpenGL Qt applications some way. I'm doing this as well. Not everything can be done anyway.
EDIT: I'm sure you already did, but in case, give this http://doc.qt.io/qt-4.8/qt-embeddedlinux-opengl.html much attention.
Unfortunately I don't know anything about SimpleGL, but I do know that there is a way to render a standard Qt widget in a QGLWidget. Maybe have a look at this Qt Quarterly which I think is somewhat related to your question:
http://doc.qt.nokia.com/qq/qq26-openglcanvas.html

Resources