4

I've been using the old Qt OpenGl methods but it was about time to switch to the newer ones.

being bitmap a FIBITMAP* properly initialized

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,0, GL_BGRA,GL_UNSIGNED_BYTE, (void*)FreeImage_GetBits(pImage));

worked like a charm for me.

But now in the newer methods it is preferred to use QOpenGLTexture

Unfortunatly my tries were unsucessful ie.

QOpenGLTexture*qtexture = new QOpenGLTexture(QOpenGLTexture::Target2D);

texture->setData(QOpenGLTexture::PixelFormat::RGBA, QOpenGLTexture::PixelType::Int8,FreeImage_GetBits(bitmap));

that code returns a 1x1 texture but also if I force the size like using

qtexture->setSize(width,height,4);

qtexture has the proper size but it is totally black, also I've tried to search in Qt/Freeimage forums etc but nothing related unfortunatly everyone uses QImage to feed QOpenGLTexture but unfortunatly I need to support some "strange" fileformats like .hdr or .exr that are not supported by Qt itself.

Thank you in advance for your time!

Frank Escobar
  • 368
  • 4
  • 20

2 Answers2

2

For a QOpenGLTexture, you have to set Size, Format before allocateStorage. The last step is setData.

QOpenGLTexture *text = new QOpenGLTexture(QOpenGLTexture::Target2D);
text->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear);
text->create();

// given some `width`, `height` and `data_ptr`
text->setSize(width, height, 1);
text->setFormat(QOpenGLTexture::RGBA8_UNorm);
text->allocateStorage();
text->setData(QOpenGLTexture::Red, QOpenGLTexture::UInt8, data_ptr);
Neil Z. Shao
  • 732
  • 1
  • 5
  • 12
0

qtexture->allocateStorage();

was the key!

Frank Escobar
  • 368
  • 4
  • 20