Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Make a texture with RGBA pixel format

Make a texture with RGBA pixel format

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.1k 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.
  • J Offline
    J Offline
    JesusM
    wrote on last edited by
    #1

    Hi all, I am trying to make a texture from a RGBA image, is the texture also in RGBA? I mean, i need pixels to be in RGBA format but there is not a function to set the pixel format.

    texture::texture(QVector<QString> rutas, QVector<TexturesTypes> tipo)
    {
        initializeOpenGLFunctions();
        for (int i = 0; i < rutas.size(); i++)
        {
            QString filename = rutas[i];
            TexturesTypes tipoTextura = tipo[i];
            QOpenGLTexture *texture = new QOpenGLTexture(QImage(filename).mirrored());
    
            if (texture == nullptr)
            {
                std::cout << filename.toStdString() << " cannot be loaded" << std::endl;
                return;
            }
    
            //Construimos la textura con las imágenes que queremos y la función de cada imagen
                
                    texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
                    texture->setMagnificationFilter(QOpenGLTexture::Linear);
                    texture->generateMipMaps();
                    texture->setWrapMode(QOpenGLTexture::DirectionS,QOpenGLTexture::ClampToEdge );
                    texture->setWrapMode(QOpenGLTexture::DirectionT,QOpenGLTexture::ClampToEdge );
           }
    }
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      QOpenGLTexture does not do format conversions. If you need a specific format don't use the QImage constructor. Instead use the other constructor, then allocate the storage in the format you need and transfer the data. Note that the uploaded data needs to be in the correct format already so you need to do the conversion beforehand.

      J 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        QOpenGLTexture does not do format conversions. If you need a specific format don't use the QImage constructor. Instead use the other constructor, then allocate the storage in the format you need and transfer the data. Note that the uploaded data needs to be in the correct format already so you need to do the conversion beforehand.

        J Offline
        J Offline
        JesusM
        wrote on last edited by JesusM
        #3

        @Chris-Kawa but I am not converting the format of the image. The image I am loading is a .png with RGBA so, does it save with that format in a QOpenGLTexture object or I have to do what you said even if the image has the format i want to?

        Edit: I suppose what you want me to do is something like that:
        0_1552853103651_Anotación 2019-03-17 210432.png

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What I'm saying is that when you use the QImage constructor the format of the texture is picked up automatically based on the format of that image. If you want to control the format of the texture you need to do it manually and provide the data in the correct format. If the image you have has the correct format already then you don't need any conversion.

          The example you posted is conceptually fine, but are those really the values you want? This would result in a RGB texture with 16 bit integer channels. That's not a very common thing and certainly not what a png file provides.

          J 1 Reply Last reply
          1
          • Chris KawaC Chris Kawa

            What I'm saying is that when you use the QImage constructor the format of the texture is picked up automatically based on the format of that image. If you want to control the format of the texture you need to do it manually and provide the data in the correct format. If the image you have has the correct format already then you don't need any conversion.

            The example you posted is conceptually fine, but are those really the values you want? This would result in a RGB texture with 16 bit integer channels. That's not a very common thing and certainly not what a png file provides.

            J Offline
            J Offline
            JesusM
            wrote on last edited by
            #5

            @Chris-Kawa Ok, I understand now.
            And no, these are not the values I want. It's and example I found of how to control the format.
            Thank you so much for helping! Now I know what I have to do.

            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