Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
examples [2007/06/08 14:08]
admin
examples [2007/10/24 11:23]
admin
Line 14: Line 14:
 ==== qgllogo.py ==== ==== qgllogo.py ====
  
-<​code>​+<​code ​python>
 import OpenGL.GL as ogl import OpenGL.GL as ogl
 import math import math
Line 36: Line 36:
     ogl.glEnd()     ogl.glEnd()
 </​code>​ </​code>​
 +
  
 ==== simpleViewer.py ==== ==== simpleViewer.py ====
  
-<​code>​+<​code ​python>
 from PyQt4.QtGui import * from PyQt4.QtGui import *
 from PyQGLViewer import * from PyQGLViewer import *
Line 54: Line 55:
 <​b>​Alt+Return</​b>​ for full screen mode and <​b>​Control+S</​b>​ to save a snapshot. ​ <​b>​Alt+Return</​b>​ for full screen mode and <​b>​Control+S</​b>​ to save a snapshot. ​
 See the <​b>​Keyboard</​b>​ tab in this window for a complete shortcut list.<​br><​br>​ See the <​b>​Keyboard</​b>​ tab in this window for a complete shortcut list.<​br><​br>​
-Double clicks automates single click actions: A left button double click aligns the closer axis with the camera (if close enough). ​ +Double clicks automates single click actions: A left button double click aligns ​ 
-A middle button double click fits the zoom of the camera and the right button re-centers the scene.<​br><​br>​ +the closer axis with the camera (if close enough). A middle button double click  
-A left button double click while holding right button pressed defines the camera <​i>​Revolve Around Point</​i>​. ​+fits the zoom of the camera and the right button re-centers the scene.<​br><​br>​ 
 +A left button double click while holding right button pressed defines the camera ​ 
 +<​i>​Revolve Around Point</​i>​.
 See the <​b>​Mouse</​b>​ tab and the documentation web pages for details.<​br><​br>​ See the <​b>​Mouse</​b>​ tab and the documentation web pages for details.<​br><​br>​
 Press <​b>​Escape</​b>​ to exit the viewer."""​ Press <​b>​Escape</​b>​ to exit the viewer."""​
Line 75: Line 78:
     viewer = Viewer()     viewer = Viewer()
     viewer.setWindowTitle("​simpleViewer"​)     viewer.setWindowTitle("​simpleViewer"​)
 +    viewer.show()
 +    qapp.exec_()
 +
 +if __name__ == '​__main__':​
 +    main()
 +</​code>​
 +
 +==== Result ====
 +
 +{{simpleviewer.png|}}
 +
 +
 +===== Texture 3D example =====
 +
 +A simple example with texture 3D.
 +
 +In the ''​init''​ method, four small Qimages are generated and filled each with an unique color. The 3D texture is then binded.
 +
 +In the ''​draw''​ method, a dynamic pyramid is drawn using texture 3D.
 +
 +The ''​animate''​ method updates the coordinates of the pyramid.
 +
 +
 +
 +
 +==== texture3D.py ====
 +
 +<code python>
 +from PyQt4.QtGui import *
 +from PyQGLViewer import *
 +import OpenGL.GL as ogl
 +import math
 +
 +helpstr = """<​h2>​T e x t u r e 3 D</​h2>​
 +An example to show how to build a 3D texture and apply it on a dynamic pyramid."""​
 +
 +class Viewer(QGLViewer):​
 +    def __init__(self,​parent = None):
 +        QGLViewer.__init__(self,​parent)
 +        self.center = [ 0.0,0.0,1.0 ]
 +        self.base = [[ -1.0, -1.0, 0.0 ], [-1.0, 1.0, 0.0], [1.0, 1.0, 0.0], [1.0, -1.0, 0.0]]
 +        self.time = 0.
 +    def animate(self):​
 +        self.center[2] = math.sin(self.time / 15.0) * 2.0
 +        self.time += 1
 +    def draw(self):
 +        if self.texname > 0:
 +            ogl.glBindTexture(ogl.GL_TEXTURE_3D,​ self.texname)
 +        ogl.glBegin(ogl.GL_TRIANGLES)
 +        # texture coordinates are always specified before the vertex they apply to.
 +        for x in range(4):
 +            ogl.glTexCoord3dv(self.center)
 +            ogl.glVertex3dv(self.center)
 +            ​
 +            ogl.glTexCoord3dv(self.base[x])
 +            ogl.glVertex3dv(self.base[x])
 +            ​
 +            ogl.glTexCoord3dv(self.base[(x+1)%4])
 +            ogl.glVertex3dv(self.base[(x+1)%4])
 +        ogl.glEnd()
 +    def init(self):
 +        self.restoreStateFromFile()
 +        self.help()
 +        imgs = [QImage(4,​4,​QImage.Format_ARGB32) for i in range(4)]
 +        imgs[0].fill(qRgb(128,​0,​0))
 +        imgs[1].fill(qRgb(0,​128,​0))
 +        imgs[2].fill(qRgb(0,​0,​128))
 +        imgs[3].fill(qRgb(128,​128,​128))
 +        self.texname = self.bindTexture3D(imgs)
 +        self.setSceneRadius(1)
 +        self.startAnimation()
 +    def helpString(self):​
 +        return helpstr
 +    def closeEvent(self,​event):​
 +        if self.texname > 0:
 +            ogl.glDeleteTextures(self.texname)
 +        QGLViewer.closeEvent(self,​event)
 +
 +def main():
 +    qapp = QApplication([])
 +    viewer = Viewer()
 +    viewer.setWindowTitle("​texture3D"​)
     viewer.show()     viewer.show()
     qapp.exec_()     qapp.exec_()
 
Back to top
examples.txt · Last modified: 2007/10/24 11:29 by admin
Valid CSS Driven by DokuWiki Valid XHTML 1.0