def use(self): """camera.use() -> void` Calls gluLookAt using the current camera settings.""" GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() p, l, u = self.pos, self.lookAt, self.up GLU.gluLookAt(p[0], p[1], p[2], l[0], l[1], l[2], u[0], u[1], u[2])
def refresh_position(self): """Recalc where in modelspace quad needs to be to fill screen.""" screensize = pygame.display.get_surface().get_size() bottomleft = oglu.gluUnProject(screensize[0] / 2 - \ self._winsize[0] / 2 + \ self._position[0], screensize[1] / 2 - \ int(round(self._winsize[1] / 2.0)) + \ self._position[1], 0) bottomright = oglu.gluUnProject(screensize[0] / 2 + \ int(round(self._winsize[0] / 2.0)) + \ self._position[0], screensize[1] / 2 - \ int(round(self._winsize[1] / 2.0)) + \ self._position[1], 0) topleft = oglu.gluUnProject(screensize[0] / 2 - \ self._winsize[0] / 2 + \ self._position[0], screensize[1] / 2 + \ self._winsize[1] / 2 + \ self._position[1], 0) topright = oglu.gluUnProject(screensize[0] / 2 + \ int(round(self._winsize[0] / 2.0)) + \ self._position[0], screensize[1] / 2 + \ self._winsize[1] / 2 + \ self._position[1], 0) self.dims = topleft, topright, bottomright, bottomleft width = topright[0] - topleft[0] height = topright[1] - bottomright[1] self._qdims = topleft[0], topleft[1], width, height
def gl_draw_all(self, root, offset): if not self.visible: return from OpenGL import GL, GLU rect = self.rect.move(offset) if self.is_gl_container: self.gl_draw_self(root, offset) suboffset = rect.topleft for subwidget in self.subwidgets: subwidget.gl_draw_all(root, suboffset) else: try: surface = Surface(self.size, SRCALPHA) except Exception, e: #size error? return self.draw_all(surface) data = image.tostring(surface, 'RGBA', 1) w, h = root.size GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluOrtho2D(0, w, 0, h) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glRasterPos2i(max(rect.left, 0), max(h - rect.bottom, 0)) GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glDrawPixels(self.width, self.height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, fromstring(data, dtype='uint8')) GL.glPopAttrib() GL.glFlush()
def initOpenGLMatrix(self): # FROM http://code.activestate.com/recipes/325391-open-a-glut-window-and-draw-a-sphere-using-pythono/ glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) glut.glutInitWindowSize(400, 400) glut.glutCreateWindow(b'PyTowerDefense') gl.glClearColor(0., 0., 0., 1.) gl.glShadeModel(gl.GL_SMOOTH) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_LIGHTING) gl.lightZeroPosition = [100., 40., 100., 1.] gl.lightZeroColor = [0.8, 1.0, 0.8, 1.0] #green tinged gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, gl.lightZeroPosition) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, gl.lightZeroColor) gl.glLightf(gl.GL_LIGHT0, gl.GL_CONSTANT_ATTENUATION, 0.01) gl.glLightf(gl.GL_LIGHT0, gl.GL_LINEAR_ATTENUATION, 0.005) gl.glEnable(gl.GL_LIGHT0) glut.glutDisplayFunc(self.paint) glut.glutIdleFunc(self.repaint) gl.glMatrixMode(gl.GL_PROJECTION) glu.gluPerspective(30., 1., 1., 1000.) gl.glMatrixMode(gl.GL_MODELVIEW) self._eyePosition = Point3D("Camera Eye Location").translate(0, 0, 400) self._watchingPosition = Point3D("Camera Watching Position") self._upVector = Point3D("Camera Up Vector").translate(0, 1, 0) glu.gluLookAt(self._eyePosition.x, self._eyePosition.y, self._eyePosition.z, self._watchingPosition.x, self._watchingPosition.y, self._watchingPosition.z, self._upVector.x, self._upVector.y, self._upVector.z) gl.glPushMatrix() return
def bezier1(self, vertex, controlpoint): for fraction in [0.2, 0.4, 0.6, 0.8, 1.0]: lnode1 = self.prevnode + fraction * (controlpoint - self.prevnode) lnode2 = controlpoint + fraction * (vertex - controlpoint) vnew = lnode1 + fraction * (lnode2 - lnode1) glu.gluTessVertex(tess, vnew, vnew)
def on_paint(self, event): """Process the drawing event.""" import OpenGL.GL as gl import OpenGL.GLU as glu self.canvas.SetCurrent(self.canvas.context) if not self.gl_initialized: self.initgl() self.gl_initialized = True self.print_help() if self.light: gl.glEnable(gl.GL_LIGHTING) else: gl.glDisable(gl.GL_LIGHTING) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # Clear The Screen And The Depth Buffer gl.glLoadIdentity( ) # Reset The View gl.glPushMatrix() glu.gluLookAt(*(list(rtp_to_xyz( *self.camera_pos_rtp)) + list(self.target_pos) + list(self.up))) self.draw_cube() gl.glPopMatrix() gl.glFlush() self.SwapBuffers() event.Skip()
def reshape(self, w, h): GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() self.width=w self.height=h GLU.gluPerspective(self.fov, self.width * 1.0 / self.height, self.nearDist, self.farDist) GL.glMatrixMode(GL.GL_MODELVIEW)
def expose_cb(self,w,ev): style=self.get_style() gc=style.bg_gc[gtk.STATE_NORMAL] left,top,width,height=self.get_allocation() gldrawable = self.get_gl_drawable() glcontext = self.get_gl_context() gldrawable.gl_begin(glcontext) GL.glClearColor(1, 1, 1, 0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glViewport(0,0,width,height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(23, width/height, 5, 20) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() self.drawit() if gldrawable.is_double_buffered(): gldrawable.swap_buffers() else: glFlush() gldrawable.gl_end()
def initgl(self): """Initialize OpenGL for use in the window.""" import OpenGL.GL as gl import OpenGL.GLU as glu self.load_textures() gl.glEnable(gl.GL_TEXTURE_2D) gl.glClearColor(0.0, 0.0, 0.0, 0.0) # This Will Clear The Background Color To Black gl.glClearDepth( 1.0) # Enables Clearing Of The Depth Buffer gl.glDepthFunc( gl.GL_LESS) # The Type Of Depth Test To Do gl.glEnable(gl.GL_DEPTH_TEST) # Enables Depth Testing gl.glShadeModel( gl.GL_SMOOTH) # Enables Smooth Color Shading gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() # Reset The Projection Matrix # Calculate The Aspect Ratio Of The Window (width, height) = self.canvas.GetClientSize() glu.gluPerspective(45.0, float(width) / float(height), 0.1, 100.0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, (0.5, 0.5, 0.5, 1.0)) # Setup The Ambient Light gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) # Setup The Diffuse Light gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, (0.0, 0.0, 2.0, 1.0)) # Position The Light gl.glEnable(gl.GL_LIGHT0)
def DrawScreen(self): OGL.glClear(OGL.GL_COLOR_BUFFER_BIT | OGL.GL_DEPTH_BUFFER_BIT) # Clear The Screen And The Depth Buffer OGL.glLoadIdentity() # Reset The matrix # To calculate our collision detection with the camera, it just takes one function # call from the client side. We just pass in the vertices in the world that we # want to check, and then the vertex count. objCamera.CheckCameraCollision(g_vWorld, g_NumberOfVerts) # Assign Values to Local Variables to Prevent Long Lines Of Code pos.x, pos.y, pos.z = objCamera.mPos.x, objCamera.mPos.y, objCamera.mPos.z view.x, view.y, view.z = objCamera.mView.x, objCamera.mView.y, objCamera.mView.z up.x, up.y, up.z = objCamera.mUp.x, objCamera.mUp.y, objCamera.mUp.z # use this function for opengl target camera OGLU.gluLookAt(pos.x, pos.y, pos.z, view.x, view.y, view.z, up.x, up.y, up.z) # Since we have the vertices for the world in the correct order, let's create # a loop that goes through all of the vertices and passes them in to be rendered. OGL.glBegin(OGL.GL_TRIANGLES) # Go through all the vertices and draw them for i in range(0,g_NumberOfVerts,3): OGL.glColor3ub(i, 2*i, 3*i) # All different colors to see the structure while playing OGL.glVertex3f(g_vWorld[i].x, g_vWorld[i].y, g_vWorld[i].z) OGL.glVertex3f(g_vWorld[i+1].x, g_vWorld[i+1].y, g_vWorld[i+1].z) OGL.glVertex3f(g_vWorld[i+2].x, g_vWorld[i+2].y, g_vWorld[i+2].z) OGL.glEnd()
def glInit(): OGLUT.glutInit() # initialize the GLUT library. OGLUT.glutInitDisplayMode(OGLUT.GLUT_DOUBLE | OGLUT.GLUT_RGB |OGLUT.GLUT_DEPTH) # initial display mode OGL.glShadeModel(OGL.GL_SMOOTH) # Enable Smooth Shading OGL.glClearColor(0.0, 0.0, 0.0, 0.0) # Black Background OGL.glClearDepth(1.0) # Depth Buffer Setup OGL.glEnable(OGL.GL_DEPTH_TEST) # Enables Depth Testing OGL.glDepthFunc(OGL.GL_LEQUAL) # The Type Of Depth Testing To Do OGL.glHint(OGL.GL_PERSPECTIVE_CORRECTION_HINT, OGL.GL_NICEST) # Really Nice Perspective Calculations objCamera.Position_Camera(10, 4, 12, 9, 4, 12, 0, 1, 0) # Set Camera Position LoadVertices() OGL.glViewport(0,0,SCREEN_SIZE[0],SCREEN_SIZE[1]) # Reset The Current Viewport OGL.glMatrixMode(OGL.GL_PROJECTION) OGL.glLoadIdentity() # Calculate The Aspect Ratio Of The Window OGLU.gluPerspective(45.0, SCREEN_SIZE[0]/SCREEN_SIZE[1], 0.1, 100.0) OGL.glMatrixMode(OGL.GL_MODELVIEW) OGL.glCullFace(OGL.GL_BACK) # Don't draw the back sides of polygons OGL.glEnable(OGL.GL_CULL_FACE) # Turn on culling
def reshape(w, h): GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(60.0, float(w)/h, .01, 1000.0) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity()
def loadProjection(self,force=False,pick=None): """Load the projection/perspective matrix. The caller will have to setup the correct GL environment beforehand. No need to set matrix mode though. This function will switch to GL_PROJECTION mode before loading the matrix, and go back to GL_MODELVIEW mode on exit. A pick region can be defined to use the camera in picking mode. pick defines the picking region center and size (x,y,w,h). This function does it best at autodetecting changes in the lens settings, and will only reload the matrix if such changes are detected. You can optionally force loading the matrix. """ if self.lensChanged or force: GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() if pick: #print 'PICK: %s' % str(pick) GLU.gluPickMatrix(*pick) if self.perspective: GLU.gluPerspective(self.fovy,self.aspect,self.near,self.far) else: #print "FOVY: %s" % self.fovy top = tand(self.fovy*0.5) * self.dist bottom = -top right = top * self.aspect left = bottom * self.aspect #print "Ortho %s" % [left,right,bottom,top,self.near,self.far] GL.glOrtho(left,right,bottom,top,self.near,self.far) GL.glMatrixMode(GL.GL_MODELVIEW)
def frustum( self, w, h ): """Set up the viewing Frustum""" if w and h: aspect = float(w)/float(h) else: aspect = 1.0 GLU.gluPerspective(self.fov * 180.0 / pi, aspect, 0.001, 1000.0)
def main(): glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH) glut.glutInitWindowSize(400,400) glut.glutCreateWindow("teapot") gl.glClearColor(0.,0.,0.,1.) gl.glShadeModel(gl.GL_SMOOTH) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_LIGHTING) lightZeroPosition = [10.,4.,10.,1.] lightZeroColor = [0.8,1.0,0.8,1.0] #green tinged gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, lightZeroPosition) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, lightZeroColor) gl.glLightf(gl.GL_LIGHT0, gl.GL_CONSTANT_ATTENUATION, 0.1) gl.glLightf(gl.GL_LIGHT0, gl.GL_LINEAR_ATTENUATION, 0.05) gl.glEnable(gl.GL_LIGHT0) glut.glutDisplayFunc(display) gl.glMatrixMode(gl.GL_PROJECTION) glu.gluPerspective(40.,1.,1.,40.) gl.glMatrixMode(gl.GL_MODELVIEW) glu.gluLookAt(0,0,10, 0,0,0, 0,1,0) gl.glPushMatrix() glut.glutMainLoop() return
def display(self): """ Render the scene. """ start = time.time() GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glPushMatrix() cam_x = self.zoom * math.sin(self.cam_lat) * math.cos(self.cam_long) cam_y = self.zoom * math.sin(self.cam_lat) * math.sin(self.cam_long) cam_z = self.zoom * math.cos(self.cam_lat) GLU.gluLookAt(cam_x, cam_y, cam_z, 0, 0, 0, 0, 0, 2) self.display_box() self.display_points() self.display_segments() self.display_circles() self.display_polygons() self.display_regions() self.display_sphere() GL.glPopMatrix() GLUT.glutSwapBuffers() render_time = time.time() - start GLUT.glutSetWindowTitle("%.3f" % render_time)
def update_projection(self, fovy, width, height): """Update the projection matrix.""" GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(fovy, width / height, self.znear, self.zfar) self.fovy = fovy
def resizeGL(self, width, height): GL.glViewport(0, 0, width, height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() # fov (deg) controls amount of perspective, and as a side effect initial apparent size GLU.gluPerspective(45, width / height, 0.0001, 1000) # fov, aspect, nearz & farz clip planes GL.glMatrixMode(GL.GL_MODELVIEW)
def drawBackground(self, painter, rect) : super(BlobViewScene, self).drawBackground(painter,rect) height = float(painter.device().height()) width = float(painter.device().width()) painter.beginNativePainting() self.setStates() GL.glClearColor(0.0, 0.0, 0.0, 0.0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_PROJECTION) GLU.gluPerspective(60.0, width / height, 0.01, 450.0); GLU.gluLookAt(-self._distance,0,0,0,0,0,0,0,1); GL.glMatrixMode(GL.GL_MODELVIEW); view = QtGui.QMatrix4x4() view.rotate(self._trackballs[2].rotation()) # view = np.array(list(view.data())).reshape((4,4)) # view[2, 3] -= 2.0 * math.exp(self._distance / 1200.0) # view = QtGui.QMatrix4x4(*view.reshape((16,))) GL.glLoadMatrixf(view.data()) self.drawAxis() # self.drawPoints() self.drawSphere() self.setDefaultState() painter.endNativePainting() self._frame+=1
def resizeGL(self, w, h): GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() # 軸幅の設定 xmin, xmax, ymin, ymax = self._get_axes() GLU.gluOrtho2D(xmin, xmax, ymin, ymax)
def DrawWire(self, yangle, xangle, vfrom, vto): lm1 = self.colony.polyp_list[vfrom - 1] lm2 = self.colony.polyp_list[vto - 1] # print lm1.x, lm2.x axis_start = [0, 0, 1] axis_end = [lm1.pos[0] - lm2.pos[0], lm1.pos[1] - lm2.pos[1], lm1.pos[2] - lm2.pos[2]] # print vfrom, vto, axis_start, axis_end angle = math.acos(axis_start[0] * axis_end[0] + axis_start[1] * axis_end[1] + axis_start[2] * axis_end[2] / ( (axis_start[0] ** 2 + axis_start[1] ** 2 + axis_start[2] ** 2) ** 0.5 * ( axis_end[0] ** 2 + axis_end[1] ** 2 + axis_end[2] ** 2) ** 0.5)) angle = angle * (180 / math.pi) axis_rotation = [0, 0, 0] axis_rotation[0] = axis_start[1] * axis_end[2] - axis_start[2] * axis_end[1] axis_rotation[1] = axis_start[2] * axis_end[0] - axis_start[0] * axis_end[2] axis_rotation[2] = axis_start[0] * axis_end[1] - axis_start[1] * axis_end[0] if angle == 180: axis_rotation = [1, 0, 0] length = (axis_end[0] ** 2 + axis_end[1] ** 2 + axis_end[2] ** 2) ** 0.5 radius = self.wire_radius cyl = glu.gluNewQuadric() gl.glPushMatrix() gl.glLoadIdentity() # glTranslate(0, 0, self.offset) gl.glRotatef(yangle, 1.0, 0.0, 0.0) gl.glRotatef(xangle, 0.0, 1.0, 0.0) gl.glTranslate(lm2.pos[0], lm2.pos[1], lm2.pos[2]) if (angle != 0): gl.glRotate(angle, axis_rotation[0], axis_rotation[1], axis_rotation[2]) glu.gluCylinder(cyl, radius, radius, length, 10, 10) gl.glPopMatrix()
def locate(self): gl.glLoadIdentity() glu.gluLookAt( self.__eye_x, self.__eye_y, self.__eye_z, self.__center_x, self.__center_y, 0, self.__up_vector_x, self.__up_vector_y, self.__up_vector_z )
def draw(self): t1 = time.time() glClearColor(0.0, 0.0, 0.0, 0.0) glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) glLoadIdentity () horizonY = 1 * 2.2 - .6 + .5 GLU.gluLookAt(self.eyeX.x, horizonY, 8.0, self.lookX.x, horizonY, 0.0, 0.0, 1.0, 0.0) glEnable(GL.GL_TEXTURE_2D) if 0: with pushMatrix(): glColor3f(1,0,0) glTranslatef(*self.ball) glScalef(.2, .2, 1) imageCard("sample.jpg") with pushMatrix(): with mode(disable=[GL.GL_LIGHTING]): for card in self.cards: card.draw(self.eyeX.x, horizonY, self.cardList) glFlush() pygame.display.flip()
def paintGL(self): GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GLU.gluLookAt(0, 0, 2, 0, 0, 0, 0, 1, 0) GL.glDisable(GL.GL_DEPTH_TEST) self.qglClearColor(self.clearColor) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glPushMatrix() GL.glEnable(GL.GL_TEXTURE_2D) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) offset = self.offset if offset <= 0: offset = 0 if offset > len(self.res_list) - 1: offset = len(self.res_list) - 1 mid = int(math.floor(offset + 0.5)) start_pos = mid - TileflowWidget.VISIBLE_TILES if start_pos < 0: start_pos = 0 end_pos = mid + TileflowWidget.VISIBLE_TILES if end_pos > len(self.res_list): end_pos = len(self.res_list) for i in range(start_pos, mid)[::TileflowWidget.DIRECTION]: self.drawTile(i, i - offset, self.tiles[i]) for i in range(mid, end_pos)[::-TileflowWidget.DIRECTION]: self.drawTile(i, i - offset, self.tiles[i]) GL.glPopMatrix()
def main(): global calib, cyl src_dir = os.path.split(os.path.abspath(__file__))[0] data_dir = os.path.join(src_dir,'..','data') pmat = np.loadtxt( os.path.join(data_dir, 'cameramatrix.txt') ) calib = decompose(pmat) width = 752 height = 480 glut.glutInit() glut.glutInitWindowSize(width,height) glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DEPTH | glut.GLUT_ACCUM | glut.GLUT_DOUBLE) glut.glutCreateWindow("calib_test_pyopengl"); cyl = PointCylinder() if 1: # compose view matrix r = get_gluLookAt(pmat) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() glu.gluLookAt( *r['all_args'] ) gl.glDisable(gl.GL_DEPTH_TEST) glut.glutDisplayFunc(on_draw) on_resize(width,height) glut.glutMainLoop()
def resizeGL(self, w, h): GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluOrtho2D(0, w, h, 0) # same OpenGL coordinates as pixel ones GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity()
def _load_texture(self, filename): """ Loads an image as texture """ if not os.path.exists(filename): raise ValueError("Texture file not found: " + filename) sys.exit() # Load the image image = Image.open(filename) ix = image.size[0] iy = image.size[1] image = image.tostring("raw", "RGBX", 0, -1) # Create Texture ind = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D, ind) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_REPEAT) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_NEAREST) glu.gluBuild2DMipmaps(gl.GL_TEXTURE_2D, 3, ix, iy, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, image) return ind
def resizeGL(self, width, height): # To insure we don't have a zero height if height == 0: height = 1 # Fill the entire graphics window! gl.glViewport(0, 0, width, height) # Set the projection matrix... our "view" gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() # Set how we view the world and position our eyeball glu.gluPerspective(45.0, 1.0, 1.0, 100.0) # Set the matrix for the object we are drawing gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() # Place the camera position, the direction of view # and which axis is up glu.gluLookAt(self.coordLength, self.coordLength, self.coordLength, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0)
def InitGL(self): # set viewing projection mat_specular = (1.0, 1.0, 1.0, 1.0) light_position = (.3, .3, 0.5, 0.0) light_position1 = (-0.3, 0.3, 0.5, 0.0) diffuseMaterial = (1., 1., 1., 1.0) ambientMaterial = (0.5, .5, .5, 1.0) gl.glClearColor(1.0, 1.0, 1.0, 1.0) gl.glShadeModel(gl.GL_SMOOTH) gl.glEnable(gl.GL_DEPTH_TEST) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, ambientMaterial) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, diffuseMaterial) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, mat_specular) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, 25.0) gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position) gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, light_position1) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_LIGHT1) gl.glColorMaterial(gl.GL_FRONT, gl.GL_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(self.fov, self.aspect, 0.2, 200.0) gl.glMatrixMode(gl.GL_MODELVIEW) self.CameraTransformation() self.globTrans = gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX) gl.glRenderMode(gl.GL_RENDER) self.max_stack = gl.glGetFloatv(gl.GL_MAX_NAME_STACK_DEPTH)
def keystroke(self,*args): # If escape is pressed, kill everything. key=args[0] x=args[1] y=args[2] if key == 's': self.save() if key == 'v': if self.recordingon==False: self.recordingon=True print('Recording is on') else: self.recordingon=False print('Recording is off') if key == '9': #zoom out self.glu_perspect[0]+=10.#self.glu_perspect[0] glut.glutPostRedisplay() if key == '0': #zoom in self.glu_perspect[0]-=10. #0.5*self.glu_perspect[0] glut.glutPostRedisplay() if key == 'o': self.isperspect=int(not(self.isperspect)) if self.isperspect: print('perspective projection on') else: print('orthogonal projection on') px,py,w,h=self.viewport self.reshape(w,h) glut.glutPostRedisplay() if args[0] == 'r': self.glu_perspect[0]=60. self.mouse.rotationMatrix.reset() self.mouse.translationMatrix.reset() glut.glutPostRedisplay() if key == 'j': cube.position[0]+=10. glut.glutPostRedisplay() if key == 'k': cube.position[0]-=10. glut.glutPostRedisplay() if key == 'p': viewport=gl.glGetDoublev(gl.GL_VIEWPORT) #print 'Viewport' #print viewport #print float(x), viewport[3]-float(y) xn,yn,zn=glu.gluUnProject(np.double(x),viewport[3]-np.double(y),0.) #print 'World Coordinates Near' #print xn,yn,zn xf,yf,zf=glu.gluUnProject(np.double(x),viewport[3]-np.double(y),1.) near=np.array([xn,yn,zn]) far =np.array([xf,yf,zf]) self.plot.update_pick_ray(near,far) if key == '\033': sys.exit()
def to_OpenGL(self, color=None, show_directions=False): if not GL_enabled: return if not color is None: GL.glColor4f(*color) GL.glBegin(GL.GL_TRIANGLES) # use normals to improve lighting (contributed by imyrek) normal_t = self.normal GL.glNormal3f(normal_t[0], normal_t[1], normal_t[2]) # The triangle's points are in clockwise order, but GL expects # counter-clockwise sorting. GL.glVertex3f(self.p1[0], self.p1[1], self.p1[2]) GL.glVertex3f(self.p3[0], self.p3[1], self.p3[2]) GL.glVertex3f(self.p2[0], self.p2[1], self.p2[2]) GL.glEnd() if show_directions: # display surface normals n = self.normal c = self.center d = 0.5 GL.glBegin(GL.GL_LINES) GL.glVertex3f(c[0], c[1], c[2]) GL.glVertex3f(c[0] + n[0] * d, c[1] + n[1] * d, c[2] + n[2] * d) GL.glEnd() if False: # display bounding sphere GL.glPushMatrix() middle = self.middle GL.glTranslate(middle[0], middle[1], middle[2]) if not hasattr(self, "_sphere"): self._sphere = GLU.gluNewQuadric() GLU.gluSphere(self._sphere, self.radius, 10, 10) GL.glPopMatrix() if pycam.Utils.log.is_debug(): # draw triangle id on triangle face GL.glPushMatrix() c = self.center GL.glTranslate(c[0], c[1], c[2]) p12 = pmul(padd(self.p1, self.p2), 0.5) p3_12 = pnormalized(psub(self.p3, p12)) p2_1 = pnormalized(psub(self.p1, self.p2)) pn = pcross(p2_1, p3_12) GL.glMultMatrixf((p2_1[0], p2_1[1], p2_1[2], 0, p3_12[0], p3_12[1], p3_12[2], 0, pn[0], pn[1], pn[2], 0, 0, 0, 0, 1)) n = pmul(self.normal, 0.01) GL.glTranslatef(n[0], n[1], n[2]) maxdim = max((self.maxx - self.minx), (self.maxy - self.miny), (self.maxz - self.minz)) factor = 0.001 GL.glScalef(factor * maxdim, factor * maxdim, factor * maxdim) w = 0 id_string = "%s." % str(self.id) for ch in id_string: w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch)) GL.glTranslate(-w / 2, 0, 0) for ch in id_string: GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch)) GL.glPopMatrix() if False: # draw point id on triangle face c = self.center p12 = pmul(padd(self.p1, self.p2), 0.5) p3_12 = pnormalized(psub(self.p3, p12)) p2_1 = pnormalized(psub(self.p1, self.p2)) pn = pcross(p2_1, p3_12) n = pmul(self.normal, 0.01) for p in (self.p1, self.p2, self.p3): GL.glPushMatrix() pp = psub(p, pmul(psub(p, c), 0.3)) GL.glTranslate(pp[0], pp[1], pp[2]) GL.glMultMatrixf( (p2_1[0], p2_1[1], p2_1[2], 0, p3_12[0], p3_12[1], p3_12[2], 0, pn[0], pn[1], pn[2], 0, 0, 0, 0, 1)) GL.glTranslatef(n[0], n[1], n[2]) GL.glScalef(0.001, 0.001, 0.001) w = 0 for ch in str(p.id): w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch)) GL.glTranslate(-w / 2, 0, 0) for ch in str(p.id): GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch)) GL.glPopMatrix()
def __init__(self): self.quadric = GLU.gluNewQuadric() GLU.gluQuadricNormals(self.quadric, GLU.GLU_SMOOTH) #Create Smooth Normals GLU.gluQuadricTexture(self.quadric, gl.GL_TRUE) #Create Texture Coords
def end(self): if PolygonSet.in_poly: self.endContour() glu.gluEndPolygon(tess) PolygonSet.in_poly = False
def begin(self): self.end() glu.gluTessBeginPolygon(tess, self.vbuf) PolygonSet.in_poly = True
def beginContour(self): self.endContour() if not PolygonSet.in_poly: self.begin() glu.gluTessBeginContour(tess) PolygonSet.in_contour = True
if self.dialog: self.dialog.setValue(value) QApplication.processEvents() else: print 'Progress: %.2f%% done' % value def close(self): if self.dialog: self.dialog.close() import OpenGL.GLU as glu import numpy as np from math import cos, radians, degrees, sqrt, atan2, sin, asin from zipfile import ZipFile tess = glu.gluNewTess() glu.gluTessCallback(tess, glu.GLU_TESS_VERTEX_DATA, lambda vertex, vbuf: vbuf.extend(vertex[0:2])) glu.gluTessCallback(tess, glu.GLU_EDGE_FLAG, lambda flag: None) glu.gluTessCallback(tess, glu.GLU_TESS_COMBINE, lambda c, d, w: np.array(c)) """ Load static data for GUI from files such as airport, shapes, etc.""" class PolygonSet: in_poly = False in_contour = False def __init__(self): self.vbuf = [] self.prevnode = None self.prevcp = None
def __init__(self, y1, r1, y2, r2): self._coords = y1, r1, y2, r2 self.q = GLU.gluNewQuadric()
def OnDraw(self): # get screen position and store tmp = glu.gluProject(self._x, self._y, self._z) self._screenx, self._screeny, self._screenz = tuple(tmp)
def main(args): if (args.from_up is None) != (args.to_up is None): raise Exception( "from-up and to-up args should be both present or both absent") up_conversion = None if args.from_up is not None: up_conversion = (args.from_up, args.to_up) if args.verbose: def log(*args, **kwargs): print(*args, **kwargs) else: def log(*args, **kwargs): pass # Load and parse the model sys.stderr.flush() models = [] for path in args.input: log('Loading model ' + path + '...', file=sys.stderr, end='') model = load_model(path, up_conversion) # Compute normals if not already computed if len(model.normals) == 0: log(' done! (' + str(sum(map(lambda x: len(x.faces), model.parts))) + ' faces)\nComputing normals...', file=sys.stderr, end='') sys.stderr.flush() model.generate_vertex_normals() # Generate vbos for smooth rendering log(' done!\nGenerating vbos...', file=sys.stderr, end='') sys.stderr.flush() model.generate_vbos() models.append(model) log(' done!\nInitialiazing OpenGL Context', file=sys.stderr, end='') sys.stderr.flush() camera = Camera(Vector(0, 0, 5), Vector(0, 0, 0)) controls = OrbitControls() pg.init() pg.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), pgl.DOUBLEBUF | pgl.OPENGL | pgl.RESIZABLE) pg.display.set_caption('Model-Converter') # OpenGL init gl.glMatrixMode(gl.GL_MODELVIEW) gl.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_BLEND) gl.glClearColor(0, 0, 0, 0) running = True bounding_box = BoundingBox() if CENTER_AND_SCALE: for model in models: for vertex in model.vertices: bounding_box.add(vertex) log(' done!\nComputing bounding box...', file=sys.stderr, end='') log(' done!\nInitializing OpenGL textures...', file=sys.stderr, end='') sys.stderr.flush() # Initializes OpenGL textures for model in models: model.init_textures() shader = Shader() log(' done!\nReady!', file=sys.stderr) sys.stderr.flush() while running: for event in pg.event.get(): controls.apply_event(event) if event.type == pg.QUIT: pg.quit() quit() elif event.type == pg.KEYUP: if event.key == pg.K_ESCAPE: pg.quit() quit() elif event.type == pg.MOUSEBUTTONDOWN: if event.button == 1: pg.mouse.get_rel() elif event.type == pg.VIDEORESIZE: resize(event.size[0], event.size[1]) # Update physics controls.update() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() camera.look() gl.glPushMatrix() controls.apply() # gl.glBegin(gl.GL_LINES) # gl.glColor3f (1.0,0.0,0.0) # gl.glVertex3f(0.0,0.0,0.0) # gl.glVertex3f(2.0,0.0,0.0) # gl.glColor3f (0.0,1.0,0.0) # gl.glVertex3f(0.0,0.0,0.0) # gl.glVertex3f(0.0,2.0,0.0) # gl.glColor3f (0.0,0.0,1.0) # gl.glVertex3f(0.0,0.0,0.0) # gl.glVertex3f(0.0,0.0,2.0) # gl.glEnd() shader.bind() if CENTER_AND_SCALE: center = bounding_box.get_center() scale = bounding_box.get_scale() / 2 gl.glPushMatrix() gl.glScalef(1 / scale, 1 / scale, 1 / scale) gl.glTranslatef(-center.x, -center.y, -center.z) for model in models: model.draw() if CENTER_AND_SCALE: gl.glPopMatrix() shader.unbind() gl.glPopMatrix() gl.glFlush() pg.display.flip() # Sleep pg.time.wait(10)
def drawFlashLight(self): glPushMatrix() glRotate(-self.phi, 1.0, 0.0, 0.0) glRotate(-self.theta, 0.0, 1.0, 0.0) glTranslate(0, 0, 4) glMaterialfv(GL_FRONT, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0]) glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.0, 0.0, 0.0, 1.0]) glMaterialfv(GL_FRONT, GL_SPECULAR, [0.0, 0.0, 0.0, 1.0]) glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 1.0, 0.0, 1.0]) flashlight = GLU.gluNewQuadric() GLU.gluQuadricDrawStyle(flashlight, GLU.GLU_FILL) GLU.gluCylinder(flashlight, 0.3, 0.3, 1.5, 30, 30) GLU.gluCylinder(flashlight, 0.5, 0.3, 0.4, 30, 30) glPushMatrix() glTranslate(0, 0, 1.5) GLU.gluDisk(flashlight, 0.0, 0.3, 30, 30) glPopMatrix() glMaterialfv(GL_FRONT, GL_EMISSION, self.diffuse) GLU.gluDisk(flashlight, 0.0, 0.5, 30, 30) glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0, 1.0]) glPopMatrix()
def main(): models = load_json.load_folder('models', RESOLUTION) # Initialize the library if not glfw.init(): return display = [480, 480] # Create a windowed mode window and its OpenGL context window = glfw.create_window(display[0], display[1], "super normal", None, None) if not window: glfw.terminate() return # Make the window's context current glfw.make_context_current(window) glu.gluPerspective(45, (display[0] / display[1]), 0.1, RESOLUTION * 6) # glu.gluLookAt(- RESOLUTION*CUBE_SIZE/2, RESOLUTION*CUBE_SIZE/2, RESOLUTION*CUBE_SIZE*2, RESOLUTION*CUBE_SIZE/2 , RESOLUTION*CUBE_SIZE/2 ,0, 0,1,0) glu.gluLookAt(RESOLUTION * CUBE_SIZE * 1.2, RESOLUTION * CUBE_SIZE / 2 * 1.2, RESOLUTION * CUBE_SIZE * 2 * 1.2, 0, RESOLUTION * CUBE_SIZE / 2, 0, 0, 1, 0) # gl.glRotatef(-math.radians(90), 0.0, 1.0, 0.0); # glRotatef(-xAngle, 1.0f, 0.0f, 0.0f); # gl.glTranslatef(- RESOLUTION*CUBE_SIZE/2, -RESOLUTION*CUBE_SIZE/2, - RESOLUTION*CUBE_SIZE*2) #-60-RESOLUTION*4 gl.glColor4f(1, 1, 1, 1) print("Rendering...") ind = 0 # Loop until the user closes the window while not glfw.window_should_close(window): # gl.glRotatef(glfw.get_time() , 0, 1, 1) # gl.glRotatef(math.radians(45), 1, 1, 0) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # render the chairs as is # for chair in models: for c in models[ind]: gl.glTranslate(CUBE_SIZE * c[0], CUBE_SIZE * c[1], CUBE_SIZE * c[2]) drawCube() gl.glTranslate(-CUBE_SIZE * c[0], -CUBE_SIZE * c[1], -CUBE_SIZE * c[2]) #rendered the averaged chairs # for c in cubes: # gl.glTranslate( CUBE_SIZE*c[0] , CUBE_SIZE*c[1] , CUBE_SIZE*c[2] ) # drawCube() # gl.glTranslate( -CUBE_SIZE*c[0] , -CUBE_SIZE*c[1] , -CUBE_SIZE*c[2] ) ind += 1 time.sleep(5) # Swap front and back buffers glfw.swap_buffers(window) # Poll for and process events glfw.poll_events() glfw.terminate()
def main(): ## process the chair models # cubes = average_chair.single_cell(RESOLUTION,THRESHOLD) cubes = average_chair.neighbors(RESOLUTION, THRESHOLD) cubes = average_chair.smooth(cubes) # cubes = average_chair.flood(RESOLUTION,THRESHOLD) # cubes = platos_flood(RESOLUTION) exportForMatlab(cubes) # Initialize the library if not glfw.init(): return display = [640, 480] # Create a windowed mode window and its OpenGL context window = glfw.create_window(display[0], display[1], "super normal", None, None) if not window: glfw.terminate() return # Make the window's context current glfw.make_context_current(window) glu.gluPerspective(45, (display[0] / display[1]), 0.1, RESOLUTION * 6.0) glu.gluLookAt(-RESOLUTION * CUBE_SIZE / 2, RESOLUTION * CUBE_SIZE / 2, RESOLUTION * CUBE_SIZE * 2, RESOLUTION * CUBE_SIZE / 2, RESOLUTION * CUBE_SIZE / 2, 0, 0, 1, 0) # gl.glRotatef(-math.radians(90), 0.0, 1.0, 0.0); # glRotatef(-xAngle, 1.0f, 0.0f, 0.0f); # gl.glTranslatef(- RESOLUTION*CUBE_SIZE/2, -RESOLUTION*CUBE_SIZE/2, - RESOLUTION*CUBE_SIZE*2) #-60-RESOLUTION*4 gl.glColor4f(1, 1, 1, 1) print("Rendering...") # Loop until the user closes the window while not glfw.window_should_close(window): # gl.glRotatef(glfw.get_time() , 0, 1, 1) gl.glRotatef(math.radians(45), 1, 1, 0) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) #render the chairs as is # gl.glColor4f(1,1,1,1) # for chair in models: # for c in chair: # gl.glTranslate( CUBE_SIZE*c[0] , CUBE_SIZE*c[1] , CUBE_SIZE*c[2] ) # drawCube() # gl.glTranslate( -CUBE_SIZE*c[0] , -CUBE_SIZE*c[1] , -CUBE_SIZE*c[2] ) #rendered the averaged chairs for c in cubes: gl.glTranslate(CUBE_SIZE * c[0], CUBE_SIZE * c[1], CUBE_SIZE * c[2]) drawCube() gl.glTranslate(-CUBE_SIZE * c[0], -CUBE_SIZE * c[1], -CUBE_SIZE * c[2]) # Swap front and back buffers glfw.swap_buffers(window) # Poll for and process events glfw.poll_events() glfw.terminate()
def paintGL(self, context=None, camera=None, pick_layer=None): context = context or self if pick_layer: glClearColor(1., 1., 1., 1.) else: glClearColor(.7, .7, .7, 1.) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() c = camera or self.camera dist = (c.at - c.eye).length() GLU.gluPerspective(45.0, float(context.width())/context.height(), 0.01*dist, 100*dist) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) GLU.gluLookAt(c.eye.x(), c.eye.y(), c.eye.z(), c.at.x(), c.at.y(), c.at.z(), c.up.x(), c.up.y(), c.up.z()) leftv = QVector3D.crossProduct(c.up, c.at-c.eye).normalized() upv = QVector3D.crossProduct(c.at-c.eye, leftv).normalized() to = (c.at - c.eye).normalized() glLightfv(GL_LIGHT0, GL_POSITION, [c.eye.x(), c.eye.y(), c.eye.z(), 1]) if self.scene: if pick_layer: self.scene.pickrendergl(pick_layer) else: self.scene.rendergl(leftv, upv, c.eye, context.height(), context) else: # Draw 3 Cube faces (multiple quads) glEnable(GL_DEPTH_TEST) glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [1., 0., 0., 1.]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [1., 0., 0., 1.]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1., 1., 1., 1.]) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50) glBegin(GL_QUADS) glNormal3f(0, 1, 0) glVertex3f( 1.0, 1.0,-1.0) glNormal3f(0, 1, 0) glVertex3f(-1.0, 1.0,-1.0) glNormal3f(0, 1, 0) glVertex3f(-1.0, 1.0, 1.0) glNormal3f(0, 1, 0) glVertex3f( 1.0, 1.0, 1.0) glNormal3f(0, 0, 1) glVertex3f( 1.0, 1.0, 1.0) glNormal3f(0, 0, 1) glVertex3f(-1.0, 1.0, 1.0) glNormal3f(0, 0, 1) glVertex3f(-1.0,-1.0, 1.0) glNormal3f(0, 0, 1) glVertex3f( 1.0,-1.0, 1.0) glNormal3f(1, 0, 0) glVertex3f( 1.0, 1.0,-1.0) glNormal3f(1, 0, 0) glVertex3f( 1.0, 1.0, 1.0) glNormal3f(1, 0, 0) glVertex3f( 1.0,-1.0, 1.0) glNormal3f(1, 0, 0) glVertex3f( 1.0,-1.0,-1.0) glEnd()
def _triangulate(self, looplist, fill_rule): if self.shape in ['line']: return None t_list = [] self.ctx_curr_shape = [] spare_verts = [] tess = glu.gluNewTess() glu.gluTessNormal(tess, 0, 0, 1) glu.gluTessProperty(tess, glu.GLU_TESS_WINDING_RULE, glu.GLU_TESS_WINDING_NONZERO) def set_tess_callback(which): def set_call(func): glu.gluTessCallback(tess, which, func) return set_call @set_tess_callback(glu.GLU_TESS_VERTEX) def vertex_callback(vertex): self.ctx_curr_shape.append(list(vertex[0:2])) @set_tess_callback(glu.GLU_TESS_BEGIN) def begin_callback(which): self.ctx_tess_style = which @set_tess_callback(glu.GLU_TESS_END) def end_callback(): if self.ctx_tess_style == gl.GL_TRIANGLE_FAN: c = self.ctx_curr_shape.pop(0) p1 = self.ctx_curr_shape.pop(0) while self.ctx_curr_shape: p2 = self.ctx_curr_shape.pop(0) t_list.extend([c, p1, p2]) p1 = p2 elif self.ctx_tess_style == gl.GL_TRIANGLE_STRIP: p1 = self.ctx_curr_shape.pop(0) p2 = self.ctx_curr_shape.pop(0) while self.ctx_curr_shape: p3 = self.ctx_curr_shape.pop(0) t_list.extend([p1, p2, p3]) p1 = p2 p2 = p3 elif self.ctx_tess_style == gl.GL_TRIANGLES: t_list.extend(self.ctx_curr_shape) else: self._warn("Unrecognised tesselation style: %d" % (self.ctx_tess_style, )) self.ctx_tess_style = None self.ctx_curr_shape = [] @set_tess_callback(glu.GLU_TESS_ERROR) def error_callback(code): ptr = glu.gluErrorString(code) err = '' idx = 0 while ptr[idx]: err += chr(ptr[idx]) idx += 1 self._warn("GLU Tesselation Error: " + err) @set_tess_callback(glu.GLU_TESS_COMBINE) def combine_callback(coords, vertex_data, weights): x, y, z = coords[0:3] dataOut = (x, y, z) spare_verts.append((x, y, z)) return dataOut data_lists = [] for vlist in looplist: d_list = [] for x, y in vlist: v_data = (x, y, 0) d_list.append(v_data) data_lists.append(d_list) if fill_rule == 'nonzero': glu.gluTessProperty(tess, glu.GLU_TESS_WINDING_RULE, glu.GLU_TESS_WINDING_NONZERO) elif fill_rule == 'evenodd': glu.gluTessProperty(tess, glu.GLU_TESS_WINDING_RULE, glu.GLU_TESS_WINDING_ODD) glu.gluTessBeginPolygon(tess, None) for d_list in data_lists: glu.gluTessBeginContour(tess) for v_data in d_list: glu.gluTessVertex(tess, v_data, v_data) glu.gluTessEndContour(tess) glu.gluTessEndPolygon(tess) return t_list
def resizeGL(self, width, height): GL.glViewport(0, 0, width, height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(40.0, float(width) / float(height), 0.01, 10.0)
def test_nurbs(self): """Test nurbs rendering""" def buildControlPoints(): ctlpoints = np.zeros((4, 4, 3), 'f') for u in range(4): for v in range(4): ctlpoints[u][v][0] = 2.0 * (u - 1.5) ctlpoints[u][v][1] = 2.0 * (v - 1.5) if (u == 1 or u == 2) and (v == 1 or v == 2): ctlpoints[u][v][2] = 3.0 else: ctlpoints[u][v][2] = -3.0 return ctlpoints controlPoints = buildControlPoints() theNurb = GLU.gluNewNurbsRenderer() GLU.gluNurbsProperty(theNurb, GLU.GLU_SAMPLING_TOLERANCE, 25.0) GLU.gluNurbsProperty(theNurb, GLU.GLU_DISPLAY_MODE, GLU.GLU_FILL) knots = np.array([0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0], "f") glPushMatrix() try: glRotatef(330.0, 1., 0., 0.) glScalef(0.5, 0.5, 0.5) GLU.gluBeginSurface(theNurb) try: GLU.gluNurbsSurface(theNurb, knots, knots, controlPoints, GL_MAP2_VERTEX_3) finally: GLU.gluEndSurface(theNurb) finally: glPopMatrix()
def set_call(func): glu.gluTessCallback(tess, which, func)
def redraw_perspective(self): w = self.winfo_width() h = self.winfo_height() GL.glViewport(0, 0, w, h) # left corner in pixels if self.use_gradient_background: GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) ### GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() # switch to identity (origin) matrix GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glPushMatrix() GL.glLoadIdentity() GL.glDisable(GL.GL_DEPTH_TEST) GL.glBegin(GL.GL_QUADS) #//bottom color color = self.gradient_color1 GL.glColor3f(color[0], color[1], color[2]) GL.glVertex2f(-1.0, -1.0) GL.glVertex2f(1.0, -1.0) #//top color color = self.gradient_color2 GL.glColor3f(color[0], color[1], color[2]) GL.glVertex2f(1.0, 1.0) GL.glVertex2f(-1.0, 1.0) GL.glEnd() GL.glEnable(GL.GL_DEPTH_TEST) GL.glPopMatrix() GL.glPopMatrix() else: # Clear the background and depth buffer. GL.glClearColor(*(self.colors['back'] + (0, ))) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective( self. fovy, # The vertical Field of View, in radians: the amount of "zoom". # Think "camera lens". Usually between 90 (extra wide) and 30 (quite zoomed in) float(w) / float( h ), # Aspect Ratio. Notice that 4/3 == 800/600 screen resolution self. near, # near clipping plane. Keep as big as possible, or you'll get precision issues. self.far + self.distance) # Far clipping plane. Keep as little as possible. GLU.gluLookAt( 0, 0, self.distance, # the position of your camera, in world space 0, 0, 0, # where you want to look at, in world space 0., 1., 0. ) # probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() try: self.redraw() finally: GL.glFlush() # Tidy up GL.glPopMatrix() # Restore the matrix
def _GetCords(self): """ _GetCords() Get a pointset of the coordinates of the wobject. This is used for drawing the quads and lines using a vertex array. """ # Can we reuse buffered coordinates? if self._cordsBuffer is not None: return self._cordsBuffer # Get ranges in world coords rangex, rangey = self._GetRangesInWorldCords() # Project two points to use in OnDrawScreen screen1 = glu.gluProject(rangex.min, rangey.min, 0) screen2 = glu.gluProject(rangex.max, rangey.max, 0) # Calculate world-distance of a screendistance of self._barwidth # and then do drawing here (not in OnDrawScreen), otherwise I won't # be able to detect picking!! onePixelx = rangex.range / (screen2[0] - screen1[0]) onePixely = rangey.range / (screen2[1] - screen1[1]) # Get coords tmp = self._barWidth x1, x2, xd = rangex.min, rangex.max, onePixelx * tmp y1, y2, yd = rangey.min, rangey.max, onePixely * tmp if yd < 0: y1, y2 = y2, y1 # axis flipped # Definition of the coordinate indices: # # 12 11 10 15 # 4 0 ----- 3 9 # | | # | | # 5 1------ 2 8 # 13 6 7 14 # # Make coords pp = Pointset(2) # pp.append(x1, y1) pp.append(x1, y2) pp.append(x2, y2) pp.append(x2, y1) # pp.append(x1 - xd, y1) pp.append(x1 - xd, y2) pp.append(x1, y2 + yd) pp.append(x2, y2 + yd) # pp.append(x2 + xd, y2) pp.append(x2 + xd, y1) pp.append(x2, y1 - yd) pp.append(x1, y1 - yd) # pp.append(x1 - xd, y1 - yd) pp.append(x1 - xd, y2 + yd) pp.append(x2 + xd, y2 + yd) pp.append(x2 + xd, y1 - yd) # Done self._cordsBuffer = pp return pp
def render(self, start, color, radius=0.03): gl.glPushMatrix() gl.glColor3f(*color) gl.glTranslatef(*start) GLU.gluSphere(self.sphere, radius, 10, 10) gl.glPopMatrix()
def test_quadrics(self): """Test for rendering quadric objects""" quad = GLU.gluNewQuadric() glColor3f(1, 0, 0) GLU.gluSphere(quad, 1.0, 16, 16)
def visualisation_particle(self): # print('visualisation_particle') if len(self.list_of_solar_system) == 9: for k in range(len(self.list_of_solar_system)): sphere = glu.gluNewQuadric() gl.glPushMatrix() gl.glLightModelfv( gl.GL_LIGHT_MODEL_AMBIENT, self.list_of_solar_system[k].color) # цвет задаем gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, self.list_of_solar_system[k].color) gl.glTranslatef(self.list_of_solar_system[k].x * 7, self.list_of_solar_system[k].y * 7, self.list_of_solar_system[k].z * 7) glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL) if k == 0: glu.gluSphere(sphere, self.list_of_solar_system[k].m / 150000.0, 16, 16) if k == 1: glu.gluSphere(sphere, self.list_of_solar_system[k].m * 20, 16, 16) if k == 2: glu.gluSphere(sphere, self.list_of_solar_system[k].m * 2, 16, 16) if k == 3: glu.gluSphere(sphere, self.list_of_solar_system[k].m * 1.5, 16, 16) if k == 4: glu.gluSphere(sphere, self.list_of_solar_system[k].m * 7, 16, 16) if k == 5: glu.gluSphere(sphere, self.list_of_solar_system[k].m / 30, 16, 16) if k == 6: glu.gluSphere(sphere, self.list_of_solar_system[k].m / 12, 16, 16) if k == 7: glu.gluSphere(sphere, self.list_of_solar_system[k].m / 2.3, 16, 16) if k == 8: glu.gluSphere(sphere, self.list_of_solar_system[k].m / 3.2, 16, 16) gl.glTranslatef(-self.list_of_solar_system[k].x * 7, -self.list_of_solar_system[k].y * 7, -self.list_of_solar_system[k].z * 7) gl.glPopMatrix() glu.gluDeleteQuadric(sphere) self.update() else: # for l in self.general_list: # for k in range(len(l)): for k in range(len(self.list_of_particles)): sphere = glu.gluNewQuadric() gl.glPushMatrix() gl.glLightModelfv( gl.GL_LIGHT_MODEL_AMBIENT, self.list_of_particles[k].color) # цвет задаем gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, self.list_of_particles[k].color) gl.glTranslatef(self.list_of_particles[k].x, self.list_of_particles[k].y, self.list_of_particles[k].z) glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL) glu.gluSphere(sphere, self.list_of_particles[k].m / 100.0, 16, 16) gl.glTranslatef(-self.list_of_particles[k].x, -self.list_of_particles[k].y, -self.list_of_particles[k].z) gl.glPopMatrix() glu.gluDeleteQuadric(sphere) self.update()
def getPoint(self, pt): """Get x,y coords of pt in 3d space.""" pt2 = oglu.gluProject(*pt) return pt2[0], pt2[1]
def paintGL(self): ''' Renders the OpenGL scene. Gets called whenever the widget needs to be updated. ''' GL.glClearColor(0.5, 0.5, 0.5, 1.0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() # Correct a bug related with the overlap of contexts between simultaneous OpenGL windows. for index, frame in enumerate(self._pending_frames): #if self.zoom>=0: # frame = cv2.resize(frame, (int(frame.shape[0]/(2*(1-self.zoom))),int( frame.shape[1]/(2*(1-self.zoom))) )) color = GL.GL_LUMINANCE if len(frame.shape) == 2 else GL.GL_BGR w, h = len(frame[0]), len(frame) #Size of the image if len(self.textures) < len(self.image_2_display): self.textures.append(GL.glGenTextures(1)) #Load the textures to opengl GL.glEnable(GL.GL_TEXTURE_2D) GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) GL.glBindTexture(GL.GL_TEXTURE_2D, self.textures[index]) GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_BORDER) GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_BORDER) GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, w, h, 0, color, GL.GL_UNSIGNED_BYTE, frame) self._pending_frames = [] GL.glTranslatef(0, 0, -1) GL.glTranslatef(0, 0, -self.zoom) if len(self.image_2_display) > 1: #in case of having more images to display, it centers the images translate_x = float( (len(self.image_2_display) - 1) * self._width) / 2.0 GL.glTranslatef(-translate_x, 0, 0) if self._point is not None: GL.glColor4f(0, 0, 1, 1.0) GL.glPushMatrix() GL.glTranslatef(self._point[0], self._point[1], self._point[2]) self.draw_pyramid() GL.glPopMatrix() GL.glColor4f(1, 1, 1, 1.0) GL.glRotatef(self._rotateX, -1, 0, 0) GL.glRotatef(self._rotateZ, 0, 0, 1) GL.glDisable(GL.GL_TEXTURE_2D) GL.glColor4f(0, 0, 0, .0) GL.glBegin(GL.GL_QUADS) GL.glVertex3f(20, -20, -.01) GL.glVertex3f(20, 20, -.001) GL.glVertex3f(-20, 20, -.001) GL.glVertex3f(-20, -20, -.001) GL.glEnd() GL.glColor4f(1, 1, 1, 1.0) # mouse events: find the image position where the mouse is if self._mouse_pressed: modelview = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) projection = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) winX = float(self._mouseX) winY = float(viewport[3] - self._mouseY) winZ = GL.glReadPixels(winX, winY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT) self._glX, self._glY, self._glZ = GLU.gluUnProject( winX, winY, winZ[0][0], modelview, projection, viewport) if not self._last_mouse_gl_pos: self._last_mouse_gl_pos = self._glX, self._glY, self._glZ #mouse click event if self._mouse_clicked_event is not None: if hasattr(self, 'imgWidth'): self.onClick(self._mouse_clicked_event, self._get_current_x(), self._get_current_y()) if self._mouse_clicked_event.button == 1: self._mouse_leftbtn_pressed = True self._mouseStartDragPoint = self._get_current_mouse_point() if self._mouse_clicked_event.button == 4: self._mouseStartDragPoint = self._get_current_mouse_point() self._move_img = True self._last_mouse_gl_pos = None self._lastGlX = self._glX self._lastGlY = self._glY self._mouse_clicked_event = None #mouse double click event if self._mouse_dblclicked_event is not None: if hasattr(self, 'imgWidth'): self.onDoubleClick(self._mouse_dblclicked_event, self._get_current_x(), self._get_current_y()) self._mouse_dblclicked_event = None #mouse move event if self._mouse_move_event is not None: if self._mouse_leftbtn_pressed and self._mouse_pressed: p1 = self._mouseStartDragPoint p2 = self._get_current_mouse_point() self.onDrag(p1, p2) if self._move_img and self._mouse_pressed: p1 = self._mouseStartDragPoint p2 = self._get_current_mouse_point() self.onDrag(p1, p2) self._mouse_move_event = None # end of the mouse events ################################# GL.glEnable(GL.GL_TEXTURE_2D) GL.glDisable(GL.GL_DEPTH_TEST) if self._move_img and self._last_mouse_gl_pos is not None: self._x -= (self._last_mouse_gl_pos[0] - self._glX) self._y -= (self._last_mouse_gl_pos[1] - self._glY) for texture_index in range(0, len(self.image_2_display)): if texture_index > 0: GL.glTranslatef(self._width, 0, 0) GL.glBindTexture(GL.GL_TEXTURE_2D, self.textures[texture_index]) self.draw_video(self._width, self._height, self._x, self._y, 0.0) GL.glEnable(GL.GL_DEPTH_TEST) if self._helpText is not None: self.qglColor(QtCore.Qt.black) self.renderText(5, 31, self._helpText, font=self._font) self.qglColor(QtCore.Qt.white) self.renderText(4, 30, self._helpText, font=self._font) if self._tmp_msg is not None: self.qglColor(QtCore.Qt.black) self.renderText(5, self.height() - 19, self._tmp_msg, font=self._font) self.qglColor(QtCore.Qt.white) self.renderText(4, self.height() - 20, self._tmp_msg, font=self._font) if self._move_img: self._last_mouse_gl_pos = self._glX, self._glY, self._glZ
def __init__(self): self.sphere = GLU.gluNewQuadric() GLU.gluQuadricNormals(self.sphere, GLU.GLU_SMOOTH) GLU.gluQuadricTexture(self.sphere, gl.GL_TRUE)
class GLDisplayContext(object): def __init__(self, splash=None, caption=("", "")): self.win = None self.reset(splash, caption=caption) @staticmethod def getWindowSize(): w, h = (config.settings.windowWidth.get(), config.settings.windowHeight.get()) return max(20, w), max(20, h) @staticmethod def displayMode(): return pygame.OPENGL | pygame.RESIZABLE | pygame.DOUBLEBUF def reset(self, splash=None, caption=("", "")): pygame.key.set_repeat(500, 100) try: display.gl_set_attribute(pygame.GL_SWAP_CONTROL, config.settings.vsync.get()) except Exception, e: logging.warning('Unable to set vertical sync: {0!r}'.format(e)) display.gl_set_attribute(pygame.GL_ALPHA_SIZE, 8) if DEBUG_WM: print "config.settings.windowMaximized.get()", config.settings.windowMaximized.get( ) wwh = self.getWindowSize() if DEBUG_WM: print "wwh 1", wwh d = display.set_mode(wwh, self.displayMode()) # Let initialize OpenGL stuff after the splash. GL.glEnableClientState(GL.GL_VERTEX_ARRAY) GL.glAlphaFunc(GL.GL_NOTEQUAL, 0) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) # textures are 256x256, so with this we can specify pixel coordinates # GL.glMatrixMode(GL.GL_TEXTURE) # GL.glScale(1 / 256., 1 / 256., 1 / 256.) display.set_caption(*caption) if mcplatform.WindowHandler: self.win = mcplatform.WindowHandler(mode=self.displayMode()) # The following Windows specific code won't be executed if we're using '--debug-wm' switch. if not USE_WM and sys.platform == 'win32' and config.settings.setWindowPlacement.get( ): config.settings.setWindowPlacement.set(False) config.save() X, Y = config.settings.windowX.get(), config.settings.windowY.get() if X: hwndOwner = display.get_wm_info()['window'] flags, showCmd, ptMin, ptMax, rect = mcplatform.win32gui.GetWindowPlacement( hwndOwner) realW = rect[2] - rect[0] realH = rect[3] - rect[1] showCmd = config.settings.windowShowCmd.get() rect = (X, Y, X + realW, Y + realH) mcplatform.win32gui.SetWindowPlacement( hwndOwner, (0, showCmd, ptMin, ptMax, rect)) config.settings.setWindowPlacement.set(True) config.save() elif self.win: maximized = config.settings.windowMaximized.get() if DEBUG_WM: print "maximized", maximized if maximized: geom = self.win.get_root_rect() in_w, in_h = self.win.get_size() x, y = int((geom[2] - in_w) / 2), int((geom[3] - in_h) / 2) os.environ['SDL_VIDEO_CENTERED'] = '1' else: os.environ['SDL_VIDEO_CENTERED'] = '0' x, y = config.settings.windowX.get( ), config.settings.windowY.get() wwh = self.win.get_size() if DEBUG_WM: print "x", x, "y", y print "wwh 2", wwh if splash: # Setup the OGL display GL.glLoadIdentity() GLU.gluOrtho2D(0, wwh[0], 0, wwh[1]) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_ACCUM_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT) swh = splash.get_size() _x, _y = (wwh[0] / 2 - swh[0] / 2, wwh[1] / 2 - swh[1] / 2) w, h = swh try: data = image.tostring(splash, 'RGBA_PREMULT', 1) except ValueError: data = image.tostring(splash, 'RGBA', 1) except ValueError: data = image.tostring(splash, 'RGB', 1) # Set the raster position GL.glRasterPos(_x, _y) GL.glDrawPixels(w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, numpy.fromstring(data, dtype='uint8')) if splash: display.flip() if self.win: if not maximized: wwh = self.getWindowSize() if DEBUG_WM: print "wwh 3", wwh self.win.set_position((x, y), update=True) if DEBUG_WM: print "* self.win.get_position()", self.win.get_position() try: iconpath = os.path.join(directories.getDataDir(), 'favicon.png') iconfile = file(iconpath, 'rb') icon = pygame.image.load(iconfile, 'favicon.png') display.set_icon(icon) except Exception, e: logging.warning('Unable to set icon: {0!r}'.format(e))
def display(self): gl.glClear(self.clear_bit) x,y,w,h=self.viewport gl.glMatrixMode (gl.GL_PROJECTION) gl.glLoadIdentity() if self.isperspect: fovy,aspect,zNear,zFar=self.glu_perspect #print fovy glu.gluPerspective(fovy,w/float(h),zNear,zFar) else: left,right,bottom,top,near,far=self.gl_orthog gl.glOrtho(left, right, bottom, top, near, far) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() eyex,eyey,eyez,centx,centy,centz,upx,upy,upz=self.glu_lookat glu.gluLookAt(eyex,eyey,eyez,centx,centy,centz,upx,upy,upz) #gl.glTranslatef(0,0,-150) self.mouse.applyTransformation() #Add objects #cube.display() #bsurf.display() #im2d.display() #cube.display() #cube2.display() #primitives.render_pot() #primitives.render2_pot() #t3d.display() #dp.display() ''' gl.glDisable(self.enab_light) gl.glColor3f(1.,1.,0.3) gl.glRasterPos3f(4.,4.,4.) for c in "hello :-)": glut.glutBitmapCharacter( glut.GLUT_BITMAP_TIMES_ROMAN_24, ord(c) ) gl.glEnable(self.enab_light) ''' self.plot.display() gl.glFlush() glut.glutSwapBuffers()
def setup_modelview(self): GLU.gluLookAt(-self.schematic.Width * 2.8, self.schematic.Height * 2.5 + 1, -self.schematic.Length * 1.5, self.schematic.Width, 0, self.schematic.Length, 0, 1, 0)
def resize(self, Width, Height): print("please overrider resize") gl.glViewport(0, 0, Width, Height) glu.gluPerspective(45.0, float(Width) / float(Height), 0.1, 1000.0)
def paintGL(self): GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glPushMatrix() GL.glLoadIdentity() GLU.gluLookAt(self.camera.eye.x, self.camera.eye.y, self.camera.eye.z, self.camera.at.x , self.camera.at.y, self.camera.at.z , self.camera.up.x , self.camera.up.y, self.camera.up.z) GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, (GL.GLfloat *4) ( self.camera.eye.x, self.camera.eye.y, self.camera.eye.z, 1 )) if self.wireframe: GL.glDisable(GL.GL_LIGHTING) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glColor3f(0, 1, 0) else: GL.glEnable(GL.GL_LIGHTING) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, (GL.GLfloat * 4) ( 1, 1, 1, 1 )) if self.display_object: self.display_object.draw() GL.glDisable(GL.GL_LIGHTING) if self.grid: glutils.draw_grid() if self.frameRef: glutils.draw_frame() GL.glEnable(GL.GL_LIGHTING) GL.glPopMatrix()