Re: [PyQt] Help about the use of OpenGL with PyQt

2009-04-06 Thread projetmbc

Thanks a lot.
I will look at that but it seems that there is no Windows version for 
Python 2-6.


Christophe.

There are also the QGLViewer/PyQGLViewer  couple.
Basically QGLViewer is build on top of the Qt4 OpenGL widget and 
PyQGLViewer is its python bindings.


http://www.libqglviewer.com/
http://pyqglviewer.gforge.inria.fr/wiki/doku.php

bye
Gianluca


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Help about the use of OpenGL with PyQt

2009-04-05 Thread projetmbc

That seems to be very good.

Thanks a lot.
Christophe


David Boddie a écrit :

On Sat Apr 4 17:43:29 BST 2009, Jamie Riotto wrote:

  

OpenGL Tutorial:
http://cs.uccs.edu/~semwal/indexGLTutorial.html

Also NeHe productions does a realy great job breaking down OpenGL into
lessons: My favorite!
http://nehe.gamedev.net/

Also, since your accessing OpenGL through PyOpenGL, you should look at:
http://pyopengl.sourceforge.net/documentation/

for other links and examples. Enjoy - jaime



Another good source of information is the Red Book. You can find an old
version online here:

http://www.opengl.org/documentation/red_book/

Although it only covers OpenGL 1.1, it should contain all the basic
information you need to help you get started.

David
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
 



  



___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Help about the use of OpenGL with PyQt

2009-04-05 Thread duncan duncan
On Sat, Apr 4, 2009 at 6:43 PM, Jamie Riotto jamie.rio...@gmail.com wrote:

 OpenGL Tutorial:
 http://cs.uccs.edu/~semwal/indexGLTutorial.htmlhttp://cs.uccs.edu/%7Esemwal/indexGLTutorial.html

 Also NeHe productions does a realy great job breaking down OpenGL into
 lessons: My favorite!
 http://nehe.gamedev.net/

 Also, since your accessing OpenGL through PyOpenGL, you should look at:
 http://pyopengl.sourceforge.net/documentation/

 for other links and examples. Enjoy - jaime



There are also the QGLViewer/PyQGLViewer  couple.
Basically QGLViewer is build on top of the Qt4 OpenGL widget and PyQGLViewer
is its python bindings.

http://www.libqglviewer.com/
http://pyqglviewer.gforge.inria.fr/wiki/doku.php

bye
Gianluca
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Help about the use of OpenGL with PyQt

2009-04-04 Thread projetmbc

Hello,
I would like to draw for example a 3D triangle with OpenGL. I've tried to play 
with the example Hello GL proposed by PyQt.

In the following code I would like to draw a red triangle and then a blue one. 
I also would like to set the xMin, xMax, yMin, yMax, zMin, zMax, for the point 
of view. My purpose would be to a 3D geometric viewers for educational purposes.

Best regards.
Christophe


The code


#!/usr/bin/env python

PyQt4 port of the opengl/hellogl example from Qt v4.x

import sys
import math
from PyQt4 import QtCore, QtGui, QtOpenGL

try:
   from OpenGL import GL
except ImportError:
   app = QtGui.QApplication(sys.argv)
   QtGui.QMessageBox.critical(None, OpenGL hellogl,
   PyOpenGL must be installed to run this example.,
   QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default,
   QtGui.QMessageBox.NoButton)
   sys.exit(1)


class Window(QtGui.QWidget):
   def __init__(self, parent=None):
   QtGui.QWidget.__init__(self, parent)

   self.glWidget = GLWidget()

   self.xSlider = self.createSlider(QtCore.SIGNAL(xRotationChanged(int)),
self.glWidget.setXRotation)
   self.ySlider = self.createSlider(QtCore.SIGNAL(yRotationChanged(int)),
self.glWidget.setYRotation)
   self.zSlider = self.createSlider(QtCore.SIGNAL(zRotationChanged(int)),
self.glWidget.setZRotation)

   mainLayout = QtGui.QHBoxLayout()
   mainLayout.addWidget(self.glWidget)
   mainLayout.addWidget(self.xSlider)
   mainLayout.addWidget(self.ySlider)
   mainLayout.addWidget(self.zSlider)
   self.setLayout(mainLayout)

   self.xSlider.setValue(15 * 16)
   self.ySlider.setValue(345 * 16)
   self.zSlider.setValue(0 * 16)

   self.setWindowTitle(self.tr(Hello GL))

   def createSlider(self, changedSignal, setterSlot):
   slider = QtGui.QSlider(QtCore.Qt.Vertical)

   slider.setRange(0, 360 * 16)
   slider.setSingleStep(16)
   slider.setPageStep(15 * 16)
   slider.setTickInterval(15 * 16)
   slider.setTickPosition(QtGui.QSlider.TicksRight)

   self.glWidget.connect(slider, QtCore.SIGNAL(valueChanged(int)), 
setterSlot)
   self.connect(self.glWidget, changedSignal, slider, 
QtCore.SLOT(setValue(int)))

   return slider


class GLWidget(QtOpenGL.QGLWidget):
   def __init__(self, parent=None):
   QtOpenGL.QGLWidget.__init__(self, parent)

   self.object = 0
   self.xRot = 0
   self.yRot = 0
   self.zRot = 0

   self.lastPos = QtCore.QPoint()

   self.trolltechGreen = QtGui.QColor.fromCmykF(0.40, 0.0, 1.0, 0.0)
   self.trolltechPurple = QtGui.QColor.fromCmykF(0.39, 0.39, 0.0, 0.0)

   def xRotation(self):
   return self.xRot

   def yRotation(self):
   return self.yRot

   def zRotation(self):
   return self.zRot

   def minimumSizeHint(self):
   return QtCore.QSize(50, 50)

   def sizeHint(self):
   return QtCore.QSize(400, 400)

   def setXRotation(self, angle):
   angle = self.normalizeAngle(angle)
   if angle != self.xRot:
   self.xRot = angle
   self.emit(QtCore.SIGNAL(xRotationChanged(int)), angle)
   self.updateGL()

   def setYRotation(self, angle):
   angle = self.normalizeAngle(angle)
   if angle != self.yRot:
   self.yRot = angle
   self.emit(QtCore.SIGNAL(yRotationChanged(int)), angle)
   self.updateGL()

   def setZRotation(self, angle):
   angle = self.normalizeAngle(angle)
   if angle != self.zRot:
   self.zRot = angle
   self.emit(QtCore.SIGNAL(zRotationChanged(int)), angle)
   self.updateGL()

   def initializeGL(self):
   self.qglClearColor(self.trolltechPurple.dark())
   self.object = self.makeObject()
   GL.glShadeModel(GL.GL_FLAT)
   GL.glEnable(GL.GL_DEPTH_TEST)
   GL.glEnable(GL.GL_CULL_FACE)

   def paintGL(self):
   GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
   GL.glLoadIdentity()
   GL.glTranslated(0.0, 0.0, -10.0)
   GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
   GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
   GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
   GL.glCallList(self.object)

   def resizeGL(self, width, height):
   side = min(width, height)
   GL.glViewport((width - side) / 2, (height - side) / 2, side, side)

   GL.glMatrixMode(GL.GL_PROJECTION)
   GL.glLoadIdentity()
   GL.glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0)
   GL.glMatrixMode(GL.GL_MODELVIEW)

   def mousePressEvent(self, event):
   self.lastPos = QtCore.QPoint(event.pos())

   def mouseMoveEvent(self, event):
   dx = event.x() - self.lastPos.x()
   dy = event.y() - self.lastPos.y()

   if event.buttons()  QtCore.Qt.LeftButton:
   self.setXRotation(self.xRot + 8 * dy)
   

Re: [PyQt] Help about the use of OpenGL with PyQt

2009-04-04 Thread Jamie Riotto
Christophe,
Your problem is with your OpenGL syntax. Simply change GL.GL_QUADS (which
draw quadrilaterals) with
GL.GL_TRIANGLES (self evident). Also, it would be better to move those
declarations into your triangle routine as follows:

  def triangle(self, x1, y1, z1, x2, y2, z2, x3, y3, z3,r,g,b):
  self.qglColor(QtGui.QColor(r,g,b))
  GL.glBegin(GL.GL_TRIANGLES)
  GL.glVertex3d(x1, y1, z1)
  GL.glVertex3d(x2, y2, z2)
  GL.glVertex3d(x3, y3, z3)
  GL.glEnd()

This way, each glBegin is guaranteed to have a closing glEnd.
I believe it now works as you would expect...
Cheers - jamie
On Sat, Apr 4, 2009 at 9:04 AM, projetmbc projet...@club-internet.frwrote:

 Hello,
 I would like to draw for example a 3D triangle with OpenGL. I've tried to
 play with the example Hello GL proposed by PyQt.

 In the following code I would like to draw a red triangle and then a blue
 one. I also would like to set the xMin, xMax, yMin, yMax, zMin, zMax, for
 the point of view. My purpose would be to a 3D geometric viewers for
 educational purposes.

 Best regards.
 Christophe

 
 The code
 

 #!/usr/bin/env python

 PyQt4 port of the opengl/hellogl example from Qt v4.x

 import sys
 import math
 from PyQt4 import QtCore, QtGui, QtOpenGL

 try:
   from OpenGL import GL
 except ImportError:
   app = QtGui.QApplication(sys.argv)
   QtGui.QMessageBox.critical(None, OpenGL hellogl,
   PyOpenGL must be installed to run this
 example.,
   QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default,
   QtGui.QMessageBox.NoButton)
   sys.exit(1)


 class Window(QtGui.QWidget):
   def __init__(self, parent=None):
   QtGui.QWidget.__init__(self, parent)

   self.glWidget = GLWidget()

   self.xSlider =
 self.createSlider(QtCore.SIGNAL(xRotationChanged(int)),
self.glWidget.setXRotation)
   self.ySlider =
 self.createSlider(QtCore.SIGNAL(yRotationChanged(int)),
self.glWidget.setYRotation)
   self.zSlider =
 self.createSlider(QtCore.SIGNAL(zRotationChanged(int)),
self.glWidget.setZRotation)

   mainLayout = QtGui.QHBoxLayout()
   mainLayout.addWidget(self.glWidget)
   mainLayout.addWidget(self.xSlider)
   mainLayout.addWidget(self.ySlider)
   mainLayout.addWidget(self.zSlider)
   self.setLayout(mainLayout)

   self.xSlider.setValue(15 * 16)
   self.ySlider.setValue(345 * 16)
   self.zSlider.setValue(0 * 16)

   self.setWindowTitle(self.tr(Hello GL))

   def createSlider(self, changedSignal, setterSlot):
   slider = QtGui.QSlider(QtCore.Qt.Vertical)

   slider.setRange(0, 360 * 16)
   slider.setSingleStep(16)
   slider.setPageStep(15 * 16)
   slider.setTickInterval(15 * 16)
   slider.setTickPosition(QtGui.QSlider.TicksRight)

   self.glWidget.connect(slider, QtCore.SIGNAL(valueChanged(int)),
 setterSlot)
   self.connect(self.glWidget, changedSignal, slider,
 QtCore.SLOT(setValue(int)))

   return slider


 class GLWidget(QtOpenGL.QGLWidget):
   def __init__(self, parent=None):
   QtOpenGL.QGLWidget.__init__(self, parent)

   self.object = 0
   self.xRot = 0
   self.yRot = 0
   self.zRot = 0

   self.lastPos = QtCore.QPoint()

   self.trolltechGreen = QtGui.QColor.fromCmykF(0.40, 0.0, 1.0, 0.0)
   self.trolltechPurple = QtGui.QColor.fromCmykF(0.39, 0.39, 0.0, 0.0)

   def xRotation(self):
   return self.xRot

   def yRotation(self):
   return self.yRot

   def zRotation(self):
   return self.zRot

   def minimumSizeHint(self):
   return QtCore.QSize(50, 50)

   def sizeHint(self):
   return QtCore.QSize(400, 400)

   def setXRotation(self, angle):
   angle = self.normalizeAngle(angle)
   if angle != self.xRot:
   self.xRot = angle
   self.emit(QtCore.SIGNAL(xRotationChanged(int)), angle)
   self.updateGL()

   def setYRotation(self, angle):
   angle = self.normalizeAngle(angle)
   if angle != self.yRot:
   self.yRot = angle
   self.emit(QtCore.SIGNAL(yRotationChanged(int)), angle)
   self.updateGL()

   def setZRotation(self, angle):
   angle = self.normalizeAngle(angle)
   if angle != self.zRot:
   self.zRot = angle
   self.emit(QtCore.SIGNAL(zRotationChanged(int)), angle)
   self.updateGL()

   def initializeGL(self):
   self.qglClearColor(self.trolltechPurple.dark())
   self.object = self.makeObject()
   GL.glShadeModel(GL.GL_FLAT)
   GL.glEnable(GL.GL_DEPTH_TEST)
   GL.glEnable(GL.GL_CULL_FACE)

   def paintGL(self):
   GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
   GL.glLoadIdentity()
   GL.glTranslated(0.0, 0.0, -10.0)
   GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
   GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
   

Re: [PyQt] Help about the use of OpenGL with PyQt

2009-04-04 Thread projetmbc
 Your problem is with your OpenGL syntax. Simply change GL.GL_QUADS 
(which draw quadrilaterals) with GL.GL_TRIANGLES (self evident). Also, 
it would be better to move those declarations into your triangle routine 
as follows


Thanks and sorry for this simple problem but I'm a real newbie with OpenGL.

Where can I find documentations showing what kind of objects I can draw 
with OpenGL ?


Best regards and thanks a lot.



___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Help about the use of OpenGL with PyQt

2009-04-04 Thread Jamie Riotto
OpenGL Tutorial:
http://cs.uccs.edu/~semwal/indexGLTutorial.html

Also NeHe productions does a realy great job breaking down OpenGL into
lessons: My favorite!
http://nehe.gamedev.net/

Also, since your accessing OpenGL through PyOpenGL, you should look at:
http://pyopengl.sourceforge.net/documentation/

for other links and examples. Enjoy - jaime



On Sat, Apr 4, 2009 at 9:35 AM, projetmbc projet...@club-internet.frwrote:

  Your problem is with your OpenGL syntax. Simply change GL.GL_QUADS
 (which draw quadrilaterals) with GL.GL_TRIANGLES (self evident). Also, it
 would be better to move those declarations into your triangle routine as
 follows

 Thanks and sorry for this simple problem but I'm a real newbie with OpenGL.

 Where can I find documentations showing what kind of objects I can draw
 with OpenGL ?

 Best regards and thanks a lot.




___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Help about the use of OpenGL with PyQt

2009-04-04 Thread David Boddie
On Sat Apr 4 17:43:29 BST 2009, Jamie Riotto wrote:

 OpenGL Tutorial:
 http://cs.uccs.edu/~semwal/indexGLTutorial.html

 Also NeHe productions does a realy great job breaking down OpenGL into
 lessons: My favorite!
 http://nehe.gamedev.net/

 Also, since your accessing OpenGL through PyOpenGL, you should look at:
 http://pyopengl.sourceforge.net/documentation/

 for other links and examples. Enjoy - jaime

Another good source of information is the Red Book. You can find an old
version online here:

http://www.opengl.org/documentation/red_book/

Although it only covers OpenGL 1.1, it should contain all the basic
information you need to help you get started.

David
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt