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. How to load OpenGLES texture from PNG file?
Forum Updated to NodeBB v4.3 + New Features

How to load OpenGLES texture from PNG file?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 1.8k 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.
  • D Offline
    D Offline
    Dmitriano
    wrote on last edited by Dmitriano
    #1

    And I am searching for a way how to create OpenGLES texture from PNG file, I need a method like this:

    	struct TextureInfo
    	{
    		//! The texture handle
    		GLuint Id;
    		//! The width of the texture
    		unsigned int Width;
    		//! The height of the texture
    		unsigned int Height;
    	};
    
    TextureInfo LoadTextureFromFile(GLenum target, GLint level, const Path & file_name)
    

    the function can use QT internally (there should not be QT Widgets dependency, only QT Quick), but the loaded texture is used with raw OpenGLES 2.0 calls (without QT). What is the proper way to implement it? Is it possible to use libPNG (compiled with QT) directly?

    The function should do something like this:

    GLuint texture;
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(image.width), static_cast<GLsizei>(image.height), 0,
        GL_RGBA, GL_UNSIGNED_BYTE, <???DATA???>);
    glGenerateMipmap(GL_TEXTURE_2D);
    
    
    1 Reply Last reply
    0
    • johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by
      #2

      You can check some tutorials I have here https://bitbucket.org/joaodeusmorgado/opengltutorials/src/83630ec69fce6c237f7a23367aa6859a2184a73f/T07_ImageTexture/?at=master
      This should compatible with OpenGLES, and could easily be used without widgets.
      Note that I'm using QImage to load the png, but it should be trivial to use some other image library if you want to.

      D 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Are you looking for something like described in the Textures Example ? i.e. QOpenGLTexture

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Are you looking for something like described in the Textures Example ? i.e. QOpenGLTexture

          D Offline
          D Offline
          Dmitriano
          wrote on last edited by
          #4

          @SGaist QOpenGLTexture is a good class but it does not have a 'detach' method, so I should keep its instance alive while I use the texture. Ideally I need only texture ID, width and height.

          1 Reply Last reply
          0
          • johngodJ johngod

            You can check some tutorials I have here https://bitbucket.org/joaodeusmorgado/opengltutorials/src/83630ec69fce6c237f7a23367aa6859a2184a73f/T07_ImageTexture/?at=master
            This should compatible with OpenGLES, and could easily be used without widgets.
            Note that I'm using QImage to load the png, but it should be trivial to use some other image library if you want to.

            D Offline
            D Offline
            Dmitriano
            wrote on last edited by
            #5

            @johngod Thank you! It works! You saved me a lot of time!

            1 Reply Last reply
            0

            • Login

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