Dynamic texture with QOpenGLWidget gives black texture

  • 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 );
    		//Here, I want to paint my tecture Just try a red cross on a yellow background
    		QOpenGLPaintDevice device(fbo->size());
    		QPainter painter;
    			painter.fillRect(0, 0, fbo->width(), fbo->height(), QBrush(Qt::yellow));
    			painter.setPen(QPen(QBrush(Qt::red), 5));
    			painter.drawLine(0, 0, 800, 800);
    	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
    		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);

    Can anybody tell my what I am doing wront ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.