Ver Mensaje Individual
  #7 (permalink)  
Antiguo 20/01/2009, 18:14
iozk
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 16 años, 6 meses
Puntos: 1
Respuesta: como instalo pyOpengl

encontre un tutorial pero no esta del todo completo como hago que vea las clases en la aplicacion

Código python:
Ver original
  1. import wx
  2. import sys
  3. from wx import glcanvas
  4. from OpenGL.GL import*
  5. from OpenGL.GLUT import*
  6.  
  7. class MyCanvasBase(glcanvas.GLCanvas):
  8.     def __init__(self, parent):
  9.         glcanvas.GLCanvas.__init__(self, parent, -1)
  10.         self.int = False
  11.         #initial mouse position
  12.         self.lastx = self.x = 30
  13.         self.lasty = self.y = 30
  14.         self.size = None
  15.         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
  16.         self.Bind(wx.EVT_SIZE, self.OnSize)
  17.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  18.         self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
  19.         self.Bind(wx.WVT_LEFT_UP, self.OnMouseUp)
  20.         self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
  21.  
  22.     def OnEraseBackground(self, event):
  23.         pass
  24.     def OnSize(self, event):
  25.         size = self.size = self.GetClientSize()
  26.         if self.GetContext():
  27.             self.SetCurrent()
  28.             glViewport(0, 0, size.width, size.height)
  29.         event.Skip()
  30.  
  31.     def OnPaint(self, event):
  32.         dc = wx.PaintDC(self)
  33.         self.SetCurrent()
  34.         if not self.init:
  35.             self.InitGL()
  36.             self.init = True
  37.         self.OnDraw()
  38.  
  39.     def OnMouseDown(self, event):
  40.         self.CaptureMouse()
  41.         self.x, self.y = self.lastx, self.lasty = wvt.GetPosition()
  42.  
  43.     def OnMouseUp(self, event):
  44.         self.ReleaseMouse()
  45.  
  46.     def OnMouseMotion(self, event):
  47.         if evt.Dragging() and evt.LeftIsDown():
  48.             self.lastx, self.lasty = self.x, self.y
  49.             self.x, self.y, = evt.GetPosition()
  50.             self.Refresh(False)
  51.  
  52. class CubeCanvas(MyCanvasBase):
  53.     def InitGL(self):
  54.         glMatrixMode(GL_PROJECTION)
  55.         glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0)
  56.  
  57.         #position viewer
  58.         glMatrixMode(GL_MODELVIEW)
  59.         glTranslatef(0.0, 0.0, -2.0)
  60.  
  61.         #position object
  62.         glRotatef(self.y, 1.0, 0.0, 0.0)
  63.         glRotatef(self.x, 0.0, 1.0, 0.0)
  64.  
  65.         glEnable(GL_DEPTH_TEST)
  66.         glEnable(GL_LIGHTING)
  67.         glEnable(GL_LIGHTO)
  68.  
  69.     def OnDraw(self):
  70.         #clear color and depth buffers
  71.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  72.  
  73.         #draw six faces of a cube
  74.         glBegin(GL_QUADS)
  75.         glNormal3f( 0.0, 0.0, 1.0)
  76.         glVertex3f( 0.5, 0.5, 0.5)
  77.         glVertex3f(-0.5, 0.5, 0.5)
  78.         glVertex3f(-0.5,-0.5, 0.5)
  79.         glVertex3f( 0.5,-0.5, 0.5)
  80.  
  81.         glNormal3f( 0.0, 0.0,-1.0)
  82.         glVertex3f(-0.5,-0.5,-0.5)
  83.         glVertex3f(-0.5, 0.5,-0.5)
  84.         glVertex3f( 0.5, 0.5,-0.5)
  85.         glVertex3f( 0.5,-0.5,-0.5)
  86.  
  87.         glNormal3f( 0.0, 1.0, 0.0)
  88.         glVertex3f( 0.5, 0.5, 0.5)
  89.         glVertex3f( 0.5, 0.5,-0.5)
  90.         glVertex3f(-0.5, 0.5,-0.5)
  91.         glVertex3f(-0.5, 0.5, 0.5)
  92.  
  93.         glNormal3f( 0.0,-1.0, 0.0)
  94.         glVertex3f(-0.5,-0.5,-0.5)
  95.         glVertex3f( 0.5,-0.5,-0.5)
  96.         glVertex3f( 0.5,-0.5, 0.5)
  97.         glVertex3f(-0.5,-0.5, 0.5)
  98.  
  99.         glNormal3f( 1.0, 0.0, 0.0)
  100.         glVertex3f( 0.5, 0.5, 0.5)
  101.         glVertex3f( 0.5,-0.5, 0.5)
  102.         glVertex3f( 0.5,-0.5,-0.5)
  103.         glVertex3f( 0.5, 0.5,-0.5)
  104.  
  105.         glNormal3f(-1.0, 0.0, 0.0)
  106.         glVertex3f(-0.5,-0.5,-0.5)
  107.         glVertex3f(-0.5,-0.5, 0.5)
  108.         glVertex3f(-0.5, 0.5, 0.5)
  109.         glVertex3f(-0.5, 0.5,-0.5)
  110.         glEnd()
  111.  
  112.         if self.size is None:
  113.             self.size = self.GetClientSize()
  114.         w, h = self.size
  115.         w = max(w, 1.0)
  116.         h = max(h, 1.0)
  117.         xScale = 180.0 / w
  118.         yScale = 180.0 / h
  119.         glRotatef((self.y - self.lasty) * yScale, 1.0, 0.0, 0.0);
  120.         glRotatef((self.x - self.lastx) * xScale, 0.0, 1.0, 0.0);
  121.  
  122.         self.SwapBuffers()
  123.  
  124. class ConeCanvas(MyCanvasBase):
  125.     def InitGL( self ):
  126.         glMatrixMode(GL_PROYECTION)
  127.         #camera frustrum setup
  128.         glFrustum(-5.0, 0.5, -0.5, 1.0, 3.0)
  129.         glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
  130.         glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
  131.         glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
  132.         glMaterial(GL_FRONT, GL_SHININESS, 50.0)
  133.         glLight(GL_LIGHTO, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
  134.         glLight(GL_LIGHTO, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
  135.         glLight(GL_LIGHTO, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
  136.         glLight(GL_LIGHTO, GL_POSITION, [1.0, 1.0, 1.0, 0.0])
  137.         glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
  138.         glEnable(GL_LIGHTING)
  139.         glEnable(GL_LIGHTO)
  140.         glDepthFunc(GL_LESS)
  141.         glEnable(GL_DEPTH_TEST)
  142.         glCler(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  143.         #position viewer
  144.         glMatrixMode(GL_MODELVIEW)
  145.         #position viewer
  146.         glTranslatef(0.0, 0.0, -2.0);
  147.         #
  148.         glutInit(sys.argv)
  149.  
  150.     def OnDraw(self):
  151.         #clear coor and depth buffers
  152.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  153.         #use a fresh transformation matrix
  154.         glPushMatrix()
  155.         #position object
  156.         #glTranslate(0.0, 0.0, -2.0)
  157.         glRotate(30.0, 1.0, 0.0, 0.0)
  158.         glRotate(30.0, 0.0, 1.0, 0.0)
  159.  
  160.         glTranslate(0, -1, 0)
  161.         glRotate(250, 1, 0, 0)
  162.         glutSolidCone(0.5, 1, 30, 5)
  163.         glPopMatrix()
  164.         glRotatef((self.y - self.lasty), 0.0, 0.0, 1.0);
  165.         glRotatef((self.x - self.lastx), 1.0, 0.0, 0.0);
  166.         #push into visible buffer
  167.         self.SwapBuffers()
  168.  
  169. class MainWindow(wx.Frame):
  170.     def __init__(self, parent = None, id = -1, title ="PyOpenGl example"):
  171.         #Init
  172.         wx.Frame.__init__(self, parent, id, title, size = (400, 200),
  173.                           style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
  174.         self.base = MyCanvasBase(self)
  175.        
  176.  
  177.        
  178.  
  179. if __name__ == '__main__':
  180.     app = wx.App()
  181.     MainWindow().Show()
  182.     app.MainLoop()