def paintGL(self): #This function uses shape objects, such as cube() or meshSector(). Shape objects require the following: #a list named 'vertices' - This list is a list of points, from which edges and faces are drawn. #a list named 'wires' - This list is a list of tuples which refer to vertices, dictating where to draw wires. #a list named 'facets' - This list is a list of tuples which refer to vertices, ditating where to draw facets. #a bool named 'render' - This bool is used to dictate whether or not to draw the shape. #a bool named 'drawWires' - This bool is used to dictate whether wires should be drawn. #a bool named 'drawFaces' - This bool is used to dictate whether facets should be drawn. glLoadIdentity() gluPerspective(45, self.width / self.height, 0.1, 110.0) #set perspective? glTranslatef(0, 0, self.zoomLevel) #I used -10 instead of -2 in the PyGame version. glRotatef(self.rotateDegreeV, 1, 0, 0) #I used 2 instead of 1 in the PyGame version. glRotatef(self.rotateDegreeH, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) if len(self.shapes) != 0: glBegin(GL_LINES) for s in self.shapes: glColor3fv(s.color) if s.render and s.drawWires: for w in s.wires: for v in w: glVertex3fv(s.vertices[v]) glEnd() glBegin(GL_QUADS) for s in self.shapes: glColor3fv(s.color) if s.render and s.drawFaces: for f in s.facets: for v in f: glVertex3fv(s.vertices[v]) glEnd()
def display(): glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0, 1.0, 1.0) glMatrixMode(GL_PROJECTION) glLoadIdentity() if cam.projection_mode == "ortho": width_ratio = DISPLAY_WIDTH / DISPLAY_HEIGHT zoom = -cam.cur_position.z if zoom > 0: glOrtho(-zoom * width_ratio, zoom * width_ratio, -zoom, zoom, .5, 100) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotated(cam.cur_rotation, 0, 1, 0) glTranslated(cam.cur_position.x, cam.cur_position.y, cam.cur_position.z) else: gluPerspective(60, (DISPLAY_WIDTH / DISPLAY_HEIGHT), 0.1, 100.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotated(cam.cur_rotation, 0, 1, 0) glTranslated(cam.cur_position.x, cam.cur_position.y, cam.cur_position.z) draw_neighborhood() animate_car() glFlush()
def display(): glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0, 1.0, 1.0) glMatrixMode(GL_PROJECTION) glLoadIdentity() if projection_mode == "ortho": width_ratio = DISPLAY_WIDTH / DISPLAY_HEIGHT zoom = -cam_z if zoom > 0: glOrtho(-zoom * width_ratio, zoom * width_ratio, -zoom, zoom, .5, 100) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotated(rot_deg, 0, 1, 0) glTranslated(cam_x, cam_y, cam_z) else: gluPerspective(55, (DISPLAY_WIDTH / DISPLAY_HEIGHT), 0.1, 100.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotated(rot_deg, 0, 1, 0) glTranslated(cam_x, cam_y, cam_z) drawTestShape() drawAxisOfRotation() if transform: shape_offset = [30, 0, 40] # problem 1 transform_shape(shape_offset, 40) glFlush()
def make_coord_system_eye_camera_based(window_size, focal_length): camera_fov = math.degrees(2.0 * math.atan(window_size[1] / (2.0 * focal_length))) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(camera_fov, float(window_size[0]) / window_size[1], 0.1, 2000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity()
def SetupProjection(self, width = 640, height = 480, zNear = 5., zFar = 300.): """ Sets up the projection matrix for opengl. """ # set the projection transformation glMatrixMode(GL_PROJECTION) glLoadIdentity() #TODO: replace the glu call with something else. #gluPerspective(45.0, float(width) / height, scale * 50.0, scale * 1000.0) #gluPerspective(45.0, float(self.width) / float(self.height), 5.0, 1000.0) self.zNear = zNear self.zFar = zFar self.buffer_calc_a = self.zFar / ( self.zFar - self.zNear ) self.buffer_calc_b = self.zFar * self.zNear / ( self.zNear - self.zFar ) gluPerspective(45.0, float(width) / float(height), self.zNear, self.zFar) self.gl_projection_matrix = glGetFloatv(GL_PROJECTION_MATRIX) # set the model transformation glMatrixMode(GL_MODELVIEW)
def reshape_function(self, w, h): # prevent dividing by zero if window height is 0 if h == 0: h = 1 self.window_width = w self.window_height = h proportional_rate = float(w) / h glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60.0, proportional_rate, 0.1, 100) camera_settings_matrix = [0 for i in range(9)] # calculate camera's point of view camera_settings_matrix = self.recalculate_camera_settings( camera_settings_matrix) # set camera's point of view gluLookAt(camera_settings_matrix[0], camera_settings_matrix[1], camera_settings_matrix[2], camera_settings_matrix[3], camera_settings_matrix[4], camera_settings_matrix[5], camera_settings_matrix[6], camera_settings_matrix[7], camera_settings_matrix[8]) glScalef(self.scale_factor, self.scale_factor, self.scale_factor) glMatrixMode(GL_MODELVIEW)
def make_coord_system_eye_camera_based(window_size, focal_length ): camera_fov = math.degrees(2.0 * math.atan( window_size[1] / (2.0 * focal_length))) glMatrixMode( GL_PROJECTION ) glLoadIdentity( ) gluPerspective( camera_fov, float(window_size[0])/window_size[1], 0.1, 2000.0 ) glMatrixMode( GL_MODELVIEW ) glLoadIdentity( )
def initialize(self): """ Set up the viewport. """ x, y = self.viewSize # Hide things that are behind other things glEnable(GL_DEPTH_TEST) # Create the OpenGL viewport, setting the size of the window (in pixels) # and defining how the scene is projected onto it. glViewport(0, 0, x, y) glMatrixMode(GL_PROJECTION) glLoadIdentity() # Field of view, aspect ratio, near clipping, far clipping gluPerspective(45.0, x / y, 0.5, 1000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # This makes material color properties be defined by glColor calls, # necessary to get the right colors when lighting is enabled. glEnable(GL_COLOR_MATERIAL) # This might be desirable at some point, who knows. # glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION) # Make lighting work, because we like lights. glEnable(GL_LIGHTING) # Make textures work too. glEnable(GL_TEXTURE_2D)
def prepare_environment(self): """Set basics needed to launch 3D game mode.""" pygame.display.set_mode(self.resolution, DOUBLEBUF | OPENGL | pygame.FULLSCREEN) gluPerspective(45, (self.resolution[0] / self.resolution[1]), 0.1, 50) self.spawned_at = -10 self.wave = self.create_wave(Wave3D, self.spawned_at)
def pickup(event, right): """ Function to get the Name Stack right es si el boton pulsado es el derecho El viewport[3]-event.y() creo que es porque la medida de las Y está invertida Los problemas que tenía con windows de tener que hacer varios click se corrigieron sustituyendo la región de selección de 1,1 a 5,5 """ viewport = glGetIntegerv(GL_VIEWPORT) glMatrixMode(GL_PROJECTION) glPushMatrix() glSelectBuffer(512) glRenderMode(GL_SELECT) glLoadIdentity() gluPickMatrix(event.x(), viewport[3] - event.y(), 4, 4, viewport) aspect = viewport[2] / viewport[3] gluPerspective(60, aspect, 1.0, 400) glMatrixMode(GL_MODELVIEW) self.paintGL() glMatrixMode(GL_PROJECTION) if right == False: parseLeftButtonNameStack(glRenderMode(GL_RENDER)) else: parseRightButtonNameStack(glRenderMode(GL_RENDER)) glPopMatrix() glMatrixMode(GL_MODELVIEW)
def handle_reshape(self, width, height): glLoadIdentity() aspect = height / width glViewport(0, 0, width, height) gluPerspective(45.0, 1 / aspect, 0.1, 2000.0)
def resizeGL(self, width, height): glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() aspect = width / height gluPerspective(60.0, aspect, 1, 400) glMatrixMode(GL_MODELVIEW)
def reshape(self, width, height): glClearColor(0.0, 0.0, 0.0, 1.0) glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60, width / height, 1.0, 10000.0) glMatrixMode(GL_MODELVIEW)
def paintGL(self): if self.crashFlag: #run cleanup operations glUseProgram(0) glDisableVertexAttribArray(self.attrID) glDeleteBuffers(1,[self.vertexBuffer]) glDeleteVertexArrays(1, [self.vertexArrayID]) glLoadIdentity() gluPerspective(45, self.sizeX / self.sizeY, 0.1, 110.0) #set perspective glTranslatef(0, 0, self.zoomLevel) glRotatef(self.rotateDegreeV + self.vOffset, 1, 0, 0) glRotatef(self.rotateDegreeH, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) self.vertexData = [ -1, 1, 0, 0, -1, 0, 1, 1, 0 ] arrayType = GLfloat * len(self.vertexData) target = GL_ARRAY_BUFFER offset = 0 size = len(self.vertexData) * ctypes.sizeof(ctypes.c_float) data = arrayType(*self.vertexData) glBufferSubData(target, offset, size, data) glDrawArrays(GL_TRIANGLES, 0, 3)
def paintGL(self): glLoadIdentity() gluPerspective(45, self.width / self.height, 0.1, 110.0) #set perspective? glTranslatef( 0, 0, self.zoomLevel) #I used -10 instead of -2 in the PyGame version. glRotatef(self.rotateDegreeV, 1, 0, 0) #I used 2 instead of 1 in the PyGame version. glRotatef(self.rotateDegreeH, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) if len(self.shapes) != 0: glBegin(GL_LINES) for s in self.shapes: glColor3fv(s.color) if s.render and s.drawWires: for e in s.edges: for v in e: glVertex3fv(s.vertices[v]) glEnd() glBegin(GL_QUADS) for s in self.shapes: glColor3fv(s.color) if s.render and s.drawFaces: for f in s.facets: for v in f: glVertex3fv(s.vertices[v]) glEnd()
def main(): moons = [Moon(pos) for pos in d12_input] glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(800, 800) glutInitWindowPosition(350, 200) glutCreateWindow('name') glClearColor(0., 0., 0., 1.) glShadeModel(GL_SMOOTH) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) lightZeroPosition = [10., 4., 10., 1.] lightZeroColor = [0.8, 1.0, 0.8, 1.0] glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor) glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1) glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05) glEnable(GL_LIGHT0) glutDisplayFunc(lambda: display_scene(moons)) glutTimerFunc(0, timer, 0) glMatrixMode(GL_PROJECTION) gluPerspective(40., 1., 1., 40.) glMatrixMode(GL_MODELVIEW) gluLookAt(0, -10, 10, 0, 0, 0, 0, 1, 0) glPushMatrix() glutMainLoop()
def display(): glClear (GL_COLOR_BUFFER_BIT) glColor3f (1.0, 1.0, 1.0) # viewing transformation global chHor global chVert global home global ortho global chDepth global pers global chRot global totHor global totDepth global totRot #Your Code Here glMatrixMode(GL_MODELVIEW) glRotated(-totRot,0,10,0) glTranslated(-totHor,0,-totDepth) glRotated(chRot, 0, 1, 0) glTranslated(+totHor,0,+totDepth) glTranslated(chHor, chVert, chDepth) glRotated(totRot, 0, 10, 0) rad = math.radians(chRot) if(chRot > 0 or chRot < 0): totHor = totHor * math.cos(rad) + totDepth * math.sin(rad) totHorTemp = totHor totDepth = -totHorTemp * math.sin(rad) + totDepth * math.cos(rad) totHor += chHor totDepth += chDepth totRot += chRot if home == True: init() totRot = 0 totHor = 0 if ortho == True: glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(-10.0,10.0,-10.0,10.0,-100.0, 100.0) if pers == True: glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60, 1, 0, 100) chHor = 0 chVert = 0 home = False chDepth = 0 ortho = False pers = False chRot = 0 drawHouse() glFlush()
def keyboard(key, x, y): global mat, rot, animTrans, animRot if key == chr(27): import sys sys.exit(0) #Your Code Here if key == b'a': mat[2] = mat[2] - math.cos(math.radians(rot[0] + 90)) mat[0] = mat[0] + math.sin(math.radians(rot[0] + 90)) if key == b'd': mat[2] = mat[2] + math.cos(math.radians(rot[0] + 90)) mat[0] = mat[0] - math.sin(math.radians(rot[0] + 90)) if key == b'w': mat[2] = mat[2] + math.cos(math.radians(rot[0])) mat[0] = mat[0] - math.sin(math.radians(rot[0])) if key == b's': mat[2] = mat[2] - math.cos(math.radians(rot[0])) mat[0] = mat[0] + math.sin(math.radians(rot[0])) if key == b'q': rot[0] = rot[0] - 1 if key == b'e': rot[0] = rot[0] + 1 if key == b'r': mat[1] = mat[1] - 1 if key == b'f': mat[1] = mat[1] + 1 if key == b'h': mat = [0, -5, -35] rot = [0, 0, 0] animTrans = [0, 0, 0] animRot = [0, 0, 0] if key == b'o': glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(-50, 50, -50, 50, .1, 50) #glOrtho() if key == b'p': glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(50, DISPLAY_HEIGHT / DISPLAY_WIDTH, .1, 200) if key == b'z': import sys sys.exit(0) glutPostRedisplay()
def __applyProjection(self): if self.__orthographic_projection: w = self.__width_aspect * self.__zoom h = self.__height_aspect * self.__zoom glOrtho(-w, w, -h, h, 0, 2000) else: # glFrustum(-width_aspect, width_aspect, -height_aspect, height_aspect, 0.1, 20) gluPerspective(60 * self.__zoom, self.__aspect, 0.1, 3000)
def resizeGL(self, width, height): glViewport(0, 0, width, height if height else 1) glMatrixMode(GL_PROJECTION) glLoadIdentity() self.aspect = width / float(height) gluPerspective(45., self.aspect, 1., 100.) glMatrixMode(GL_MODELVIEW)
def resizeGL(self, w, h): self.w = w self.h = h glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w)/float(h), 0.1, 1000.0) glMatrixMode(GL_MODELVIEW)
def initialize_OpenGL(): pygame.init() display = (300, 300) pygame.display.set_mode(display, DOUBLEBUF | OPENGL, RESIZABLE) gluPerspective(45, (1.0 * display[0] / display[1]), 0.1, 50.0) glTranslatef(0.0, 0.0, -5)
def reshape(self, width, height): r = float(width) / float(height) glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60.0, r, 1., 50.) glMatrixMode(GL_MODELVIEW) glLoadIdentity()
def resizeGL(self, w, h): self.w = w self.h = h glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w) / float(h), 0.1, 1000.0) glMatrixMode(GL_MODELVIEW)
def window_resize(width, height): # pygame.display.set_mode((width, height), pygame.OPENGL | pygame.DOUBLEBUF | pygame.RESIZABLE) glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, width / height, 0.1, 100.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity()
def resizeGL(self, w, h): ''' Resize the GL window ''' glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(40.0, 1.0, 1.0, 30.0)
def init(): glClearColor(0.0, 0.0, 0.0, 0.0) glShadeModel(GL_FLAT) glMatrixMode(GL_PROJECTION) glLoadIdentity() # glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 100.0); gluPerspective(60, 1, 0, 100) glMatrixMode(GL_MODELVIEW) glLoadIdentity()
def resize((width, height)): if height==0: height=1 gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gluPerspective(45, 1.0*width/height, 0.1, 100.0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity()
def resizeGL(self, width, height): if height == 0: height = 1 glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(width) / float(height), 0.1, 100.0) glMatrixMode(GL_MODELVIEW)
def reshape(width, height): global w, h w = width h = height glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60, float(w) / float(h), .1, -2000) glMatrixMode(GL_MODELVIEW)
def resizeGL(self, width, height): if height == 0: height = 1 glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(width)/float(height), 0.1, 100.0) glMatrixMode(GL_MODELVIEW)
def __init__(self, periscope: Periscope = None): display = (1200, 900) pygame.display.set_mode(display, DOUBLEBUF | OPENGL) gluPerspective(45, (display[0] / display[1]), 0.1, 10.0) glTranslatef(-0.4, -0.5, -1) self.periscope: Periscope = periscope
def set_projection(self, near, far, fovy): self._near = near self._far = far self._fovy = fovy self.makeCurrent() glMatrixMode(GL_PROJECTION) glLoadIdentity() height = max(self.height(), 1) gluPerspective(self._fovy, float(self.width()) / float(height), self._near, self._far) self.updateGL()
def ViewportSetup(self): xSize, ySize = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) aspect_ratio = float(xSize) / float(ySize) self.aspect = aspect_ratio # set up the projection matrix glMatrixMode(GL_PROJECTION) glLoadIdentity() glViewport(0, 0, xSize, ySize) gluPerspective(self.fovy, self.aspect, self.near, self.far) # postcondition: matrix mode is modelview glMatrixMode(GL_MODELVIEW)
def main(): import sys from OpenGL.GLU import gluPerspective from pygame.constants import HWSURFACE, OPENGL, DOUBLEBUF, QUIT pygame.init() viewport = (800,600) hx = viewport[0]/2 hy = viewport[1]/2 srf = pygame.display.set_mode(viewport, HWSURFACE | OPENGL | DOUBLEBUF) glMatrixMode(GL_PROJECTION) glLoadIdentity() width, height = viewport gluPerspective(90.0, width/float(height), 1, 100.0) glMatrixMode(GL_MODELVIEW) glEnable(GL_COLOR_MATERIAL) glClearColor(0.0, 0.0, 0.0, 0.0) glEnable (GL_BLEND) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_TEXTURE_2D) glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ) glDisable(GL_DEPTH_TEST) clock=pygame.time.Clock() Sprite.init() while 1: clock.tick(30) for e in pygame.event.get(): if e.type == QUIT: sys.exit() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslate(0.0, 0.0, -5.0) Sprite.glow.draw( position=(-2.0, -2.5), color=(0.5, 1.0, 0.5) ) Sprite.beam.draw( position=(-3.0, -3.0), scale=(5.0, 0.25), color=(1.0, 0.5, 0.5) ) pygame.display.flip()
def push(self): glMatrixMode( GL_PROJECTION ) glPushMatrix() glLoadIdentity( ) gluPerspective( self.fov, self.aspect, 0.1, 200000.0 ) glTranslatef(*self.distance) glRotatef(0,1,0,0) glRotatef(self.pitch,1,0,0) glRotatef(self.roll,0,1,0) glMatrixMode( GL_MODELVIEW ) glPushMatrix()
def handle_reshape(self, width, height): glLoadIdentity() aspect = height / width glViewport(0, 0, width, height) bw = self.width / 2 if self._is_perspective: gluPerspective(45.0, 1 / aspect, 0.1, 2000.0) else: glOrtho(-bw, bw, -bw * aspect, bw * aspect, -bw, bw)
def push(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluPerspective(self.fov, self.aspect, 0.1, 200000.0) glTranslatef(*self.distance) glRotatef(0, 1, 0, 0) glRotatef(self.pitch, 1, 0, 0) glRotatef(self.roll, 0, 1, 0) glMatrixMode(GL_MODELVIEW) glPushMatrix()
def setres((width, height)): """res = tuple sets the resolution and sets up the projection matrix""" if height==0: height=1 glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, width / height * 1.0, 1, 50) glMatrixMode(GL_MODELVIEW) glLoadIdentity()
def setupViewport(self, width, height): GL.glViewport(0, 0, width, height) # fixes aspect and size of viewport when viewport is resized GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() aspect = self.width / self.height gluPerspective(self.zoom, aspect, 0.1, 100.0) try: GL.glMatrixMode(GL.GL_MODELVIEW) except(Exception): print("zoomed in too much!!")
def reshape(width, height): if 0 in [width, height]: return h = float(height) / float(width); glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() #glFrustum(-1.0, 1.0, -h, h, 1.1, 100.0) gluPerspective(45.0, 1.0/h, 0.1, 100.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(0.0, 0.0, 0.0)
def init_view(self): """ initialize the projection matrix """ xSize, ySize = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) aspect_ratio = float(xSize) / float(ySize) # load the projection matrix. Always the same glMatrixMode(GL_PROJECTION) glLoadIdentity() glViewport(0, 0, xSize, ySize) gluPerspective(70, aspect_ratio, 0.1, 1000.0) glTranslated(0, 0, -15)
def resize(self, w, h): if h == 0: h = 1 glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w) / float(h), 0.1, 1000.0) #glEnable(GL_DEPTH_TEST) glMatrixMode(GL_MODELVIEW) glLoadIdentity() gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0) glEnable(GL_DEPTH_TEST)
def set_3d(self): """Set 3D render mode.""" glEnable(GL_DEPTH_TEST) glViewport(0, 0, self.width, self.height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(75.0, 1.0 * self.width / self.height, 0.001, 1000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity()
def resizeGL(self, width, height): """ [Reshape] Called upon window resizing: reinitialize the viewport """ self.width = width self.height = height glViewport(0, 0, self.width, self.height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(90, float(6*self.width)/float(6*self.height), 0.001*self.lenght, 6*self.lenght) glMatrixMode(GL_MODELVIEW)
def resize(self, width, height): if width < 400: glutReshapeWindow(400, height) if height < 300: glutReshapeWindow(width, 300) if height == 0: height = 1 glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(width)/float(height), 0.1, 10000.0) glMatrixMode(GL_MODELVIEW)
def set_projection(self, perspective_on): """ Toggle projection mode to orthogonal or perspective """ glMatrixMode(GL_PROJECTION) glLoadIdentity() if perspective_on: gluPerspective(90, float(6*self.width)/float(6*self.height), 0.001*self.lenght, 6*self.lenght) else: glOrtho(-1*self.width, 1*self.width, -1*self.height, 1*self.height, -1*self.lenght, 1*self.lenght) glMatrixMode(GL_MODELVIEW) self.updateGL()
def set_perspective(self, fovy): """ Set the perspective view """ # Calculate aspect aspect = self.width / self.height # Make changes to projection matrix glMatrixMode(GL_PROJECTION) glLoadIdentity() # Set the perspective accordingly gluPerspective(fovy, aspect, 0.1, 10.0) self.matrix = glGetFloatv(GL_PROJECTION_MATRIX)
def on_resize(self, width, height): """Prepare perspective for window size.""" print('on resize') if height == 0: height = 1 glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(75, 1.0 * width / height, 0.001, 1000.0)
def on_resize(self, width, height): # Override the default on_resize handler to create a 3D projection glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60., width / float(height), .1, 1000.) glMatrixMode(GL_MODELVIEW) self.rotspeed = 45 # degrees per second from ArcBall import ArcBallT self.arcball = ArcBallT(width, height) return pyglet.event.EVENT_HANDLED
def reshape(Width,Height): far=30.0 if (Width==Height): glViewport(0,0,Width,Height) elif (Width>Height): glViewport(0,0,Height,Height) else: glViewport(0,0,Width,Width) glMatrixMode(GL_PROJECTION) glLoadIdentity() #glFrustum(-10.0,10.0,-10.0,10.0,3.0,60.0) gluPerspective(80.0,1.0,1.0,80.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() gluLookAt(0.0,0.0,far, 0.0,0.0,0.0, 0.0,1.0,far)
def main(): pygame.init() pygame.display.set_mode((1024, 768), pygame.locals.OPENGL | pygame.locals.DOUBLEBUF) glEnable(GL_DEPTH_TEST) gluPerspective(60.0, 640.0 / 480.0, 0.5, 1000.0) glTranslate(0, -15, -60) objects = [] dynamicsWorld = DiscreteDynamicsWorld() objects.append(Ground()) objects.append(Ball(Vector3(1, 10, 0), (255, 0, 0))) objects.append(Ball(Vector3(0, 20, 1), (0, 255, 0))) objects.append(Ball(Vector3(0, 30, 1), (255, 255, 0))) objects.append(Ball(Vector3(0, 40, 1), (0, 255, 255, 0))) for o in objects: dynamicsWorld.addRigidBody(o.body) simulate(dynamicsWorld, objects)
def main(): pygame.init() pygame.display.set_mode( (1024, 768), pygame.locals.OPENGL | pygame.locals.DOUBLEBUF) glEnable(GL_DEPTH_TEST) gluPerspective(60.0, 640.0 / 480.0, 0.5, 1000.0) glTranslate(0, -15, -60) objects = [] dynamicsWorld = DiscreteDynamicsWorld() debug = DebugDraw() dynamicsWorld.setDebugDrawer(debug) b1 = Ball(Vector3(-30, 0, 0), (255, 0, 0)) b1.body.applyCentralImpulse(Vector3(30, 40, 0)) objects.append(b1) b2 = Ball(Vector3(+30, 0, 0), (0, 255, 0)) b2.body.applyCentralImpulse(Vector3(-30, 40, 0)) objects.append(b2) for o in objects: dynamicsWorld.addRigidBody(o.body) while True: step(dynamicsWorld) debug.reset() dynamicsWorld.debugDrawWorld() glBegin(GL_LINES) for line in debug.lines: glColor(*line[6:]) glVertex(*line[:3]) glVertex(*line[3:6]) if debug.contacts: print 'Contact!', debug.contacts glEnd() render(objects)
def initializeGL(self): # We call this right after our OpenGL window is created. glClearColor(1.0, 1.0, 1.0, 1.0) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) light_position = (0., 0., 1., 0.) white_light = (1., 1., 1., 0.501) d_light = (1., 1., 1., 0.01) spec = (1., 1., 1., 0.08) glLightfv(GL_LIGHT0, GL_POSITION, light_position) glLightfv(GL_LIGHT0, GL_AMBIENT, white_light) #glLightfv(GL_LIGHT0, GL_DIFFUSE, d_light) glLightfv(GL_LIGHT0, GL_SPECULAR, spec) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) #glBlendFunc(GL_SRC_ALPHA,GL_ONE) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) glEnable(GL_COLOR_MATERIAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(self.size().height())/ float(self.size().width()), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.rotation = [0.0, 0.0] self.mesh.prepDraw()
def display_screen(self): glDisable(GL_LIGHTING) glColor3f(1, 1, 1) # Projection glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective (self.fov,float(self.width)/float(self.height),self.clippingplanes[0],self.clippingplanes[1]) # Initialize ModelView matrix glMatrixMode(GL_MODELVIEW) glLoadIdentity() # View transformation mat = se3.homogeneous(self.camera.matrix()) cols = zip(*mat) pack = sum((list(c) for c in cols),[]) glMultMatrixf(pack) labels = dict([ (k, T[1]) for (k, T) in vantage_point_xforms.items() ]) for (k, v) in labels.items(): try: labels[k] = gluProject(*v) except: labels[k] = None glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0,self.width,self.height,0,-1,1); glMatrixMode(GL_MODELVIEW) glLoadIdentity() for (s, p) in labels.items(): if p: glRasterPos3f(p[0], self.height - p[1], p[2]) gldraw.glutBitmapString(GLUT_BITMAP_HELVETICA_12, s)
def main(): import sys from OpenGL.GLU import gluPerspective from pygame.constants import HWSURFACE, OPENGL, DOUBLEBUF, QUIT, MOUSEBUTTONDOWN, FULLSCREEN, MOUSEMOTION pygame.init() viewport = (800,600) hx = viewport[0]/2 hy = viewport[1]/2 srf = pygame.display.set_mode(viewport, HWSURFACE | OPENGL | DOUBLEBUF) glMatrixMode(GL_PROJECTION) glLoadIdentity() width, height = viewport gluPerspective(90.0, width/float(height), 1, 100.0) glMatrixMode(GL_MODELVIEW) glEnable(GL_COLOR_MATERIAL) glClearColor(0.0, 0.0, 0.0, 0.0) glEnable (GL_BLEND) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_TEXTURE_2D) glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ) glDisable(GL_DEPTH_TEST) clock=pygame.time.Clock() Sprite.init() plume=Plume() while 1: clock.tick() for e in pygame.event.get(): if e.type == QUIT: sys.exit() elif e.type == MOUSEBUTTONDOWN: if plume.is_off(): plume.on() elif plume.is_on(): plume.off() elif e.type == MOUSEMOTION: i, j = e.rel plume.throttle += (0.005*j) if 1.0 < plume.throttle: plume.throttle=1.0 elif plume.throttle < 0.33: plume.throttle=0.33 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslate(-0.0, 0.0, -5.0) plume.update(clock) plume.draw() pygame.display.flip()
def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) h = self.size().height() w = self.size().width() glEnable(GL_DEPTH_TEST) glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w)/float(h), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # Reset The View glEnable(MeshWidget.GL_MULTISAMPLE) glTranslatef(0,0.0,self.zoom) glRotate(self.rotation[0], 0.0, 1.0, 0.0) glRotate(self.rotation[1], 1.0, 0.0, 0.0) center = -self.mesh.bounding_box.center glTranslatef(center.x,center.y,center.z) if self.draw_mesh: if self.enable_restrict: for i in self.restricted: glBegin(GL_TRIANGLES) self.mesh.drawFaceIdx(i) glEnd() else: self.mesh.draw(1.0) if self.draw_bounding_box: self.mesh.bounding_box.draw() if self.draw_octree: self.mesh.quad.draw() #single vertex marker #glPushMatrix( ) #s = self.mesh.vertices.verts[self.point_draw] #glTranslatef(s.x,s.y,s.z) #q = gluNewQuadric() #gluSphere( q, GLdouble(0.65), GLint(10), GLint(10) ) #glPopMatrix( ) #self.mesh.drawAdjacentFaces( self.count ) #self.count += 1 #if self.count == len(self.mesh.faces): #self.count = 0 #time.sleep(0.3) #self.mesh.smooth(0.45) w /= 5 h /= 5 glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w)/float(h), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glDisable(GL_DEPTH_TEST) glLoadIdentity() # Reset The View glTranslatef(0,0.0,-self.mesh.bounding_box.minViewDistance()) glRotate(self.rotation[0], 0.0, 1.0, 0.0) glRotate(self.rotation[1], 1.0, 0.0, 0.0) center = -self.mesh.bounding_box.center glTranslatef(center.x,center.y,center.z) if self.draw_mesh: self.mesh.draw(0.5)