Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML and QOpengGL for printing images
Forum Updated to NodeBB v4.3 + New Features

QML and QOpengGL for printing images

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 247 Views
  • 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.
  • Q Offline
    Q Offline
    Quentin91
    wrote on 20 Aug 2019, 12:46 last edited by
    #1

    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);
    
    	 mp_shaderProgram->link();
    	mp_vao->create();
    	mp_vao->bind();
    
    			 //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
    			
    	mp_shaderProgram->bind();
    	mp_shaderProgram->release();
    	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);
    	else 
    		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);
    	else 
    		data = stbi_load("testPicture3.jpg", &w, &h, &channels, 0);
    
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	mp_shaderProgram->bind();
    	glBindTexture(GL_TEXTURE_2D, m_textureId);//la doc est moyenne mais de très bonnes explications par ici https://learnopengl.com/Getting-started/Textures
    	/***************************************************************************************************/
    	if (mp_data)
    	{
    		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, mp_data);
    	}
    	else
    	{
    		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
            }
    	/****************************************************************************************************/
    			
    	mp_shaderProgram->release();
    	/********************/
    	stbi_image_free(data);
    }
    
    1 Reply Last reply
    0

    1/1

    20 Aug 2019, 12:46

    • 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