Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Dynamic texture with QOpenGLWidget gives black texture

    General and Desktop
    opengl qopenglwidget texture2d
    1
    1
    960
    Loading More Posts
    • 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
      LudoJ49 last edited by LudoJ49

      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 Reply Quote 1
      • First post
        Last post