def on_draw(self): gl.glClearColor(0, 0.0, 0.0, 1.) self.clear() width, height = self.get_size() gl.glViewport(0, 0, width, height) K_gl = get_projector_gl_intrinsics() TF = get_extrinsics() R = np.array([[-1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., -1., 0.], [0., 0., 0., 1.]]) full_mat = np.ascontiguousarray((K_gl.dot(TF.dot(R))).astype('f4')) with self.prog.using(): self.prog.uniforms.Mvp = full_mat.tolist() gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glPointSize(25.) distance = (0, 0, 1) gl.glPointParameterfv(gl.GL_POINT_DISTANCE_ATTENUATION, (gl.GLfloat * 3)(*distance)) gl.glEnable(gl.GL_POINT_SPRITE) self.vertex_info.draw(gl.GL_POINTS) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glMatrixMode(gl.GL_TEXTURE) gl.glLoadIdentity() gl.glDisable(gl.GL_DEPTH_TEST) gl.glDisable(gl.GL_BLEND) self.fps_display.draw()
def on_resize(self, width, height): glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, width, 0, height, -1000, 1000) glMatrixMode(GL_MODELVIEW) return pyglet.event.EVENT_HANDLED
def _reset_projection(self): if self.fullcanvas: if self._pygimage is None: return width, height = self._pygimage.width, self._pygimage.height else: size = self.GetClientSize() width, height = size.width, size.height b = 0 t = height if self.flip_lr: l = width r = 0 else: l = 0 r = width if self.rotate_180: l,r=r,l b,t=t,b if width==0 or height==0: # prevent OpenGL error return self.wxcontext.SetCurrent() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(l,r,b,t, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW)
def on_resize(self, width, height): """Calculate the new viewport preserving aspect ratio""" aspect = float(WIDTH)/HEIGHT self.viewport_width = int(min(width, height*aspect)) self.viewport_height = int(min(height, width/aspect)) self.viewport_x_offs = (width-self.viewport_width) // 2 self.viewport_y_offs = (height-self.viewport_height) // 2 x = (width-WIDTH) / 2 gl.glViewport(self.viewport_x_offs, self.viewport_y_offs, self.viewport_width, self.viewport_height, ) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, self.viewport_width, 0, self.viewport_height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() logging.debug("Viewport: %s, %s, %s, %s" % (self.viewport_x_offs, self.viewport_y_offs, self.viewport_width, self.viewport_height, )) # adjust elements depending on the new viewport self.label.x = self.viewport_width // 2 self.label.y = self.viewport_height // 2
def on_draw(): gl.glClearColor(1.0,1.0,1.0,1.0) window.clear() # Compute gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, 1, 0, 1, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glActiveTexture( gl.GL_TEXTURE1 ) gl.glBindTexture(texture_s.target, texture_s.id) gl.glActiveTexture( gl.GL_TEXTURE0 ) gl.glBindTexture(texture_uv.target, texture_uv.id) gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, framebuffer) reaction_shader.bind() texture_uv.blit(x=0.0, y=0.0, width=1.0, height=1.0) reaction_shader.unbind() gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0) # Render gl.glViewport(0, 0, window.width, window.height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, 1, 0, 1, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) color_shader.bind() texture_uv.blit(x=0.0, y=0.0, width=1.0, height=1.0) color_shader.bind()
def on_resize(width, height): gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(-width/2, width/2, -height/2, height/2, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) return EVENT_HANDLED
def camera(self): o = self.center() a1 = o[0] - 1. / self.magnify a2 = o[0] + 1. / self.magnify a3 = o[1] - 1. / self.magnify a4 = o[1] + 1. / self.magnify gl.glOrtho(a1, a2, a3, a4, -1., 1.)
def handle_resize(w, h): gl.glViewport(0, 0, w, h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, w, h, 0, 0, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity()
def draw(self): # set up projection gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glViewport(self.x, self.y, self.width, self.height) gl.glOrtho(0, self.width, 0, self.height, self.near, self.far) gl.glMatrixMode(gl.GL_MODELVIEW) fx, fy = self._determine_focus() w2 = self.width / 2 h2 = self.height / 2 x1, y1 = fx - w2, fy - h2 x2, y2 = fx + w2, fy + h2 gl.glPushMatrix() gl.glTranslatef(self.width / 2 - fx, self.height / 2 - fy, 0) for layer in self.layers: if hasattr(layer, 'x'): translate = layer.x or layer.y else: translate = False if translate: gl.glPushMatrix() gl.glTranslatef(layer.x, layer.y, 0) layer.draw() if translate: gl.glPopMatrix() gl.glPopMatrix()
def draw(self): gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, self.width, 0, self.height, 1, -1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() self.batch.draw()
def _drawLUTtoScreen(self): """(private) Used to set the LUT in 'bits++' mode. Should not be needed by user if attached to a ``psychopy.visual.Window()`` since this will automatically draw the LUT as part of the screen refresh. """ # push the projection matrix and set to orthorgaphic GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() # this also sets the 0,0 to be top-left GL.glOrtho(0, self.win.size[0], self.win.size[1], 0, 0, 1) # but return to modelview for rendering GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() # draw the pixels GL.glActiveTextureARB(GL.GL_TEXTURE0_ARB) GL.glEnable(GL.GL_TEXTURE_2D) GL.glBindTexture(GL.GL_TEXTURE_2D, 0) GL.glActiveTextureARB(GL.GL_TEXTURE1_ARB) GL.glEnable(GL.GL_TEXTURE_2D) GL.glBindTexture(GL.GL_TEXTURE_2D, 0) GL.glRasterPos2i(0, 1) GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) GL.glDrawPixels(len(self._HEADandLUT), 1, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, self._HEADandLUTstr) # GL.glDrawPixels(524,1, GL.GL_RGB,GL.GL_UNSIGNED_BYTE, # self._HEADandLUTstr) # return to 3D mode (go and pop the projection matrix) GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW)
def _resize(self, width, height): aspect = float(self._width)/self._height self._viewport_width = int(min(width, height*aspect)) self._viewport_height = int(min(height, width/aspect)) self._viewport_x_offs = (width-self._viewport_width) // 2 self._viewport_y_offs = (height-self._viewport_height) // 2 x = (width-self._width) / 2 gl.glViewport(self._viewport_x_offs, self._viewport_y_offs, self._viewport_width, self._viewport_height, ) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, self._viewport_width, 0, self._viewport_height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() logging.debug("Viewport: %s, %s, %s, %s" % (self._viewport_x_offs, self._viewport_y_offs, self._viewport_width, self._viewport_height, ))
def set_viewport(left, right, bottom, top): """ This sets what coordinates appear on the window. Note: It is recommended to only set the viewport to integer values that line up with the pixels on the screen. Otherwise if making a tiled game the blocks may not line up well, creating rectangle artifacts. >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> set_viewport(-1, 1, -1, 1) >>> arcade.quick_run(0.25) """ global _left global _right global _bottom global _top _left = left _right = right _bottom = bottom _top = top # GL.glViewport(0, 0, _window.height, _window.height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glOrtho(_left, _right, _bottom, _top, -1, 1) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity()
def display(self, width, height): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.gluPerspective(60., width / float(height), .1, 1000.) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glTranslatef(self.trans[0], self.trans[1], self.trans[2]) gl.glRotatef(self.rot[0], 1.0, 0.0, 0.0) gl.glRotatef(self.rot[1], 0.0, 1.0, 0.0) gl.glRotatef(self.rz, 0, 0, 1) gl.glRotatef(self.ry, 0, 1, 0) gl.glRotatef(self.rx, 1, 0, 0) gl.glEnable(gl.GL_LIGHTING) gl.glColor3f(1, 0, 0) self.torus.draw() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glDisable(gl.GL_LIGHTING) gl.glColor3f(0, 1, 0) self.lowerlabel.text = 'Rx %.2f Ry %.2f Rz %.2f' % (self.rx, self.ry, self.rz) self.lowerlabel.draw() self.upperlabel.text = time.strftime('Now is %H:%M:%S') self.upperlabel.x = width - self.upperlabel.content_width - 5 self.upperlabel.y = height - self.upperlabel.content_height self.upperlabel.draw()
def _drawLUTtoScreen(self): """(private) Used to set the LUT in Bits++ mode. Should not be needed by user if attached to a ``psychopy.visual.Window()`` since this will automatically draw the LUT as part of the screen refresh. """ #push the projection matrix and set to orthorgaphic GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() GL.glOrtho( 0, self.win.size[0],self.win.size[1], 0, 0, 1 ) #this also sets the 0,0 to be top-left #but return to modelview for rendering GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() #draw the pixels GL.glActiveTextureARB(GL.GL_TEXTURE0_ARB) GL.glEnable(GL.GL_TEXTURE_2D) GL.glBindTexture(GL.GL_TEXTURE_2D, 0) GL.glActiveTextureARB(GL.GL_TEXTURE1_ARB) GL.glEnable(GL.GL_TEXTURE_2D) GL.glBindTexture(GL.GL_TEXTURE_2D, 0) GL.glRasterPos2i(0,1) GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) GL.glDrawPixels(len(self._HEADandLUT),1, GL.GL_RGB,GL.GL_UNSIGNED_BYTE, self._HEADandLUTstr) #GL.glDrawPixels(524,1, GL.GL_RGB,GL.GL_UNSIGNED_BYTE, self._HEADandLUTstr) #return to 3D mode (go and pop the projection matrix) GL.glMatrixMode( GL.GL_PROJECTION ) GL.glPopMatrix() GL.glMatrixMode( GL.GL_MODELVIEW )
def on_draw(): # Draw the apriltag image on a quad with vert edges # from the vert buffer. gl.glClearColor(1.0, 0.0, 1.0, 1.0) window.clear() width, height = window.get_size() print("On draw %dx%d" % (width, height)) gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() texture = base_tag.get_texture() gl.glTexParameteri(texture.target, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST) gl.glTexParameteri(texture.target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) base_tag.blit(apriltag_x, apriltag_y, width=apriltag_size, height=apriltag_size) print("Done with draw")
def own_render(environment, img): if environment.window is None: config = gl.Config(double_buffer=False) environment.window = window.Window(width=WINDOW_WIDTH, height=WINDOW_HEIGHT, resizable=False, config=config) environment.window.clear() environment.window.switch_to() environment.window.dispatch_events() gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, 0, 10) width = img.shape[1] height = img.shape[0] img = np.ascontiguousarray(np.flip(img, axis=0)) img_data = image.ImageData( width, height, 'RGB', img.ctypes.data_as(POINTER(gl.GLubyte)), pitch=width * 3, ) img_data.blit(0, 0, 0, width=WINDOW_WIDTH, height=WINDOW_HEIGHT) x, y, z = environment.cur_pos environment.text_label.text = "pos: (%.2f, %.2f, %.2f), angle: %d, steps: %d, speed: %.2f m/s" % ( x, y, z, int(environment.cur_angle * 180 / math.pi), environment.step_count, environment.speed) environment.text_label.draw() gl.glFlush()
def SetOrigin(self): size = self.GetVirtualSize() self.SetScrollbar(wx.HORIZONTAL, self.GetScrollPos(wx.HORIZONTAL), size[0], self.map.width * 32 * self.zoom, refresh=True) self.SetScrollbar(wx.VERTICAL, self.GetScrollPos(wx.VERTICAL), size[1], self.map.height * 32 * self.zoom, refresh=True) size = self.GetGLExtents() if size.width <= 0: size.width = 1 if size.height <= 0: size.height = 1 self.tilemap.updateDimmingSprite( int(size.width) + 2, int(size.height) + 2, 1 / self.zoom) gl.glViewport(0, 0, size.width, size.height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho( 0, size.width / self.zoom, 0, size.height / self.zoom, -1, 1) x = (-self.GetScrollPos(wx.HORIZONTAL)) / self.zoom y = ((-(self.map.height * 32) + size.height / self.zoom) + self.GetScrollPos(wx.VERTICAL) / self.zoom) gl.glTranslatef(x, y, 0) self.translateX = -x + size.width / 2 / self.zoom self.translateY = -y + size.height / 2 / self.zoom self.onscreenwidth = int(size.width / self.zoom) self.onscreenheight = int(size.height / self.zoom) self.tilemap.setDimXY(self.translateX - 1, self.translateY + 1) gl.glMatrixMode(gl.GL_MODELVIEW)
def set_viewport(width, height): gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW)
def on_draw(): update_grid() window.clear() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, 200, 200, 0, 0, 1) grid.draw()
def on_draw(self): """Draw window.""" self.clear() viewport = self.get_viewport_size() gl.glViewport(0, 0, max(1, viewport[0]), max(1, viewport[1])) # set projection for billiard table gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho( self.center[0] - self.extent / 2, self.center[0] + self.extent / 2, self.center[1] - self.extent / (2 * self.aspect_ratio), self.center[1] + self.extent / (2 * self.aspect_ratio), -1, 1, ) # draw balls and obstacles gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() self.obs_batch.draw() self.ball_batch.draw() # set projection for GUI gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, max(1, self.width), 0, max(1, self.height), -1, 1) # draw GUI gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() self.gui_batch.draw()
def on_draw(self, dt): self.window.clear() # This is where the code to auto-resize the window begins. # Set it up to draw to the whole space of the window. glViewport(0, 0, self.window.width, self.window.height) # Switch to projection matrix. glMatrixMode(gl.GL_PROJECTION) glLoadIdentity() # Calculate the size of our display. base_size = 240.0 size_x = 0.0 size_y = 0.0 if (self.window.width >= self.window.height): size_x = base_size * (self.window.width / float(self.window.height)) size_y = base_size else: size_x = base_size size_y = base_size * (self.window.height / float(self.window.width)) # Set the orthogonal projection. glOrtho(-size_x / 2.0, size_x / 2.0, -size_y / 2.0, size_y / 2.0, -100, 100) # Switch back to model view so we can do the rest of our drawing. glMatrixMode(gl.GL_MODELVIEW) glLoadIdentity() # Draw stuff in the level. glPushMatrix() glTranslatef(int(-self.player1.x), int(-self.player1.y), 0.0) self.bg.draw() for platform in self.platforms: platform.render() self.player1.draw() if const.DRAW_SENSORS: for sensor in self.player1.sensors: sensor.render() glPopMatrix() # Draw HUD. self.fps_display.text = 'FPS: %d' % (1 / dt) self.fps_display.draw() self.debug_text[0].text = str(int(self.player1.hlock)) self.debug_text[1].text = str(self.player1.state) self.debug_text[2].text = str(self.player1.rangle) self.debug_text[0].draw() self.debug_text[1].draw() self.debug_text[2].draw()
def __enter__(self): width, height = self.window.get_size() gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity()
def _update(self): # glViewport(0, 0, self.width, self.height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() scaled_left, scaled_right, scaled_bottom, scaled_top = self.scaled_bounds( ) gl.glOrtho(scaled_left, scaled_right, scaled_bottom, scaled_top, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW)
def on_resize(self, width, height): glViewport(0, 0, width, height) glMatrixMode(gl.GL_PROJECTION) glLoadIdentity() width = self.vwidth if self.vwidth is not None else width height = self.vheight if self.vheight is not None else height glOrtho(0, width, 0, height, -1, 1) glMatrixMode(gl.GL_MODELVIEW)
def before_render(self, texture): self.pbuf.switch_to() gl.glViewport(0, 0, self.pbuf.width, self.pbuf.height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, self.pbuf.width, 0, self.pbuf.height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glEnable(gl.GL_TEXTURE_2D)
def draw_camera(): gl.glViewport(0, 0, w, h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, w, 0, h, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glLoadIdentity()
def set_viewport(left, right, bottom, top): # gl.glViewport(0, 0, _window.height, _window.height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(left, right, bottom, top, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity()
def on_resize(self, width, height, x=0, y=0): gl.glViewport(x, y, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() h = height or 1 w = width / float(h) gl.glOrtho(-w, w, -1, 1, -1, 1000.) gl.glMatrixMode(gl.GL_MODELVIEW) self._setLightsAndEffects()
def _set_2d(self, near, far): w = self.context.window gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() gl.glOrtho(0, w.width, 0, w.height, near, far) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glLoadIdentity()
def on_resize(self, width, height): from options import options z = options.zoom glViewport(0, 0, int(width * z), int(height * z)) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, width, 0, height, -1000, 1000) glMatrixMode(GL_MODELVIEW) return pyglet.event.EVENT_HANDLED
def drawGUI(self): gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, self.w, 0, self.h, -1, 1) for label in self.helpLabels: label.draw() for label in self.statusLabels: label.draw()
def set_2d(self): width, height = self.get_size() glDisable(GL_DEPTH_TEST) glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, width, 0, height, -1, 1) glMatrixMode(GL_MODELVIEW) glLoadIdentity()
def on_draw(self, dt): self.window.clear() # This is where the code to auto-resize the window begins. # Set it up to draw to the whole space of the window. glViewport(0, 0, self.window.width, self.window.height) # Switch to projection matrix. glMatrixMode(gl.GL_PROJECTION) glLoadIdentity() # Calculate the size of our display. base_size = 240.0 size_x = 0.0 size_y = 0.0 if (self.window.width >= self.window.height): size_x = base_size * (self.window.width/float(self.window.height)) size_y = base_size else: size_x = base_size size_y = base_size * (self.window.height/float(self.window.width)) # Set the orthogonal projection. glOrtho(-size_x/2.0, size_x/2.0, -size_y/2.0, size_y/2.0, -100, 100) # Switch back to model view so we can do the rest of our drawing. glMatrixMode(gl.GL_MODELVIEW) glLoadIdentity() # Draw stuff in the level. glPushMatrix() glTranslatef(int(-self.player1.x), int(-self.player1.y), 0.0) self.bg.draw() for platform in self.platforms: platform.render() self.player1.draw() if const.DRAW_SENSORS: for sensor in self.player1.sensors: sensor.render() glPopMatrix() # Draw HUD. self.fps_display.text = 'FPS: %d' % (1 / dt) self.fps_display.draw() self.debug_text[0].text = str(int(self.player1.hlock)) self.debug_text[1].text = str(self.player1.state) self.debug_text[2].text = str(self.player1.rangle) self.debug_text[0].draw() self.debug_text[1].draw() self.debug_text[2].draw()
def on_draw(self): self.window.clear() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glPushMatrix() gl.glScalef(1.5, -1.5, 0) gl.glOrtho(-300, 724, 650, -150, -1, 1) self.level_batch.draw() self.game_objects_batch.draw() gl.glPopMatrix()
def on_resize(self, w, h): """ Lets the user handle the widget resize event. By default, this method resizes the view to the widget size. """ gl.glViewport(0, 0, w, h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, w, 0, h, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW)
def _center_camera(self): """Sets the camera coordinates.""" if self.main_car is not None and self.follow_main_car: x = self.main_car.state[0] y = self.main_car.state[1] else: x, y = 0.0, 0.0 z = 0.0 # set the camera to be +1/-1 from the center coordinates gl.glOrtho(x - 1.0, x + 1.0, y - 1.0, y + 1.0, z - 1.0, z + 1.0)
def set_2d(self, size): """Configure OpenGL to draw in 2d.""" width, height = size GL.glDisable(GL.GL_DEPTH_TEST) GL.glViewport(0, 0, width, height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glOrtho(0, width, 0, height, -1, 1) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity()
def _set_2d_projection(cls): # director.set_2d_projection() width, height = director.get_window_size() gl.glLoadIdentity() gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -100, 100) gl.glMatrixMode(gl.GL_MODELVIEW)
def on_resize(self, width, height): """Override default implementation to support retina displays.""" view = self.context._nscontext.view() bounds = view.convertRectToBacking_(view.bounds()).size back_width, back_height = (int(bounds.width), int(bounds.height)) gl.glViewport(0, 0, back_width, back_height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW)
def set_viewport(self): # Set viewport gl.glViewport(self.x0, self.y0, self.width, self.height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() # Set projection gl.glOrtho(-self.width / (2), self.width / (2), -self.height / (2), self.height / (2), -1000, 1000) gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, lightfv(1.0, 1., 1.0, 0.0)) return None
def set_minimap_projection(): # third of window height, bottom-right corner y = 3 * client.world.size.y x = y / win_size.y * win_size.x top_left = client.world.top_left gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, x, -y, 0, -1, 1) gl.glTranslatef(-top_left.x, top_left.y, 0) gl.glMatrixMode(gl.GL_MODELVIEW)
def resize(self, width, height): self.width = width self.height = height self.screenRect.max.x = width self.screenRect.max.y = height gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1.0, 1.0) gl.glMatrixMode(gl.GL_MODELVIEW)
def display(self, width, height): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glTranslatef(self.trans[0], self.trans[1], 0) gl.glScalef(self.trans[2], self.trans[2], self.trans[2]) # FIXME draw only visible part? self.renderer.render()
def on_draw(): GL.glPushMatrix() GL.glViewport(0, 0, window.width, window.height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glOrtho(0, 600, 0, 400, -1, 1) GL.glMatrixMode(GL.GL_MODELVIEW) window.clear() for label in labels: label.draw() GL.glPopMatrix()
def set_world_projection(): center = client.player.center horz_vp = min(foo_size.x, foo_size.y * win_size.x / win_size.y) vert_vp = min(foo_size.y, foo_size.x * win_size.y / win_size.x) s = client.player.scale * 2.0 # window border is /2 from center gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(-horz_vp / s, horz_vp / s, -vert_vp / s, vert_vp / s, -1, 1) gl.glTranslatef(-center.x, center.y, 0) gl.glMatrixMode(gl.GL_MODELVIEW)
def set_2d(self): """ Configure OpenGL to draw in 2d. """ width, height = self.get_size() gl.glDisable(gl.GL_DEPTH_TEST) gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -200, 200) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity()
def on_mouse_drag(x, y, dx, dy, button, modifiers): sprite.x = int((x/float(window.width)) * width)-sprite.width//2 sprite.y = int((y/float(window.height)) * height)-sprite.height//2 # Compute gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, framebuffer) sprite.draw() gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0)
def drawPixels(intensities): #create row of rgb vals from intensities pixels = numpy.ones([len(intensities),1,3]).astype(numpy.ubyte) pixels[:,0,0] = intensities pixels[:,0,1] = intensities pixels[:,0,2] = intensities #scale window gl.glOrtho( 0, win.size[0], 0, win.size[1], 0, 1 ) #move to top left gl.glRasterPos2f(0, win.size[1]-1 ) gl.glDrawPixels(pixels.shape[0], pixels.shape[1], gl.GL_RGB, gl.GL_UNSIGNED_BYTE, pixels.tostring())