Last active
September 12, 2016 12:40
-
-
Save bjorn/4635382 to your computer and use it in GitHub Desktop.
Loading a DDS to a QImage using QGLPixelBuffer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: better just use the DDS image plugin shipping with Qt!