Research on the bottom layer Scene Graph of Qt new rendering (2), scenegraph

Source: Internet
Author: User

Research on the bottom layer Scene Graph of Qt new rendering (2), scenegraph

Research on the bottom layer Scene Graph of Qt new rendering (2)

The previous article introduced Qt's new rendering of the underlying Scene Graph. How can we use this framework to add brilliant results to applications? First, we need to clarify the purpose of using Scene Graph for development. If the GUI is simple and purely 2D, you can directly use the Qt Quick and Qt Quick widgets built on Scene Graph. If Qt Quick does not provide enough functionality for us and cannot be implemented well at the QML layer, we may need to consider a lower layer of Scene Graph. A common requirement for using Scene Graph is to render 3D models and Overlay 2D elements on them ).

Jiang caiyang's original article, first published at: http://blog.csdn.net/gamesdev/article/details/10967265. Welcome to the discussion.

This article is too difficult and suitable for experienced Qt developers to learn and communicate with each other.

Currently, I have found two ways to integrate 3D rendering with Scene Graph. The first is to use the related classes provided by Scene Graph, such as QSGNode and QSGGeometry for rendering. This method corresponds to the customgeometry example in the Qt example, this example shows how the 2D cubic besell curve is displayed; the second is rendering completely Using OpenGL-related APIs (to be compatible with Qt, we recommend that you use QOpenGL *. The corresponding example is OpenGL under QML. I wrote a similar example about half a year ago (see Qt mobile application development (8): cross-platform QML and OpenGL hybrid rendering). Compared with the two examples, we found that the second method is easier for third-party library integration, because we only need to know the knowledge of OpenGL APIs and pointers. Of course, I recently explored the first method and learned some knowledge about SceneGraph.

Okay, you can come up with your own Qt Quick program for experiment (if not, the Windows standalone version of my independent games "ten-day ghost drive" and "take medicine" can be downloaded for free for experiments). In Windows, go to cmd and set QSG_VISUALIZE to overdraw, let's take a look at the display. We found that a cube is wandering inside the window. In fact, it is not the cube but the camera set by Qt. The scene is not moving. This cube is the visual object to be displayed under normal circumstances (also known as the flat header ). In Qt Quick, rendering 2D uses orthogonal projection instead of perspective projection, so we can see that this is a cube rather than a cube. However, note that this is slightly different from the OpenGL scenario we have created. We found that in Qt Quick, x increments to the right, and y increments downward, which is different from that of OpenGL x to the right, and y increments upwards, while QtQuick uses OpenGL, that is to say, how does one place the coordinate system of the right hand coordinate system? In the previous article, we talked about the cube in the range of x, 0, Screen. width], y, [0, Screen. height], z, [0, 1]. We can use a figure to understand the coordinate system:

Now point to x with the four fingers in the right hand, and point to y with the thumb, then the point in the palm of your hand is z. That's right. This is the right hand Coordinate System of OpenGL, but Qt has put it upside down. At the same time, the overdraw mode camera is in the negative half axis of the z axis, and the general position of the camera is in the positive Half Axis of z. In the figure, the z values of the two textures from left to right are-1 and 0, respectively.

After understanding this, our goal is to let the elements we plot fall into x 0, Screen as much as possible. width], y, [0, Screen. height], z in the range of [0, 1. This requires us to set the position of each vertex in detail in VBO. In addition, the Item: z value in Qt Quick is not a concept with OpenGL z. Item: z indicates the stacked order. The larger the value, the more advanced it is. The z value of OpenGL, the smaller the value, the more it indicates the front. In addition, the scene is stacked with n layers, so the entire scene is classified as n, and each layer is displayed in front. This may not be easy to understand. Let's look at the figure.

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: 100            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: 100            height: 100            color: "blue"             Rectangle            {                anchors.centerIn: parent                width: 20                height: 20                color: "red"            }        }       }}

The next article will introduce my attempt to display 3D objects in Scene Graph.

Related Article

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.