Image support using OpenGL ES 3.0 on S32V234

  • Hello,

    Integrated Meta_QT5 in our S32V234 yocto environment.
    We are loading image ( PNG/JPEG etc) and applying texture using QT5.10 and OpenGL ES 3.0 APIs.
    But the image is not being displayed.
    Any pointers on this would be much appreciated.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are not giving enough details on how you implement that nor if you have that working on your desktop machine nor if you have anything OpenGL shown on your device.

  • Hello,

    Here are the code details,

    We are writing OpenGL ES 2.0 simple application of loading a texture(.png) on QT 5.10 using QOpenGLWidget.
    We are able to build and run in both Windows and Ubuntu version 16.04 Environment, but we are targetting the NXP S32V234 board.

    We have QT 5.10, OpenGL ES 2.0, Linux 4.19 version running on NXP S32V234 board, there it fails to load the texture. Pointers would be much appreciated.

    Here is the vertex and fragment shader code which are compiled using normal gl functions not the QT's addShaderFromSourceFile function.

    //Vertex Shader

    #ifdef GL_ES
    precision mediump int;
    precision mediump float;

    attribute vec3 position;
    attribute vec3 color;
    attribute vec2 texCoord;

    varying vec3 Color;
    varying vec2 TexCoord;

    uniform mat4 transform;

    void main()
    gl_Position = transform * vec4(position, 1.0);
    Color = color;
    TexCoord = texCoord;

    //Fragment Shader

    #ifdef GL_ES
    precision mediump int;
    precision mediump float;

    uniform sampler2D outputTexture;

    varying vec3 Color;
    varying vec2 TexCoord;

    void main()
    gl_FragColor = texture2D(outputTexture, TexCoord) * vec4(Color, 1.0);

    Here is the initialization and loading of texture

    void MyGL::initializeTextureBuffer()
    float vertices[] = {
    // positions // texture coords
    0.0f, 0.3f, 0.0f, 1.0f,0.0f,0.0f, 0.0f, 0.0f, // bottom left /* @pixel (35,57)
    0.0f, 0.6f, 0.0f,0.0f,1.0f,0.0f, 0.0f, 1.0f, // top left @pixel (35,27)
    0.5f, 0.6f, 0.0f,0.0f,0.0f,1.0f, 1.0f, 1.0f, // top right @pixel (76,27)
    0.5f, 0.3f, 0.0f, 1.0f,1.0f,1.0f, 1.0f, 0.0f, // bottom right @pixel (76,57) */

                glGenBuffers(1, &camTextureBufferObject);
                glBindBuffer(GL_ARRAY_BUFFER, camTextureBufferObject);
                glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
                glBindBuffer(GL_ARRAY_BUFFER, 0); //unbinding
                textureQT = loadTexture(":/images/images/CamRedA.PNG");


    QOpenGLTexture* MyGL::loadTexture(const char * path)
    QOpenGLTexture* texture;
    texture = new QOpenGLTexture(QImage(path).mirrored());
    return texture;

    Here is the main render loop

    void MyGL::paintGL()
    glClearColor(0.0f, 0.0f, 0.0f, 0.05f);

                ///********************************* Texture Rendering ********************************************************/
                glm::mat4 projection = glm::perspective(glm::radians(camspec.fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
                glm::mat4 view = glm::lookAt(camspec.cameraPos, camspec.cameraPos + camspec.cameraFront, camspec.cameraUp);
                glm::mat4 model = glm::mat4(1.0f);
                glm::mat4 transform = projection * view * model;
                glUniformMatrix4fv(glGetUniformLocation(shaderpgmTexture, "transform"), 1, false, &transform[0][0]);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                glUniform1i(glGetUniformLocation(shaderpgmTexture, "outputTexture"), 0);
                glBindBuffer(GL_ARRAY_BUFFER, camTextureBufferObject);
                // position attribute
                GLint vertexLocation = glGetAttribLocation(shaderpgmTexture,"position");
                glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
                // color
                GLint colorLocation = glGetAttribLocation(shaderpgmTexture, "color");
                glVertexAttribPointer(colorLocation, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
                // texture coord attribute
                GLint vertexTex = glGetAttribLocation(shaderpgmTexture, "texCoord");
                glVertexAttribPointer(vertexTex, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
                glDrawArrays(GL_QUADS, 0, 4);
                /********************************* Texture Rendering - End ********************************************************/


Log in to reply