Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How pass an array from qml to opengl Shader
Qt 6.12 LTS is out! See what's new in the release blog

How pass an array from qml to opengl Shader

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlopenglgslarray
1 Posts 1 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simkat82
    wrote on last edited by
    #1

    Hello Everyone,

    I'm trying to paint a polygon on a map, using QML + Opengl.
    I can paint everything I want but, using QML, I don't find any solutions to pass an array of colors as a propriety of my Shaders: the array is correctly initialized in my app, but there is no way to pass it to opengl program.

    In "square.vert" I tried to define something like:
    attribute float sArray[ELEMENT]; // sArray is the proprity correctly defined in qml container

    Can anyone help me? Is there another way to pass a int[] o float[] to openGl scripts?

    Thanks in advance,

    Simone

    ShaderEffect {
        width: parent.width
        height: width
        blending: true
        property vector2d u_viewport_resolution : Qt.vector2d(width*1.0, height*1.0)
        **property variant qmlArray: externArray**
        property bool quant: true
        property int cellColor: externcellColor
        vertexShader:"qrc:/square.vert"
        fragmentShader: "qrc:/clutter.frag"
    }
    
    function vector_initialize()
    {
        console.log("vector_initialize");
        var colorIndex = 0;
        for (var i = 0; i < 11520; ++i ) {
    
            externArray[i]= 3.;//colorIndex;
            colorIndex = colorIndex +1;
    
            if (colorIndex == 5 )
                colorIndex = 0;
    
        }
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved