Research on the new rendering of Qt bottom scene graph (ii.)

Source: Internet
Author: User

Research on the new rendering of Qt bottom scene graph (ii.)

The previous article introduced the QT new rendering of the underlying scene Graph, how can we use this framework to add a brilliant effect to the application? First, we want to make clear what the purpose of using scene graph development is. If it's a simple, purely 2D graphical interface, use the QT quick and QT quick widgets built directly on scene graph. If we feel that QT quick does not provide enough functionality for us, we may need to consider a lower level of scene graph when the QML layer is not very well implemented. A common requirement for using scene graph is to implement rendering of 3D models and overlay of 2D primitives (Overlay).

Saiyang original article, starting address: http://blog.csdn.net/gamesdev/article/details/43067265. Welcome to come to discuss the peer.

The difficulty of this article is large, suitable for experienced QT development Peer learning communication.

Now I've found two ways to integrate with scene graph to render 3D. The first is the use of the scene graph to provide related classes, such as Qsgnode and qsggeometry, such as a class of rendering, this method in the QT example corresponds to the customgeometry example, this example shows how the 2D three times Bezier curve is displayed The second is the full use of OpenGL-related APIs for rendering (in order to be compatible with QT, or it is recommended to use qopengl* to wrap it), the corresponding example is OpenGL under QML. I also wrote a similar example about six months ago (see QT Mobile app Development (eight): QML and OpenGL hybrid rendering for cross-platform). In contrast to the two examples, the second method is found to be easier to integrate with third-party libraries because it is only necessary to know the API of OpenGL and the knowledge of the shader. Of course, I recently explored the first method and learned some of Scenegraph's knowledge.

Well, you can come up with your own QT Quick program to experiment (if not, my independent game "10th exorcism" and "take medicine" of the Windows standalone version can be downloaded for free to experiment), Windows into CMD, set qsg_ Visualize for Overdraw, let's take a look at the display of the situation. We found a cube hanging inside the window, in fact, not the cube is wandering, but the QT set camera is wandering, the scene is not moving. And this cube is normally the scene we want to display (also known as the flat truncated head body). In Qt quick, rendering 2D uses orthographic projections instead of perspective projections, so we see this as a cube instead of a cubic table. But note that this is slightly different from the OpenGL scenario we created. We found that in QT Quick, X is incremented to the right, and Y is incremented, and OpenGL X is incremented to the right, y upward is not the same, and Qtquick uses OpenGL, which is the right-hand coordinate system, so how does its coordinate system be placed? In the previous article, the scope of this cube is x∈[0,screen.width],y∈[0,screen.height],z∈[0,1], we can use a graph to understand the coordinate system:

Now with the right hand four fingers pointing to X, thumb pointing to Y, then the palm of the point is Z. Yes, this is the OpenGL right-hand coordinate system, but QT inverted it. At the same time, the Overdraw mode camera is in the negative half axis of the z axis, looking at the approximate position of z in the positive half axis. The z-values of the two textures from left to right in the figure are-1 and 0, respectively.

After understanding this, our goal is to let the elements we draw as far as possible fall within the scope of x∈[0,screen.width],y∈[0,screen.height],z∈[0,1]. This will require us to set the position of each vertex in detail in the VBO. In addition, the Item::z value in Qt quick and OpenGL Z is not a concept, item::z represents the stacking order, the larger the value is placed in front, OpenGL Z-value, the smaller the more the expression in front. In addition, the scene is stacked with n-layers, then the entire view body n equal, each layer is displayed in front. This may not be easy to understand, or look at the picture.

Corresponding QML code:

window{    title:qstr ("Scene Graph texturedobject")    width:480    height:320    visible:true     Rectangle    {        anchors.fill:parent        color: "Orange"         Rectangle        {            anchors.centerIn:parent            width:            height:100            color: "Blue"}        }       


Corresponding QML code:

window{    title:qstr ("Scene Graph texturedobject")    width:480    height:320    visible:true     Rectangle    {        anchors.fill:parent        color: "Orange"         Rectangle        {            anchors.centerIn:parent            width:            height:100            color: "Blue"             Rectangle            {                anchors.centerIn:parent                width:20                height:20                color: "Red"            }        }       }

The next article will describe my attempt to display a series of objects in scene graph.

Research on the new rendering of Qt bottom scene graph (ii.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.