How to display DDS images?
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
Re: How to display DDS images?
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.
Re: How to display DDS images?
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.
Re: How to display DDS images?
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
Code:
from PyQt4 import QtGui
from PyQt4 import QtOpenGL
ddsPath = "C:/ddsImage.dds"
pngPath = "C:/pngImage.png"
def __init__(self, parent=None):
QtGui.
QWidget.__init__
(self, parent
)
self.initUI()
def initUI(self):
GL_ID = GL.bindTexture(ddsPath)
GL.makeCurrent()
qimag = GL.toImage()
pixmap2
= QtGui.
QPixmap.
fromImage(qimag
)
label.setPixmap(pixmap)
label2.setPixmap(pixmap2)
hbox.addWidget(label)
hbox.addWidget(label2)
self.setLayout(hbox)
self.setWindowTitle("DDS Test")
exm = Example()
exm.show()
app.exec_()
Re: How to display DDS images?
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?
Re: How to display DDS images?
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
Code:
{
glWidget.makeCurrent();
GLuint texture = glWidget.bindTexture(filename);
if (!texture)
// 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)
if (!pbuffer.makeCurrent())
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/qgl...#bindTexture-2.
The main problem with the code snippet above is that it didn't actually draw the texture to the pixel buffer.