Hello all,

I am having some trouble loading a dds file into PyQt for displaying in a 
window. 

I have dug around and I keep being pointed towards OpenGL.GL and QtOpenGL. 
I found a function on tech artists forum 
http://tech-artists.org/forum/showthread.php?5196-Simple-DDS-loader that 
supposedly returns a Qimage from a dds filepath but when the function tries 
to bind the texture it fails instantly or returns 0. Am I missing a step 
before trying to bind the image?

I have also tried a custom fucntion earlier using QtOpenGL but I have had 
no luck so far

There doesn't seem to be a huge amount of info out there on this so 
hopefully someone on here can help shine a light!

The code is below to ilustrate my issue:

import osimport sysfrom PyQt4 import QtGui, QtCorefrom PyQt4.QtOpenGL import 
*from OpenGL.GL import * class ShaderCoordWindow(QtGui.QDialog): def 
__init__(self): QtGui.QDialog.__init__(self) global coordWindow coordWindow 
= QtGui.QDialog() coordWindow.resize(512, 512) 
coordWindow.setWindowTitle("Objects 
to skin") coordWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) testDDS 
= r'D:\\test.dds' testJPG = r'D:\\test_jpg.jpg' jpgPixMap = 
QtGui.QPixmap(testJPG) qFileDDS = fileDDS(testDDS) testImg = 
QtGui.QPixmap.fromImage(qFileDDS._qImage) imageLabel = 
QtGui.QLabel(coordWindow) imageLabel.setPixmap(testImg) layout = 
QtGui.QHBoxLayout() layout.addWidget(imageLabel) 
coordWindow.setLayout(layout) coordWindow.show() 
############################################################################# 
DDS file readerclass fileDDS(object): """This class represnts a generic DDS 
file as a QImage""" #global gDebug # 
--BASE-METHODS------------------------------------------------------- # 
--constructor- def __init__(self, filePath=None): self._filePath = None 
self._width 
= int(0) self._height = int(0) self._qImage = None if filePath != None: 
self._filePath 
= filePath self._qImage = self.readDDSFile(self._filePath) # 
--method------------------------------------------------------------- def 
readDDSFile(self, filePath=None): print 'reading', filePath glWidget = 
QGLWidget() glWidget.makeCurrent() texture = 
glWidget.bindTexture(QtCore.QString(filePath)) if not texture: print 'not 
textures' return QtGui.QImage() # Determine the size of the DDS image 
glBindTexture(GL_TEXTURE_2D, texture) self._width = 
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH) self._height = 
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT) if self._width 
== 0 and self._height == 0: print 'width and height nothing' return 
QtGui.QImage() pbuffer = QGLPixelBuffer(QtCore.QSize(self._width, 
self._height), 
glWidget.format()) if not pbuffer.makeCurrent(): print 'no pbuffer' return 
QtGui.QImage() pbuffer.drawTexture(QtCore.QRectF(-1, -1, 2, 2), texture) 
return pbuffer.toImage() def run(): app = QtGui.QApplication(sys.argv) 
ShaderCoordWindow() sys.exit(app.exec_()) run()

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/bcd4e529-5ec1-4fac-9ec2-957e0badf7c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to