Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem using glTexSubImage2D with QOpenGLWidget
Forum Updated to NodeBB v4.3 + New Features

Problem using glTexSubImage2D with QOpenGLWidget

Scheduled Pinned Locked Moved General and Desktop
openglwidgettexture
1 Posts 1 Posters 1.1k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    mbaa
    wrote on 15 Jun 2015, 13:34 last edited by mbaa
    #1

    Hello,
    I'm trying to Display a texture within a QOpenGlWidget in a QMainWindow.
    For that I made a class which derived from QopenGlWidget and my corresponding widget is promoted to use that class.

    class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
    {
        Q_OBJECT
    ...
    }
    
    

    My plan is to first initlialize the texture once in the initializeGL() method, then use the texture id in the paintGL() method and only update it with glTexSubImage2D().

    GLWidget::initializeGL()
    {
    ...
      glTexImage2D(...);
    ...
    }
    GLWidget::paintGL()
    {
    ...
       glTexSubImage2D(...);
    ...
    }
    

    This works ONLY if I use glTexImage() right before glTexSubImage2D() in the paintGL() method . Otherwise the texture won't be drawn.
    I think there is a problem with the drawing context. But I cannot figure it out.
    Any idea is appreciated.
    Thank you.

    EDIT:
    I set the new texture from the outside with a the method void setTexture(...);
    This method also calls update() to repaint the widget.
    Is it possible that calling this method from an outside thread causes the texture to render in another context?

    EDIT 2:
    I tried to set a shared context in the painGl() method. I used the context which was used in the initializeGL() method. Also, I tried do make the context from initializeGL() the current context while drawing in painGL(). Again same result. Here are my OpenGL functions for creating the texture:

    //Works when used in paintGl().
    glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, m_cvImage.cols, m_cvImage.rows,0, GL_BGR, GL_UNSIGNED_BYTE, m_cvImage.data);
    
    //Not working when used in paintGl() if glTexImage2D is used to create the texture in initializeGl().
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_cvImage.cols, m_cvImage.rows, GL_BGR,, GL_UNSIGNED_BYTE, m_cvImage.data);
    
    //Also working in paintGL()
    glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, m_cvImage.cols, m_cvImage.rows,0, GL_BGR, GL_UNSIGNED_BYTE, NULL);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_cvImage.cols, m_cvImage.rows, GL_BGR, GL_UNSIGNED_BYTE, m_cvImage.data);
    

    When I try to call makeCurrent() in the paintGL() method (even if it should be called automatically right before) I get an Assertion:

    ASSERT: "context" in file opengl\qopenglfunctions.cpp, line 209
    

    The same applies to the doneCurrent() method (just for testing).
    This tells me that there is no available context for the paintGL() method.
    Yet a check with:

    if (context() == 0)...
    

    Seems to be fine.

    1 Reply Last reply
    0

    1/1

    15 Jun 2015, 13:34

    • Login

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