Skip to content

Instantly share code, notes, and snippets.

@bjorn
Last active September 12, 2016 12:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjorn/4635382 to your computer and use it in GitHub Desktop.
Save bjorn/4635382 to your computer and use it in GitHub Desktop.
Loading a DDS to a QImage using QGLPixelBuffer.
QImage readDDSFile(const QString &filename)
{
QGLWidget glWidget;
glWidget.makeCurrent();
GLuint texture = glWidget.bindTexture(filename);
if (!texture)
return QImage();
// Determine the size of the DDS image
GLint width, height;
glBindTexture(GL_TEXTURE_2D, texture);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
if (width == 0 || height == 0)
return QImage();
QGLPixelBuffer pbuffer(QSize(width, height), glWidget.format(), &glWidget);
if (!pbuffer.makeCurrent())
return QImage();
pbuffer.drawTexture(QRectF(-1, -1, 2, 2), texture);
return pbuffer.toImage();
}
@bjorn
Copy link
Author

bjorn commented Sep 12, 2016

Note: better just use the DDS image plugin shipping with Qt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment