Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use the bindTexture() function outside of the QGLWidget children?



  • Hello!

    I have a class Scene:

    @class Scene : public QGLWidget
    {
    // ...
    void genTexture();
    // ...
    }

    void Scene::genTexture()
    {
    triangleTextureID = bindTexture( QPixmap( QString( ":Textures/Stub.jpg" ) ), GL_TEXTURE_2D );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
    }@

    And I have a class Triangle:
    @#ifndef TRIANGLE_H
    #define TRIANGLE_H

    // ...

    class Triangle
    {
    // ...
    }

    #endif // TRIANGLE_H@

    I want to move genTexture() to the class Triangle. How to use the bindTexture() function outside of the QGLWidget children?



  • Hi, not sure if it work have you tried to pass a "Scene" pointer to class Triangle??
    @#ifndef TRIANGLE_H
    #define TRIANGLE_H

    #include "scene.h"
    // ...

    class Triangle
    {
    private:
    Scene *m_scene;
    void genTexture(){m_scene->genTexture;}

    }@

    if not work try also to add m_scene->context()->makeCurrent(); before m_scene->genTexture();



  • Thank you! I will try it. But I cannot see a texture. I don't know where is mistake. Please, run my simple example from this theme: http://qt-project.org/forums/viewthread/50872/



  • unfortunately i can't help you with this, i've just started learning OpenGL v3.3 and i have also some problems... However in previous version you should try glEnable(GL_TEXTURE_2D); if you are in compatibly context it should work, don't know if still exist in new version of openGL...


Log in to reply