def loadProjection(self,force=False): """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. 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 self.perspective: GLU.gluPerspective(self.fovy,self.aspect,self.near,self.far) else: top = tan(self.fovy*0.5) * self.dist bottom = -top right = top * self.aspect left = bottom * self.aspect #print "Ortho",left,right,bottom,top,self.near,self.far GL.glOrtho(left,right,bottom,top,self.near,self.far) GL.glMatrixMode(GL.GL_MODELVIEW)
def reshape(self,w,h): #px,py,w,h=self.viewport gl.glViewport (0,0,w,h) self.viewport=(0,0,w,h) gl.glMatrixMode (gl.GL_PROJECTION) gl.glLoadIdentity () if self.isperspect: fovy,aspect,zNear,zFar=self.glu_perspect 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)
def onRender(self): gl.glEnable(gl.GL_DEPTH_TEST) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(45, self.width / self.height, 0.01, 80.0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glTranslated(0.0, 0.0, -self.camPosZ) # apply camera zooming gl.glRotated(self.angleY, 0.0, 1.0, 0.0) # apply camera rotation # draw particles for system in self.systems: system.render() # draw texts(F1 key) if not notext and self.text != 0: gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluOrtho2D(0, self.width, 0, self.height) gl.glDisable(gl.GL_DEPTH_TEST) gl.glColor3d(1.0, 1.0, 1.0) if self.text == 2: self.drawText(self.nbParticles, 4.0, 40.0) self.drawText(self.fps, 4.0, 8.0) # refresh sdl2.SDL_GL_SwapWindow(self.window)
def _setProjective(self): """ Set the camera mode projective. A perspective distortion is applied and a three dimensional impression originates. :returns: None :rtype: None """ trace('set camera mode projective (%f° field of view)' % self.fow) # apply scale later by translating # the object on the z-axis glu.gluPerspective(self.fow, self.asprat, .1, 100.) # translatation based on the offset alpha = math.radians(self.fow / 2) arcsin = 1 / math.sin(alpha) dx = math.sqrt(arcsin - 1) + 0.5 # translation based on the aspect ratio ratio = 1. if self.asprat > 1 else self.asprat self.translation = -dx * (self.offset / ratio) - 2.
def Pick(self): self.globFrame.named = False for element in self.elements: element.named = False gl.glSelectBuffer(512) gl.glRenderMode(gl.GL_SELECT) gl.glInitNames() gl.glPushMatrix() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPickMatrix(self.lastx, self.size.height-self.lasty ,0.25, 0.25, [0, 0, self.size.width, self.size.height]) glu.gluPerspective(self.fov, self.aspect, 0.2, 200.0) gl.glMatrixMode(gl.GL_MODELVIEW) self.CameraTransformation() self.OnDraw() my_buffer = gl.glRenderMode(gl.GL_RENDER) gl.glPopMatrix() gl.glPushMatrix() 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.OnDraw() self.Redraw() gl.glPopMatrix() return my_buffer
def display(self): self.fps_frame += 1 self.fps_time = glut.glutGet(glut.GLUT_ELAPSED_TIME) if self.fps_time - self.fps_timebase > 1000: print('FPS:%4.2f' % (self.fps_frame * 1000.0 / (self.fps_time - self.fps_timebase))) self.fps_timebase = self.fps_time self.fps_frame = 0 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) self.mouse.applyTransformation() #Add objects self.plot.display() gl.glFlush() glut.glutSwapBuffers()
def paintGL(self): gl.glClear (gl.GL_COLOR_BUFFER_BIT|gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(45.0, 4.0/3.0, 0.1, 100.0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() glu.gluLookAt(4, 3, 3, 0, 0, 0, 0, 1, 0) self._texture_id = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D, self._texture_id) gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGB, self._width, self._height, 0, gl.GL_BGR, gl.GL_UNSIGNED_BYTE, self._texture_data) 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_LINEAR) gl.glGenerateMipmap(gl.GL_TEXTURE_2D) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo) gl.glVertexPointer(3, gl.GL_FLOAT, 0, None) gl.glEnableVertexAttribArray(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._uv_buffer) gl.glVertexAttribPointer(1, 2, gl.GL_FLOAT, gl.GL_FALSE, 0, None) gl.glBindAttribLocation(self._shader_program, 1, "vertex_uv") gl.glLinkProgram(self._shader_program) gl.glUseProgram(self._shader_program) print gl.glGetProgramiv(self._shader_program, gl.GL_LINK_STATUS) gl.glDrawArrays(gl.GL_TRIANGLES, 0, 12*3)
def main(): GLUT.glutInit(argv) GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE) larguraTela = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH) alturaTela = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT) larguraJanela = round(2 * larguraTela / 3) alturaJanela = round(2 * alturaTela / 3) GLUT.glutInitWindowSize(larguraJanela, alturaJanela) GLUT.glutInitWindowPosition(round((larguraTela - larguraJanela) / 2), round((alturaTela - alturaJanela) / 2)) GLUT.glutCreateWindow(janela) GLUT.glutDisplayFunc(draw) load() GL.glEnable(GL.GL_MULTISAMPLE) GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_TEXTURE_2D) GL.glClearColor(*corFundo) GL.glClearDepth(1.0) GL.glDepthFunc(GL.GL_LESS) GL.glShadeModel(GL.GL_SMOOTH) GL.glMatrixMode(GL.GL_PROJECTION) GLU.gluPerspective(-45, larguraJanela / alturaJanela, 0.1, 100.0) GL.glTranslatef(0.0, 0.0, -10) GL.glMatrixMode(GL.GL_MODELVIEW) GLUT.glutTimerFunc(10, timer, 1) GLUT.glutMainLoop()
def reshape(self, w, h): gl.glViewport(0, 0, w, h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(45, w / h, 1, 100) gl.glMatrixMode(gl.GL_MODELVIEW)
def frustum(self, mode, size): """Set up the viewing Frustum""" if size and size[1]: aspect = float(size[0]) / float(size[1]) else: aspect = 1.0 GLU.gluPerspective(self.fov * 180.0 / pi, aspect, 0.001, 1000.0)
def tkRedraw(self, *dummy): """Cause the opengl widget to redraw itself.""" self.freecalc(self) if not self.initialised: return self.activate() self.update_idletasks() self.activate() w = self.winfo_width() h = self.winfo_height() GL.glViewport(0, 0, w, h) # Clear the background and depth buffer. #GL.glClearColor(self.r_back, self.g_back, self.b_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, float(w) / float(h), self.near, self.far) if 0: # Now translate the scene origin away from the world origin glMatrixMode(GL_MODELVIEW) mat = glGetDoublev(GL_MODELVIEW_MATRIX) glLoadIdentity() glTranslatef(-self.xcenter, -self.ycenter, -(self.zcenter + self.distance)) glMultMatrixd(mat) else: GLU.gluLookAt(self.xcenter, self.ycenter, self.zcenter + self.distance, self.xcenter, self.ycenter, self.zcenter, 0., 1., 0.) GL.glMatrixMode(GL.GL_MODELVIEW) # Call objects redraw method. self.redraw(self)
def init_gl(self): """ Initialise OpenGL settings """ self.sphere = GL.glGenLists(1) GL.glNewList(self.sphere, GL.GL_COMPILE) quad_obj = GLU.gluNewQuadric() GLU.gluQuadricDrawStyle(quad_obj, GLU.GLU_FILL) GLU.gluQuadricNormals(quad_obj, GLU.GLU_SMOOTH) GLU.gluSphere(quad_obj, 1, 16, 16) GL.glEndList() GL.glShadeModel(GL.GL_SMOOTH) GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_CULL_FACE) GL.glEnable(GL.GL_LIGHTING) # make sure normal vectors of scaled spheres are normalised GL.glEnable(GL.GL_NORMALIZE) GL.glEnable(GL.GL_LIGHT0) light_pos = list(_LIGHT_POSITION) + [1] GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_pos) GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [1.0, 1.0, 1.0, 1.0]) GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, [0.2, .2, .2, 1]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [0.7, 0.7, 0.7, 1]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, [0.1, 0.1, 0.1, 1]) GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 20) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(60, 1, .01, 10) GL.glMatrixMode(GL.GL_MODELVIEW)
def reshape(self, w, h): gl.glViewport(0, 0, w, h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(45, w/h, 1, 100) gl.glMatrixMode(gl.GL_MODELVIEW)
def resizeGL(self, width, height): if width == 0 or height == 0: return # Set our viewport to the size of our window GL.glViewport(0, 0, width, height) # Switch to the projection matrix so that we can manipulate how our scene is viewed GL.glMatrixMode(GL.GL_PROJECTION) # Reset the projection matrix to the identity matrix so that we don't get any artifacts (cleaning up) GL.glLoadIdentity() # Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes vMin, vMax = self.getBoundingBox() near = 1.0 far = 100.0 aspectRatio = float(width) / float(height) if vMax is not None and vMin is not None: d = vMax - vMin d = math.sqrt(d[0] ** 2 + d[1] ** 2 + d[2] ** 2) far = d * 3.0 # print 'Far plane: ',far if self.prespective: GLU.gluPerspective(60, aspectRatio, near, far) else: h = (vMax[1] - vMin[1]) * aspectRatio center = (vMax[1] - vMin[1]) / 2 GL.glOrtho(center - h / 2, center + h / 2, vMin[1], vMax[1], near, far) # Switch back to the model view matrix, so that we can start drawing shapes correctly 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 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 perspective(self): gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(45, 640 / 480, 0.1, 30.0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glEnable(gl.GL_DEPTH_TEST)
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 prepere_scene(self): gl.glClearColor(1.0, 1.0, 1.0, 1.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() x, y, width, height = gl.glGetDoublev(gl.GL_VIEWPORT) if self.ViewOrtho == False: glu.gluPerspective( 45, # field of view in degrees width / float(height or 1), # aspect ratio .25, # near clipping plane 200) # far clipping plane else: radius = .5 * min(width, height) w, h = width / radius, height / radius gl.glOrtho( -2 * w, # GLdouble left 2 * w, # GLdouble right -2 * h, # GLdouble bottom 2 * h, # GLdouble top -0.25, # GLdouble near 200.0) # GLdouble far gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity()
def main(args=sys.argv[1:]): json_fn, = args with open(json_fn) as f: world = json.load(f, object_hook=AttributeDict.object_hook) w, h = 800, 600 pygame.init() pygame.display.set_mode((w, h), pygame.DOUBLEBUF | pygame.OPENGL) GL.glMatrixMode(GL.GL_PROJECTION) # 45° FoV, aspect ratio, zNear clip, zFar clip. GLU.gluPerspective(45, w/h, 0.2, 20.0) origin = np.mean(np.array([world.airspace.min, world.airspace.max]), axis=0) GL.glEnable(GL.GL_BLEND) #GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_DEPTH_TEST) GL.glDepthFunc(GL.GL_LESS) GL.glMatrixMode(GL.GL_MODELVIEW) # Viewport starts with Y up and Z going away from the camera GL.glTranslate(0.0, -0.0, -3) GL.glRotate(-75.0, 1, 0, 0) t0 = time.time() while True: t1 = time.time() dt = t1-t0 t0 = t1 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() return GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glRotate(-30*dt, 0, 0, 1) GL.glPushMatrix() GL.glTranslate(*-origin) draw_grid() draw_airspace(world.airspace.min, world.airspace.max) for wall in world.walls: draw_wall(wall.plane.start, wall.plane.stop) for marker in world.markers: draw_marker(marker.id, marker.pose.position, marker.pose.orientation) for roadsign in world.roadsigns: draw_roadsign(roadsign.sign, roadsign.pose.position, roadsign.pose.orientation) GL.glPopMatrix() pygame.display.flip() pygame.time.wait(int(1000/60 - dt))
def resizeGL(self, width, height): if height == 0: height = 1 #glViewport(self.posx, self.posy, self.posx + width, self.posy + height) glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() self.identity = glGetDouble(GL_PROJECTION_MATRIX) self.aspect = width / float(height) self.width = width self.height = height GLU.gluPerspective(45.0, self.aspect, 0.2, 400000.0) self.proj_matrix = glGetDouble(GL_PROJECTION_MATRIX) glMatrixMode(GL_MODELVIEW) # only here should it be. Set aspect, viewport in shaders. glUseProgram(self.main_shader_program.program_id) viewport_data = numpy.array( [0.0, 0.0, float(self.width), float(self.height)], numpy.float32) aspect_data = numpy.array([self.aspect], numpy.float32) self.main_shader_program.setUniformValue('viewport', viewport_data) self.main_shader_program.setUniformValue('aspect', aspect_data) glUseProgram(0)
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 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 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 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 resizeGL(self, width, height): height = 1 if not height else height glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() GLU.gluPerspective(45.0, float(width) / height, 100, 100000) glMatrixMode(GL_MODELVIEW)
def resizeGL(self, width, height): ''' 函数原型为:glViewport(GLint x,GLint y,GLsizei width,GLsizei height) x,y 以像素为单位,指定了视口的左下角位置。 width,height 表示这个视口矩形的宽度和高度,根据窗口的实时变化重绘窗口。 ''' gl.glViewport(0, 0, width, height) ''' OpenGL支持两种类型的投影变换,即透视投影和正投影。投影也是使用矩阵来实现的。 如果需要操作投影矩阵,需要以GL_PROJECTION为参数调用glMatrixMode函数。 ''' gl.glMatrixMode(gl.GL_PROJECTION) # 把当前矩阵设置为单位矩阵 gl.glLoadIdentity() aspect = width / float(height) ''' GLU.gluPerspective(fovy,aspect,znear,zfar)fovy是眼睛上下睁开的幅度,角度值,值越小,视野范围越狭小(眯眼),值越大,视野范围越宽阔(睁开铜铃般的大眼); aspect表示裁剪面的宽w高h比,这个影响到视野的截面有多大。 zNear表示近裁剪面到眼睛的距离,zFar表示远裁剪面到眼睛的距离,注意zNear和zFar不能设置设置为负值(你怎么看到眼睛后面的东西)。 ''' GLU.gluPerspective(45.0, aspect, 1.0, 1000.0) # gl.GL_MODELVIEW说明接下来进行视景矩阵进行操作 gl.glMatrixMode(gl.GL_MODELVIEW) '''GLU.gluLookAt函数定义一个视图矩阵,并与当前矩阵相乘。 第一组eyex, eyey,eyez 相机在世界坐标的位置:就是脑袋的位置 第二组centerx,centery,centerz 相机镜头对准的物体在世界坐标的位置:就是眼睛看的物体的位置 第三组upx,upy,upz 相机向上的方向在世界坐标中的方向:就是头顶朝向的方向(因为你可以歪着头看同一个物体) ''' GLU.gluLookAt(0,0,1, 0,0,0, 1,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 render(self): """ Render the scene using the sphere display list """ if self.do_exit: print('renderer exiting ...') # glut event loop needs hard exit ... sys.exit(0) if self.bodies is None: time.sleep(1 / self.fps) return GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() x_size = GLUT.glutGet(GLUT.GLUT_WINDOW_WIDTH) y_size = GLUT.glutGet(GLUT.GLUT_WINDOW_HEIGHT) GLU.gluPerspective(60, float(x_size) / float(y_size), 0.05, 10) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glTranslatef(-_CAMERA_POSITION[0], -_CAMERA_POSITION[1], -_CAMERA_POSITION[2]) self.mouse_interactor.apply_transformation() for body_index in range(self.bodies.shape[0]): body = self.bodies[body_index, :] GL.glPushMatrix() GL.glTranslatef(body[0], body[1], body[2]) GL.glScalef(body[3], body[3], body[3]) GL.glCallList(self.sphere) GL.glPopMatrix() GLUT.glutSwapBuffers()
def initializeGL(self): """ Initialize GL """ GL.glClearColor(1., 1., 1., 1.) GL.glShadeModel(GL.GL_SMOOTH) glEnable(GL.GL_CULL_FACE) glEnable(GL.GL_DEPTH_TEST) glEnable(GL.GL_LIGHTING) lightZeroPosition = [-800., 500., 1500., 1.] lightZeroColor = [1.0, 1., 1., 1.0] #green tinged glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightZeroPosition) glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, lightZeroColor) glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [0.5, 0.5, 0.5, 1.0]) GL.glLightf(GL.GL_LIGHT0, GL.GL_CONSTANT_ATTENUATION, 1.000) #glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.01) glEnable(GL.GL_LIGHT0) glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, [100., 200., -20., 1.]) glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, [1., 1., 1., 1.0]) glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0]) glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, [0., 0., 0., 1.0]) GL.glLightf(GL.GL_LIGHT1, GL.GL_CONSTANT_ATTENUATION, 1) #glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.01) glEnable(GL.GL_LIGHT1) GL.glShadeModel(GL.GL_SMOOTH) 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()
def paintGL(self): gl.glClear (gl.GL_COLOR_BUFFER_BIT|gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(45.0, 4.0/3.0, 0.1, 100.0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() glu.gluLookAt(4, 3, 10, 0, 0, 0, 0, 1, 0) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo) gl.glVertexPointer(3, gl.GL_FLOAT, 0, None) gl.glLinkProgram(self._shader_program) gl.glUseProgram(self._shader_program) model = math3d.Matrix44.translate(0, 0, 0) view = math3d.Matrix44.look_at_right_hand( math3d.Vector(4, 3, 10), math3d.Vector(0, 0, 0), math3d.Vector(0, 1, 0)) projection = math3d.Matrix44.projection_right_hand( math.radians(45), 4.0/3.0, 0.1, 100.0) mvp = model*view*projection mvp_id = gl.glGetUniformLocation(self._shader_program, "mvp") gl.glUniformMatrix4fv(mvp_id, 1, gl.GL_FALSE, mvp.raw_data()) gl.glDrawArrays(gl.GL_TRIANGLES, 0, self._vertices.size)
def main(): light_position = (7, 2, 1) GLUT.glutInit(argv) GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE) larguraTela = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH) alturaTela = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT) larguraJanela = round(2 * larguraTela / 3) alturaJanela = round(2 * alturaTela / 3) GLUT.glutInitWindowSize(larguraJanela, alturaJanela) GLUT.glutInitWindowPosition(round((larguraTela - larguraJanela) / 2), round((alturaTela - alturaJanela) / 2)) GLUT.glutCreateWindow(janela) GLUT.glutReshapeFunc(reshape) GLUT.glutDisplayFunc(draw) GLUT.glutMouseFunc(clique) GL.glShadeModel(GL.GL_SMOOTH) GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, dados[0][0]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, dados[0][1]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, dados[0][2]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, dados[0][3]) GL.glEnable(GL.GL_LIGHTING) GL.glEnable(GL.GL_LIGHT0) GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position) GL.glEnable(GL.GL_MULTISAMPLE) GL.glEnable(GL.GL_DEPTH_TEST) GL.glClearColor(*corFundo) GLU.gluPerspective(45, larguraJanela / alturaJanela, 0.1, 50.0) GLUT.glutTimerFunc(50, timer, 1) GLUT.glutMainLoop()
def reshape(w,h): GL.glViewport(0,0,w,h) GL.glMatrixMode(GL.GL_PROJECTION) GLU.gluPerspective(45, float(w) / float(h), 0.1, 50.0) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GLU.gluLookAt(10,0,0,0,0,0,0,1,0)
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 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 start_screen(self, delta_time, speed): """Updating a welcome screen (like a screensaver)""" gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(80, self.win_w / self.win_h, 0.1, 10000) glu.gluLookAt(0, 0, 0, 0, 100, 0, 0, 0, 1) self.skybox.sky_pos = self.ship.pos self.light.disable() self.skybox.render(self.camera) self.light.enable() for ast in self.asteroids: if ast.pos[2] < -CAMERA_DIST - 10: ast.pos[0] = random.randint( (int)(self.ship.pos[0]) - AST_RANGE, (int)(self.ship.pos[0]) + AST_RANGE) ast.pos[1] = random.randint( (int)(self.ship.pos[1]) + AST_Y_MIN_INIT, (int)(self.ship.pos[1]) + AST_Y_MAX_INIT) ast.pos[2] = random.randint( (int)(self.ship.pos[2]) - AST_RANGE, (int)(self.ship.pos[2]) + AST_RANGE) else: ast.pos[1] -= speed * delta_time * 0.1 ast.render() self.light.render()
def resizeGL(self, width, height): gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(90, width / height, 0.1, 10000) gl.glMatrixMode(gl.GL_MODELVIEW)
def resizeGL(self, width, height): glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() GLU.gluPerspective(10.0, width / height, 1.0, 100.0) glMatrixMode(GL_MODELVIEW)
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 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 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 resizeGL(self, width, height): if height == 0: height = 1 GL.glViewport(0, 0, width, height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(45.0, (width / height), 1.0, 100.0) GL.glMatrixMode(GL.GL_MODELVIEW)
def resizeGL(Width, Height): if (Height == 0): Height = 1 GL.glViewport(0, 0, Width, Height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(45.0, float(Width)/float(Height), 0.1, 100.0)
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 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, 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 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(40.0, 1., 0.2, 200.0) gl.glMatrixMode(gl.GL_MODELVIEW) self.CameraTransformation()
def resizeGL(self, width, height): if width == 0 or height == 0: return # Set our viewport to the size of our window GL.glViewport(0, 0, width, height) # Switch to the projection matrix so that we can manipulate how our scene is viewed GL.glMatrixMode(GL.GL_PROJECTION) # Reset the projection matrix to the identity matrix so that we don't get any artifacts (cleaning up) GL.glLoadIdentity() # Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes vMin, vMax = self.getBoundingBox() near = 1.0 far = 100.0 aspectRatio = float(width) / float(height) if vMax is not None and vMin is not None: d = vMax - vMin d = math.sqrt(d[0]**2 + d[1]**2 + d[2]**2) far = d * 3.0 # print 'Far plane: ',far if self.prespective: GLU.gluPerspective(60, aspectRatio, near, far) else: h = (vMax[1] - vMin[1]) * aspectRatio center = (vMax[1] - vMin[1]) / 2 GL.glOrtho(center - h / 2, center + h / 2, vMin[1], vMax[1], near, far) # Switch back to the model view matrix, so that we can start drawing shapes correctly GL.glMatrixMode(GL.GL_MODELVIEW)
def paintGL(self): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(45.0, 4.0 / 3.0, 0.1, 100.0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() glu.gluLookAt(4, 3, 10, 0, 0, 0, 0, 1, 0) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo) gl.glVertexPointer(3, gl.GL_FLOAT, 0, None) gl.glLinkProgram(self._shader_program) gl.glUseProgram(self._shader_program) model = math3d.Matrix44.translate(0, 0, 0) view = math3d.Matrix44.look_at_right_hand(math3d.Vector(4, 3, 10), math3d.Vector(0, 0, 0), math3d.Vector(0, 1, 0)) projection = math3d.Matrix44.projection_right_hand( math.radians(45), 4.0 / 3.0, 0.1, 100.0) mvp = model * view * projection mvp_id = gl.glGetUniformLocation(self._shader_program, "mvp") gl.glUniformMatrix4fv(mvp_id, 1, gl.GL_FALSE, mvp.raw_data()) gl.glDrawArrays(gl.GL_TRIANGLES, 0, self._vertices.size)
def on_reshape(width, height): gl.glViewport(0, 0, width, height) gl.glMatrixMode( gl.GL_PROJECTION ) gl.glLoadIdentity( ) glu.gluPerspective( 45.0, float(width)/float(height), 2.0, 10.0 ) gl.glMatrixMode( gl.GL_MODELVIEW ) gl.glLoadIdentity( ) gl.glTranslatef( 0.0, 0.0, -5.0 )
def resizeGL(self, width, height): glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() GLU.gluPerspective(60.0, (float(width) / float(height)), 1.0, 100.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslate(0, 0, -10.0)
def camera(): gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() fov_y = 55.0 aspect = float(width / height) near = 1.0 far = 50.0 glu.gluPerspective(fov_y, aspect, near, far)
def resizeGL(self, width, height): if height == 0: height = 1 glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() aspect = width / float(height) GLU.gluPerspective(45.0, aspect, 1.0, 100.0) glMatrixMode(GL_MODELVIEW)
def resizeGL(self, w, h): """ Resize the GL window """ GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(40.0, float(w)/float(h), 1.0, 40.0)
def resizeGL(self, w, h): ratio = w if h == 0 else float(w) / h gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glViewport(0, 0, w, h) gl.glLoadIdentity() glu.gluPerspective(90, float(ratio), self.near_z, self.far_z) gl.glMatrixMode(gl.GL_MODELVIEW)
def resizeGL(self, width, height): GL.glViewport(0, 0, width, height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(90.0, float(self.width())/self.height(), 1.0, 100.0) GL.glMatrixMode(GL.GL_MODELVIEW)
def resizeGL(self,w,h): if h == 0: h = 1 GL.glViewport(0,0,w,h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(45.0,float(w)/float(h),0.1,750.0) GL.glMatrixMode(GL.GL_MODELVIEW)