+ Reply to Thread
Results 1 to 6 of 6

Thread: How to display DDS images?

  1. #1

    Question 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

  2. #2
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    31,055
    Thanks
    3
    Thanked 4,662 Times in 4,464 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default 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.

  4. #4

    Default 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

    Qt Code:
    1. from PyQt4 import QtGui
    2. from PyQt4 import QtOpenGL
    3.  
    4. ddsPath = "C:/ddsImage.dds"
    5. pngPath = "C:/pngImage.png"
    6.  
    7. class Example(QtGui.QWidget):
    8. def __init__(self, parent=None):
    9. QtGui.QWidget.__init__(self, parent)
    10.  
    11. self.initUI()
    12.  
    13.  
    14. def initUI(self):
    15.  
    16. hbox = QtGui.QHBoxLayout(self)
    17. pixmap = QtGui.QPixmap(pngPath)
    18.  
    19. GL = QtOpenGL.QGLPixelBuffer(512, 512)
    20. GL_ID = GL.bindTexture(ddsPath)
    21. GL.makeCurrent()
    22. qimag = GL.toImage()
    23.  
    24. pixmap2 = QtGui.QPixmap.fromImage(qimag)
    25.  
    26. label = QtGui.QLabel(self)
    27. label.setPixmap(pixmap)
    28.  
    29. label2 = QtGui.QLabel(self)
    30. label2.setPixmap(pixmap2)
    31.  
    32. hbox.addWidget(label)
    33. hbox.addWidget(label2)
    34. self.setLayout(hbox)
    35.  
    36. self.setWindowTitle("DDS Test")
    37.  
    38.  
    39. app = QtGui.QApplication([])
    40. exm = Example()
    41. exm.show()
    42. app.exec_()
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    31,055
    Thanks
    3
    Thanked 4,662 Times in 4,464 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default 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?

  6. #6
    Join Date
    Jun 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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

    Qt Code:
    1. QImage readDDSFile(const QString &filename)
    2. {
    3. QGLWidget glWidget;
    4. glWidget.makeCurrent();
    5.  
    6. GLuint texture = glWidget.bindTexture(filename);
    7. if (!texture)
    8. return QImage();
    9.  
    10. // Determine the size of the DDS image
    11. GLint width, height;
    12. glBindTexture(GL_TEXTURE_2D, texture);
    13. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
    14. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
    15.  
    16. if (width == 0 || height == 0)
    17. return QImage();
    18.  
    19. QGLPixelBuffer pbuffer(QSize(width, height), glWidget.format(), &glWidget);
    20. if (!pbuffer.makeCurrent())
    21. return QImage();
    22.  
    23. pbuffer.drawTexture(QRectF(-1, -1, 2, 2), texture);
    24. return pbuffer.toImage();
    25. }
    To copy to clipboard, switch view to plain text mode 
    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.

+ Reply to Thread

Similar Threads

  1. How do I display a list of images?
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2007, 08:49
  2. Display Images in QGraphicsView
    By robertaandrews in forum Qt Tools
    Replies: 4
    Last Post: 15th May 2007, 18:35
  3. Is there any way to synchronize the display of images
    By kiransu123 in forum General Programming
    Replies: 2
    Last Post: 17th March 2007, 20:50
  4. Display animated images
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2007, 21:53
  5. How to display images in QTextBrowser ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 08:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts