How to draw shapes with high performance on qml - c++

I want to develop a desktop application with QML. The app provides some drawing functions such as draw lines, rectangles, ellipses and so on. I find there are two ways to implement:
Inherit from QQuickPaintedItem and reimplement void Quick::paint(QPainter *painter).
Draw shapes in Canvas.onPaint directly.
But I find both of the implementation are not as faster as QWidget::paintEvent(). From the Qt Quick Scene Graph document says QQuickPaintedItem rendering is a two-step operation, and using scene graph API directly is always significantly faster. So how to use scene graph API
to implement that? Or I should use QWidget but not QML. Here is the Sample code and performance effect.

Related

Integrate GUI with OpenGL in C++

I need to create a GUI with a file menu and menu in which the user can input parameters. The parameters are then used for drawing rectangles in a canvas which is part of the application window. Is there a way to scale the OpenGL subwindow to just one part of the screen and the parameter input to the other? The application needs to be written in C++.
Is it possible to create a GUI with QT and draw the rectangles in the same window using OpenGL? If not, what is the common way to integrate a GUI with OpenGL? (or any other graphics library which I can use to draw rectangles from points as easy as possible)
EDIT: I am not sure If OpenGL is necessary or there is a way to paint the rectangles on the canvas like you can in Java with paintComponent().
I have never used QT before so I am not aware of its capabilites.
you can use opengl window singly or use this in the common mainwindow. previous example (in first answer) show how to use opengl window in qt singly and without communication with other components of Qt (like menu, toolbar and ...). but you can add a opengl window to a mainwindow (like other widget) and use it alongside other widgets . this example can help you.
Yes, using OpenGL together with Qt is absolutely possible. There is even an example for that and Qt provides classes for a more object oriented way of using OpenGL. Have a look here (Section "OpenGL and OpenGL ES Integration") for more details.

Integrate 3rd party 3d renderer in Qt

I have been looking for ways to render a 3d scene using Qt QML controls. I saw there is a framebuffer example which uses Canvas3D control to get OpenGL 3d scene rendered. However this example uses JavaScript for the rendering logic.
I was looking for a way to do the same but via a C++ class. Is there any way to do so? Or any example available?
Ideally, I would like to use 3rd party renderer to create a scene. Any ideas?

libvlc-qt and OpenGL

I'm trying to make an app using libvlc-qt and Qt5.5. Some functionalities require displyaing semi-transparent text and graphics over video widget. I've found this thread, which says: "The video widget is opengl. You should be able to put a new opengl layer above."
My question is how do I approach this? I've tried creating overlapping QOpenGLWidgets and drawing using QPainter on them, and some similar simple solutions, but it resulted with nothing happening or random segfaults. Any ideas?
You can overlap QWidget over QOpenGLWidget, but not the other way around. And specifically, nothing in the parent widget and under the QOpenGLWidget will be visible.

QML OpenGL game redraw loop

I am making a 3D game with OpenGL ES 2.0 and want to use QML as an overlay for the user interfaces.
I know that I can embed my OpenGL code inside a QGLWidget but how can I force QML to redraw the view as often as possible?
Additionally will I get performance issues because I am embedding the OpenGL view?
If you want to render your game with OpenGL and use QML for the UI, consider using the Qt Quick Scene Graph:
Mixing Scene Graph and OpenGL
Scene Graph - OpenGL Under QML

creating starting page for opengl game

I am working on a graphics game project in OpenGL and I want to make a front page of the game containing a image, few buttons and some text. Buttons on click perform different actions e.g. start button for starting the game , Can anyone please suggest me , How can I do it?
How can I do it?
Well, by implementing it. OpenGL is not a game engine, nor a scene graph, nor a UI toolkit. It's merely a drawing API providing you the means to draw nice pictures, and that's it. Anything beyond that is the task of either a 3rd party library/toolkit, or your own code, or a combination of both.
A usual approach to model this behaviour is by introducing application states. Here is a related question.
You could model your StartScreenState by drawing a plane with buttons using an orthogonal projection and not drawing (or not having initialized yet) the rest. When the player clicks on 'start', you can switch to perspective projection and display game contents.
I don't know that I would even use OpenGL for that. OpenGL is for rendering colored/textured triangles/quads so that you can do tons of stuff graphically. There's no such thing as "load an image to coordinate x,y on the screen". The equivalent would be "draw two triangles with these vertices that make up a rectangle and are textured with this image". Which is why I would probably stay away from OpenGL to do this, because you don't really need to use any of the awesome features that OpenGL has.
A very common UI framework that I believe nestles in with OpenGL well if you really want to use the two together is Qt. It should make your life easier in terms of UI stuff. See wiki and dev page.