I have been looking far and wide to find out how, if it’s possible, you can fill a particular area in a QML screen with an OpenGL context and do custom OpenGL only in that context. I’ve seen plenty of demos where the QML components like buttons, etc lay on top or below a screen-wide OpenGL context (as is typically required by games), but I’d like to be able to situate several distinct OpenGL contexts within QML and have the QML file define how large they are, where they are positioned, etc.
Now, since Qt 5 is all OpenGL under the hood, it makes me wonder if using a Canvas element with custom drawing via javascript could result in similar rendering performance as custom OpenGL? This would be a meaningful alternative but it’s not clear to me how the javascript drawing is handled via runtime compared to custom OpenGL drawing.
What is it that you want to draw? QQuickPaintedItem may be the simplest way to go about it. When you're using QOpenGLFramebufferObject as the target, the painter will use OpenGL to paint the texture. It might be easier than writing your own OpenGL code if all you're doing is 2D.
Related
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.
According to this article, there are two main methods for rendering raw OpenGL into an application whose UI is otherwise managed by QtQuick's scene graph. In short, they are (according to my understanding):
Calling raw OpenGL methods in hand-written code that is hooked into the scene graph's render loop through some APIs exposed by QtQuick.
Rendering the raw OpenGL portion of your scene to a QQuickFramebufferObject, which is treated like a component in the scene graph and itself rendered as if it were a texture.
What are the advantages/disadvantages of the two approaches?
The issue with QQuickWindow::beforeRendering() or QQuickWindow::afterRendering() signals is that all OpenGL drawing done from their slots will be appropriately under or over the rendered Qt Quick scene. If this is good enough for you — ie. you only want to draw a custom OpenGL background or some kind of overlay — then go for it.
If you need more, ie. use OpenGL to render some QtQuick Item that placed within the scene graph, then you have to go with the second option: rendering OpenGL to a framebufferobject that is used as a texture on some QtQuick Item.
As the documentation article you have linked to states, it gives you more possibilities (using multiple rendering contexts or even multiple rendering threads) but also comes with performance cost. It is also more troublesome to implement.
Generally, as the option 1) is usually inadequate, you are forced to go with 2). It is the only way to use raw OpenGL within a QtQuick scene that I know of.
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.
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
I need an appropriate rendering engine to render a 3D model into Qt, and use Qt then as an event handler to this model. Thank you.
As for the rendering engine, you can go several directions, but I'll mention two. Qt comes with an OpenGL widget. You could make use of this by either:
writing your own rendering code to render your model using OpenGL
or
making use of a rendering engine/framework which has it's own Qt Widget (possibly derived from Qt's OpenGl widget). I know OpenSceneGraph has Qt integration available. And I seem to remember Ogre does as well. This just to mention two options. Just Google for Qt and your favorite engine and you'll most likely find something suitable. And if not, it is usually not that difficult to write your own integration if you feel like it.
Whichever option is more suitable for you depends on the exact specification of what you're trying to achieve. You probably know that better than we do.
As for the event handling, you might want to be a bit more specific as to what you mean.