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. Dynamic texture with QOpenGLWidget gives black texture

Dynamic texture with QOpenGLWidget gives black texture

Scheduled Pinned Locked Moved Unsolved General and Desktop
openglqopenglwidgettexture2d
1 Posts 1 Posters 1.2k 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.
  • L Offline
    L Offline
    LudoJ49
    wrote on last edited by LudoJ49
    #1

    I want to draw an opengl quad with a dynamic texture. For now, I want the texture to be updated each time I render the scene. In the futur, I want to update it in a separate thread.

    I tried to use QOpenGLFramebufferObject and paint to it, but all I got is a black texture...

    Here is what I do :

    void QMyOpenGL::initializeGL()
    {
    	// in header: QOpenGLFramebufferObject* fbo;
    	fbo = new QOpenGLFramebufferObject(800, 800);
    }
    
    void QMyOpenGL::paintGL()
    {
    	glClearColor(255, 255, 255, 255);
    	glMatrixMode( GL_MODELVIEW );
    	glEnable(GL_TEXTURE_2D);
    	
    	
    	fbo->bind();
    		//Here, I want to paint my tecture Just try a red cross on a yellow background
    		QOpenGLPaintDevice device(fbo->size());
    		QPainter painter;
    		painter.begin(&device);
    			painter.fillRect(0, 0, fbo->width(), fbo->height(), QBrush(Qt::yellow));
    			painter.setPen(QPen(QBrush(Qt::red), 5));
    			painter.drawLine(0, 0, 800, 800);
    		painter.end();
    	fbo->release();
    
    	
    	glBindTexture(GL_TEXTURE_2D, fbo->texture());
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filterin
    
    	
    	//this is the quad I want the texture to
    	glBegin(GL_QUADS);
    		glTexCoord2i(0,0);       glVertex3d(1,1,1);
    		glTexCoord2i(1,0);       glVertex3d(1,1,-1);
    		glTexCoord2i(1,1);       glVertex3d(-1,1,-1);
    		glTexCoord2i(0,1);       glVertex3d(-1,1,1);
    	glEnd();
    	
    	glFlush();
    }
    

    Can anybody tell my what I am doing wront ?

    1 Reply Last reply
    1

    • Login

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