【问题标题】:How to render a OpenGL 2D texture on a QML surface? [closed]如何在 QML 表面上渲染 OpenGL 2D 纹理? [关闭]
【发布时间】:2023-02-15 15:40:20
【问题描述】:

我有一个有效的 OpenGL 2D 纹理。在 QML 表面上呈现它的最好和最简单的方法是什么?我可以参考任何简单的 Qt 示例吗?

基本上我的纹理 ID 是 GLuint。我确实有权访问应用程序的QOpenGLContext*,我认为这是渲染纹理所必需的。有没有关于如何在 QML 上渲染纹理的简单示例?

环境:
MacOS Monterey 和 Android 是我的目标平台。

我在任何地方都找不到这方面的直接例子。

【问题讨论】:

  • 您是否尝试渲染带纹理的四边形?除非有专门用于绘制现有纹理的 QML,否则它会变得非常简单。
  • 我删除了 C++ 标签。
  • 没有使用 Qt 的直接示例。这是一个有效的问题。

标签: qt qml textures qtopengl


【解决方案1】:

下面是一个旋转的 3D 立方体的 QML 演示,其面替换为 Texture png。

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick3D
Page {
    background: Rectangle { color: "#848895" }
    Node {
        id: standAloneScene
        DirectionalLight { ambientColor: Qt.rgba(1.0, 1.0, 1.0, 1.0) }
        Node {
            id: node
            Model {
                source: "#Cube"
                materials: [
                    DefaultMaterial {
                        diffuseMap: Texture {
                            sourceItem: Rectangle {
                                width: 256
                                height: 256
                                color: "#78a"
                                Image {
                                    anchors.centerIn: parent
                                    width: 224
                                    height: 224
                                    source: "https://stephenquan.github.io/images/qt/madewithqt.png"
                                }
                            }
                        }
                    }
                ]
            }
        }
        OrthographicCamera {
            id: cameraOrthographicFront
            lookAtNode: node
            y: 800; z: 1000
        }
    }
    View3D {
        anchors.fill: parent
        importScene: standAloneScene
        camera: cameraOrthographicFront
    }
    NumberAnimation {
        target: node
        property: "eulerRotation.y"
        loops: Animation.Infinite
        running: true
        from: 720; to: 0
        duration: 10000
    }
}

你可以Try it Online!

看:

【讨论】:

  • 没有“在线试用”吗? :)
  • 哈哈哈。你找到我了我确实尝试过,但是,我遇到了不支持 3D 纹理的 Web Assembly 的限制。
  • Qt6.4.2 web assembly 支持 3d 纹理。
猜你喜欢
  • 2019-04-02
  • 1970-01-01
  • 1970-01-01
  • 2012-03-14
  • 2013-12-27
  • 2013-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多