View Full Version : How to display DDS images?
jamsession
17th April 2010, 03:07
Hey guys, I have been surfing these boards for while and figured I should finally join and contribute to the community :)
I am hoping this is a trivial issue for someone out there.
I have a ton of .dds images I want to create a simple thumbnail viewer for. I have tried QImage and Pixmap, but none of those currently support .dds file types. I know openGL, and QtOpenGL does, but will I need to create a Plane to apply an image to it? Is there a way to just display a .dds that I am overlooking? Does anyone have a simple example using .dds files?
Any help or direction is greatly appreciated,
Thanks
JAM
minimoog
19th April 2010, 08:21
DDS it's not image, it's a collection of texture images (1D, 2D, 3D, cubemap texture) with optional all mipmapping levels. And how do you show cubemap texture like a image?
But, there are tons of DDS loader on the internet, and you can "ripoff" code from QtOpenGL.
wysota
19th April 2010, 08:54
Write the texture into QGLPixelBuffer and then use QGLPixelBuffer::toImage() to write it to an image. Note that you may have to switch colour channels afterwards.
jamsession
19th April 2010, 21:25
Thanks guys for your help. Unfortunately I still can't get it to display anything.
Is the proper way to specify a "bindTexture" then convert it with "toImage"?
Obviously the png works great, but the dds isn't displaying anything.
Thanks Guys
JAM
from PyQt4 import QtGui
from PyQt4 import QtOpenGL
ddsPath = "C:/ddsImage.dds"
pngPath = "C:/pngImage.png"
class Example(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.initUI()
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
pixmap = QtGui.QPixmap(pngPath)
GL = QtOpenGL.QGLPixelBuffer(512, 512)
GL_ID = GL.bindTexture(ddsPath)
GL.makeCurrent()
qimag = GL.toImage()
pixmap2 = QtGui.QPixmap.fromImage(qimag)
label = QtGui.QLabel(self)
label.setPixmap(pixmap)
label2 = QtGui.QLabel(self)
label2.setPixmap(pixmap2)
hbox.addWidget(label)
hbox.addWidget(label2)
self.setLayout(hbox)
self.setWindowTitle("DDS Test")
app = QtGui.QApplication([])
exm = Example()
exm.show()
app.exec_()
wysota
19th April 2010, 21:35
Correct me if I'm wrong but don't you have to use the GL_ARB_texture_compression extension or the glCompressedTexImage2D() function to load the compressed texture?
bjorn
12th June 2013, 22:18
I know this discussion is somewhat old, but I originally found it while looking for a way to load a DDS image in Qt. I figured out one way to do it eventually so if anybody else comes here looking for the answer, there it is:
https://gist.github.com/bjorn/4635382
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();
}
For information on the supported formats see http://qt-project.org/doc/qt-4.8/qglcontext.html#bindTexture-2.
The main problem with the code snippet above is that it didn't actually draw the texture to the pixel buffer.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.