Important: Please read the Qt Code of Conduct -

QML and QOpengGL for printing images

  • Hi ! I'm not very experienced with Qt and completely new to OpenGL so I'm confused.
    I need to show images in an OpenGL texture using a FBO, which works when I get the picture from my files with stbi.

    But the image has to come from the sharedMemory. So my code is splitted in two different clusters :
    One for getting the data from the sharedMemory using a thread that refresh the data periodically and has a structure containing a QOpenGLBuffer and a QOpenGLTexture

    struct ImageSinkOpenglTextureData
    	QOpenGLTexture* m_glTexture;
    	int m_iWidth;
    	int m_iHeight;
    	QOpenGLBuffer* m_pboIds[2];
    	int m_currentPboId;

    Another that creates the geometry of the texture, that implements a QQuickFamebufferObject and a Renderer.

    But both of these class clusters are instanciated by the QML thanks to

    qmlRegisterType<imageSourceObject>("Pegase", 1, 0, "ImageSource");
    qmlRegisterType<TextureViewObject>("Pegase", 1, 0, "TextureViewObject");

    And I have no clue on how to give the image from the classs that manage the QSharedMemory to the class that can print the data.
    Do I have to use a FBO ? I've seen that we can access to a FBO thanks to an id. But how ? Or maybe I can send a signal containing the pointer to the data to the printer ? i tried but it didn't work I could try again ?

    This is where I print the data. i'm not sure about what code to show. The first method is the initialisation of the shader, vao...

    void TextureViewRenderer::initialize(void)
    	QOpenGLShader m_shader(QOpenGLShader::Vertex);
    	 mp_shaderProgram= new QOpenGLShaderProgram(QOpenGLContext::currentContext());
    	 mp_shaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ConstantView::VS_FILE_PATH);//test, mais faudra mettre la valeur constant
    	mp_shaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ConstantView::FS_FILE_PATH);
    			 //init of the vertices table
    	float w_vertices[VERTICES_SIZE];
    			 //parcours les deux tableaux selon la longueur du plus petit au cas ou il y ait un écart (ce que serait anormal)
    	for (size_t i = 0; i < (std::min(sizeof(ConstantView::DEFAULT_VERTICES), sizeof(w_vertices)) / sizeof(float)); ++i)
    		 w_vertices[i] = ConstantView::DEFAULT_VERTICES[i];
    	float w_texc[12] = { get_uMin(), get_vMax(), get_uMax(), get_vMax(), get_uMin(), get_vMin(), get_uMax(), get_vMin() };
    	QString w_tmpStr("texCoord");
    	mp_vao->release();//donc on bien set le vertex data state là
    	QMatrix4x4 w_pmvMatrix;
    	w_pmvMatrix.ortho(0,1,0,1,0,1);//ça change rien quand on change la valeur
    	cout << "TextureViewRenderer textureId " << m_textureId << endl;

    And this one prints the images I want

    void TextureViewRenderer::textureRendering(void)
    	if (m_uvDirty)
    		TRACE_DEBUG("TextureViewRenderer::textureRendering m_ubDirty TRUE")
    		m_uvDirty = false;				
    	//nettoie les couleurs de la frame précédente pour préparer la prochaine
    	if (m_textureId == 0) 
    		//glClearColor(float(++r%10)/10, float(++g % 10) / 10, float(++b % 10) / 10, float(++a % 10) / 10);
    		glClearColor(0, 0, 0, 1);//PANO
    	else if(m_textureId==1)
    		glClearColor(1, 1, 0, 1);//petit ROI du milieu
    	else if(m_textureId==2)
    		glClearColor(0, 0, 1, 1);
    		glClearColor(1, 0, 0, 1);
    récupération de l'image test avec stb_image */
    	int w = 12, h = 12, channels = 3;
    	unsigned char* data;
    	if (m_textureId == 1)
    		data = stbi_load("testPicture2.jpg", &w, &h, &channels,0);
    	else if(m_textureId == 3)
    		data = stbi_load("testPicturePano.jpg", &w, &h, &channels, 0);
    		data = stbi_load("testPicture3.jpg", &w, &h, &channels, 0);
    	glBindTexture(GL_TEXTURE_2D, m_textureId);//la doc est moyenne mais de très bonnes explications par ici
    	if (mp_data)
    		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, mp_data);
    		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

Log in to reply