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 draw(self, x, y, z=0, angle=0, scale=1): """Draws the SVG to screen. :Parameters `x` : float The x-coordinate at which to draw. `y` : float The y-coordinate at which to draw. `z` : float The z-coordinate at which to draw. Defaults to 0. Note that z-ordering may not give expected results when transparency is used. `angle` : float The angle by which the image should be rotated (in degrees). Defaults to 0. `scale` : float The amount by which the image should be scaled, either as a float, or a tuple of two floats (xscale, yscale). """ glPushMatrix() glTranslatef(x, y, z) if angle: glRotatef(angle, 0, 0, 1) if scale != 1: try: glScalef(scale[0], scale[1], 1) except TypeError: glScalef(scale, scale, 1) if self._a_x or self._a_y: glTranslatef(-self._a_x, -self._a_y, 0) glCallList(self.disp_list) glPopMatrix()
def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(0., 0., -4. / min(self.aspect, 0.7)) glRotatef(self.yRotDeg, 0., 1., 0.) glRotatef(self.xRotDeg, 1., 0., 0.) if self.shape == 'cuboid': self.paintCuboid(self.sample_width, self.sample_thickness, self.sample_height, rotate=45.) elif self.shape == 'cylinder': self.paintCylinder(self.sample_diameter, self.sample_height) elif self.shape == 'sphere': self.paintSphere(self.sample_diameter) else: self.sample_width = self.sample_thickness = 70 self.sample_height = 100 self.paintCuboid(self.sample_width, self.sample_thickness, self.sample_height) self.paintArrow('x', [0, 0, 1]) self.paintArrow('y', [1, 0, 0]) self.paintArrow('z', [0, 1, 0]) self.paintArrow('n', [0, 0, 0]) self.paintArrow('gamma', [1, 0, 1]) self.paintCells()
def drawGrid(self): grids_per_screen = 10 eye_dist = self.camera_xyz[2] meters_per_grid = round_to_125(eye_dist / grids_per_screen) num_lines = 300 glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_LINE_BIT) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_DEPTH_TEST) glPushMatrix() glTranslatef(0, 0, 0) glColor3f(0.2, 0.2, 0.2) glBegin(GL_LINES) for i in range(num_lines): glVertex2f((-num_lines / 2 + i) * meters_per_grid, -num_lines / 2 * meters_per_grid) glVertex2f((-num_lines / 2 + i) * meters_per_grid, num_lines / 2 * meters_per_grid) glVertex2f(-num_lines / 2 * meters_per_grid, (-num_lines / 2 + i) * meters_per_grid) glVertex2f(num_lines / 2 * meters_per_grid, (-num_lines / 2 + i) * meters_per_grid) glEnd() glPopMatrix() glPopAttrib()
def on_draw(self): """Redraw window.""" self.set_3d() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # rotate camera glRotatef(self.camera.v_angle_deg(), 1.0, 0, 0) glRotatef(self.camera.h_angle_deg(), 0.0, 1.0, 0) glTranslatef( -self.camera.x_pos, -self.camera.y_pos, self.camera.z_pos) if self.rendering_type == "fill": self.use_shader("test") elif self.rendering_type == "lines": self.use_shader("lines") self.renderer.render() # draw HUD self.set_2d() self.draw_hud()
def drawbrick(color, center, axis, l, h, w, opacity = 1.0): if len(color) == 3: color = (color[0], color[1], color[2], opacity) if opacity != 1.0: glDepthMask(GL_FALSE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) apply_material(color) glPushMatrix() glTranslatef(center[0], center[1], center[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2])*180.0/pi if (axis[2]*axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glScale(h, w, l) #bruce 060302 revised the contents of solidCubeList while fixing bug 1595 glCallList(drawing_globals.solidCubeList) if opacity != 1.0: glDisable(GL_BLEND) glDepthMask(GL_TRUE) glPopMatrix() return
def render(self): ''' ''' super(Shaft, self).render() glPushAttrib(GL_CURRENT_BIT) n = int(self.length) lim = n - 1 if self.orientation in ['down', 'forward', 'backward']: lim = 0 self._set_material() # print lim for i in range(n): glPushMatrix() glTranslatef(0, i / 2.0, 0) if i == lim: self._can_(0.66, 0.5) self._cylinder_(0.5, 0.5) glPopMatrix() # if self.state and animate: # if ac % 20 == 0 and self.prev_ac != ac: # if self.orientation == 'left' or self.orientation == 'up': # self.colorlist = shift(self.colorlist) # else: # self.colorlist = deshift(self.colorlist) # self.prev_ac = ac glPopAttrib()
def drawbrick(color, center, axis, l, h, w, opacity=1.0): if len(color) == 3: color = (color[0], color[1], color[2], opacity) if opacity != 1.0: glDepthMask(GL_FALSE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) apply_material(color) glPushMatrix() glTranslatef(center[0], center[1], center[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2]) * 180.0 / pi if (axis[2] * axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glScale(h, w, l) #bruce 060302 revised the contents of solidCubeList while fixing bug 1595 glCallList(drawing_globals.solidCubeList) if opacity != 1.0: glDisable(GL_BLEND) glDepthMask(GL_TRUE) glPopMatrix() return
def drawFilledCircle(color, center, radius, normal): """ Scale, rotate/translate the unit circle properly. Added a filled circle variant, piotr 080405 """ glMatrixMode(GL_MODELVIEW) glPushMatrix() glColor3fv(color) glDisable(GL_LIGHTING) glTranslatef(center[0], center[1], center[2]) rQ = Q(V(0, 0, 1), normal) rotAngle = rQ.angle * 180.0 / pi #This may cause problems as proved before in Linear motor display. #rotation around (0, 0, 0) #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005: # rQ.x = 1.0 glRotatef(rotAngle, rQ.x, rQ.y, rQ.z) glScalef(radius, radius, 1.0) glCallList(drawing_globals.filledCircleList) glEnable(GL_LIGHTING) glPopMatrix() return
def drawRotateSign(color, pos1, pos2, radius, rotation=0.0): """Rotate sign on top of the caps of the cylinder """ glPushMatrix() glColor3fv(color) vec = pos2 - pos1 axis = norm(vec) glTranslatef(pos1[0], pos1[1], pos1[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2]) * 180.0 / pi if (axis[2] * axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glRotate(rotation, 0.0, 0.0, 1.0) #bruce 050518 glScale(radius, radius, Numeric.dot(vec, vec)**.5) glLineWidth(2.0) glDisable(GL_LIGHTING) glCallList(drawing_globals.rotSignList) glEnable(GL_LIGHTING) glLineWidth(1.0) glPopMatrix() return
def draw(self): # background set_color(*self.style['bg-color']) drawCSSRectangle(size=self.size, style=self.style) # content dynamic update with gx_matrix: glTranslatef(self.style['margin'][3], self.style['margin'][2], 0) # draw precalculated background self._current_cache['background'].draw() # draw active keys layer # +2 and -4 result of hard margin coded in _do_update (m = 3 * s) # we substract 1 cause of border (draw-border is activated.) set_color(*self.style['color-down']) for key, size in self._active_keys: x, y, w, h = size drawCSSRectangle(pos=(x+2, y+2), size=(w-4, h-4), style=self.style, prefix='key', state='down') # search the good scale for current precalculated keys layer if self._last_update_scale == self.scale: s = 1. / self.scale# / self._last_update_scale glScalef(s, s, s) else: s = 1. / self._last_update_scale glScalef(s, s, s) self._current_cache['keys'].draw()
def draw_in_abs_coords(self, glpane, color): """ Draw the handle as a highlighted object. @param glpane: The 3D Graphics area. @type gplane: L{GLPane} @param color: Unused. @type color: @attention: I{color} is not used. """ q = self.parent.quat glPushMatrix() if self.parent.center: glTranslatef( self.parent.center[0], self.parent.center[1], self.parent.center[2]) if q: glRotatef( q.angle * ONE_RADIAN, q.x, q.y, q.z) self._draw(highlighted = True) glPopMatrix()
def render(self, visibility, topMost): v = 1.0 - ((1 - visibility) ** 2) # render the background w, h = self.engine.view.geometry[2:4] with self.engine.view.orthogonalProjection(normalize = True): if self.background: drawImage(self.background, scale = (1.0,-1.0), coord = (w/2,h/2), stretched = FULL_SCREEN) else: self.engine.fadeScreen(.4) self.doneList = [] # render the scroller elements y = self.offset glTranslatef(-(1 - v), 0, 0) for element in self.credits: hE = element.getHeight() if y + hE > 0.0 and y < 1.0: element.render(y) if y + hE < 0.0: self.doneList.append(element) y += hE if y > 1.0: break if self.topLayer: wFactor = 640.000/self.topLayer.width1() hPos = h - ((self.topLayer.height1() * wFactor)*.75) if hPos < h * .6: hPos = h * .6 drawImage(self.topLayer, scale = (wFactor,-wFactor), coord = (w/2,hPos))
def draw_arrow(self, color): # Set material glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color) #glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color) #glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 0.0]) #glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20) # Draw cylinder quad = gluNewQuadric() gluQuadricDrawStyle(quad, GLU_FILL) gluQuadricTexture(quad, True) gluQuadricNormals(quad, GLU_SMOOTH) gluCylinder(quad, self.size / 30, self.size / 30, self.size * 0.8, 20, 20) # Move to the arrowhead position glTranslatef(0, 0, self.size * 0.8) # Draw arrowhead gluQuadricDrawStyle(quad, GLU_FILL) gluQuadricTexture(quad, True) gluQuadricNormals(quad, GLU_SMOOTH) gluCylinder(quad, self.size / 15, 0, self.size * 0.2, 20, 20) # Revert to the original position glTranslatef(0, 0, -self.size * 0.8)
def _draw_jig(self, glpane, color, highlighted = False): """ Draw a Grid Plane jig as a set of grid lines. """ glPushMatrix() glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/math.pi, q.x, q.y, q.z) hw = self.width/2.0; hh = self.height/2.0 corners_pos = [V(-hw, hh, 0.0), V(-hw, -hh, 0.0), V(hw, -hh, 0.0), V(hw, hh, 0.0)] if highlighted: grid_color = color else: grid_color = self.grid_color if self.picked: drawLineLoop(self.color, corners_pos) else: drawLineLoop(color, corners_pos) if self.grid_type == SQUARE_GRID: drawGPGrid(glpane, grid_color, self.line_type, self.width, self.height, self.x_spacing, self.y_spacing, q.unrot(self.assy.o.up), q.unrot(self.assy.o.right)) else: drawSiCGrid(grid_color, self.line_type, self.width, self.height, q.unrot(self.assy.o.up), q.unrot(self.assy.o.right)) glPopMatrix()
def ApplyModelview(self): """ モデルビュー行列のOpenGL適用 以下の変換を行う行列を生成し、モデルビュー行列とする - ステレオ表示の場合、視点位置をオフセットする - 視線方向の回転 - 視点位置への平行移動 """ try: from OpenGL.GL import glTranslatef, glRotatef except: return False eoff = Vec3(self._eyeOff) if self._eyeType == LEFT_EYE: eoff.m_v[0] -= Frustum.__strOff elif self._eyeType == RIGHT_EYE: eoff.m_v[0] += Frustum.__strOff try: glTranslatef(-eoff.m_v[0], -eoff.m_v[1], -eoff.m_v[2]) glRotatef(-self._hpr.m_v[2], 0.0, 0.0, 1.0) glRotatef(-self._hpr.m_v[1], 1.0, 0.0, 0.0) glRotatef(-self._hpr.m_v[0], 0.0, 1.0, 0.0) glTranslatef(-self._eye.m_v[0],-self._eye.m_v[1],-self._eye.m_v[2]) except: return False # no valid OpenGL context return True
def drawTexture(self, texture, dx, dy, dw, dh, x, y, w, h, r): ''' texture is an int textureRect is a list of size 4, determines which square to take from the texture drawRect is a list of size 4, is used to determine the drawing size ''' glBindTexture(self.texext, texture) glPushMatrix() glTranslatef(dx + dw / 2, dy + dh / 2, 0) glRotatef(r, 0, 0, 1.0) glTranslatef(-1 * (dx + dw / 2), -1 * (dy + dh / 2), 0) glBegin(GL_QUADS) #Top-left vertex (corner) glTexCoord2f(x, y + h) #image/texture glVertex3f(dx, dy, 0) #screen coordinates #Bottom-left vertex (corner) glTexCoord2f(x + w, y + h) glVertex3f((dx + dw), dy, 0) #Bottom-right vertex (corner) glTexCoord2f(x + w, y) glVertex3f((dx + dw), (dy + dh), 0) #Top-right vertex (corner) glTexCoord2f(x, y) glVertex3f(dx, (dy + dh), 0) glEnd() glPopMatrix()
def Draw(self): """draw a curve of all previous data, up to a certain point (self.resolution)""" self.vbo.bind() self.vbo.copy_data() glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, 0, self.vbo) if self.buffer_full: if self.previous_index != self.size - 1: glPushMatrix() glTranslatef(-1 * (self.previous_index + 1), 0.0, 0.0) glDrawArrays(GL_LINE_STRIP, (self.previous_index + 1), (self.size - self.previous_index - 1)) glPopMatrix() glPushMatrix() glTranslatef(self.size - self.previous_index - 1, 0.0, 0.0) glDrawArrays(GL_LINE_STRIP, 0, (self.previous_index + 1)) glPopMatrix() else: glDrawArrays(GL_LINE_STRIP, 0, (self.previous_index + 1)) glDisableClientState(GL_VERTEX_ARRAY) self.vbo.unbind()
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a linear motor as a long box along the axis, with a thin cylinder (spoke) to each atom. """ glPushMatrix() try: glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/pi, q.x, q.y, q.z) orig_center = V(0.0, 0.0, 0.0) drawbrick(color, orig_center, self.axis, self.length, self.width, self.width, opacity = self.opacity) drawLinearSign((0,0,0), orig_center, self.axis, self.length, self.width, self.width) # (note: drawLinearSign uses a small depth offset so that arrows are slightly in front of brick) # [bruce comment 060302, a guess from skimming drawLinearSign's code] for a in self.atoms[:]: drawcylinder(color, orig_center, a.posn()-self.center, self.sradius, opacity = self.opacity) except: #bruce 060208 protect OpenGL stack from exception analogous to that seen for RotaryMotor in bug 1445 print_compact_traceback("exception in LinearMotor._draw, continuing: ") glPopMatrix()
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 drawArrowHead(color, basePoint, drawingScale, unitBaseVector, unitHeightVector): arrowBase = drawingScale * 0.08 arrowHeight = drawingScale * 0.12 glDisable(GL_LIGHTING) glPushMatrix() glTranslatef(basePoint[0],basePoint[1],basePoint[2]) point1 = V(0, 0, 0) point1 = point1 + unitHeightVector * arrowHeight point2 = unitBaseVector * arrowBase point3 = - unitBaseVector * arrowBase #Draw the arrowheads as filled triangles glColor3fv(color) glBegin(GL_POLYGON) glVertex3fv(point1) glVertex3fv(point2) glVertex3fv(point3) glEnd() glPopMatrix() glEnable(GL_LIGHTING)
def main(): pygame.init() display = (800, 600) # pygame.display.set_mode(display, pygame.DOUBLEBUFFER) screen = pygame.display.set_mode(display) gluPerspective(45, display[0] / display[1], 0.001, 1000.0) glTranslatef(0.0, 0.0, -5.0) glRotatef(0, 0, 0, 0) print('before loop') done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) Cube() pygame.display.flip() pygame.time.wait(10) print('after loop')
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 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 InitGL(self, Width, Height): self.view_port_xr = 1 self.view_port_yr = 1 self.original_x = Width self.original_y = Height glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0, Width, 0, Height, -1, 1) glScalef(1, -1, 1) glTranslatef(0, -Height, 0) glMatrixMode(GL_MODELVIEW) glDisable(GL_DEPTH_TEST) # Disables Depth Testing glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading # Anti-aliasing/prettyness stuff glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_BLEND) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glHint(GL_POINT_SMOOTH_HINT, GL_NICEST) glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) glEnable(GL_LINE_SMOOTH) glEnable(GL_POINT_SMOOTH) glEnable(GL_POLYGON_SMOOTH) glClearColor(background_color()[0], background_color()[1], background_color()[2], 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
def drawFilledCircle(color, center, radius, normal): """ Scale, rotate/translate the unit circle properly. Added a filled circle variant, piotr 080405 """ glMatrixMode(GL_MODELVIEW) glPushMatrix() glColor3fv(color) glDisable(GL_LIGHTING) glTranslatef(center[0], center[1], center[2]) rQ = Q(V(0, 0, 1), normal) rotAngle = rQ.angle*180.0/pi #This may cause problems as proved before in Linear motor display. #rotation around (0, 0, 0) #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005: # rQ.x = 1.0 glRotatef(rotAngle, rQ.x, rQ.y, rQ.z) glScalef(radius, radius, 1.0) glCallList(drawing_globals.filledCircleList) glEnable(GL_LIGHTING) glPopMatrix() return
def drawRotateSign(color, pos1, pos2, radius, rotation = 0.0): """Rotate sign on top of the caps of the cylinder """ glPushMatrix() glColor3fv(color) vec = pos2-pos1 axis = norm(vec) glTranslatef(pos1[0], pos1[1], pos1[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2])*180.0/pi if (axis[2]*axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glRotate(rotation, 0.0, 0.0, 1.0) #bruce 050518 glScale(radius,radius,Numeric.dot(vec,vec)**.5) glLineWidth(2.0) glDisable(GL_LIGHTING) glCallList(drawing_globals.rotSignList) glEnable(GL_LIGHTING) glLineWidth(1.0) glPopMatrix() return
def _display_vector_head(self, head_angle: float): """Displays the robot's head to the current OpenGL context :param head_angle: the angle of the lift in radians """ glPushMatrix() # Rotate the head around the pivot glTranslatef(HEAD_PIVOT_X, 0.0, HEAD_PIVOT_Z) glRotatef(-head_angle, 0, 1, 0) glTranslatef(-HEAD_PIVOT_X, 0.0, -HEAD_PIVOT_Z) # Render all of the head meshes self.display_by_key("head_geo") # Screen self.display_by_key("backScreen_mat") self.display_by_key("screenEdge_geo") self.display_by_key("overscan_1_geo") # Eyes self.display_by_key("eye_L_geo") self.display_by_key("eye_R_geo") # Eyelids self.display_by_key("eyeLid_R_top_geo") self.display_by_key("eyeLid_L_top_geo") self.display_by_key("eyeLid_L_btm_geo") self.display_by_key("eyeLid_R_btm_geo") # Face cover (drawn last as it's translucent): self.display_by_key("front_Screen_geo") glPopMatrix()
def gl_display_cache_bars(self): """""" padding = 20.0 frame_max = len(self.g_pool.timestamps ) # last marker is garanteed to be frame max. glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() width, height = self.g_pool.camera_render_size h_pad = padding * (frame_max - 2) / float(width) v_pad = padding * 1.0 / (height - 2) gluOrtho( -h_pad, (frame_max - 1) + h_pad, -v_pad, 1 + v_pad, -1, 1 ) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() glTranslatef(0, -0.02, 0) color = (7.0, 0.1, 0.2, 8.0) draw_polyline( self.gl_display_ranges, color=RGBA(*color), line_type=GL_LINES, thickness=2.0, ) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def desenhar(self): glPushMatrix() glLoadIdentity() glTranslatef(*self.posicao) glColor3fv(self.cor) glBegin(GL_LINES) #desenha moldura glVertex3fv((0, 0, 0)) glVertex3fv((self.largura, 0, 0)) glVertex3fv((self.largura, 0, 0)) glVertex3fv((self.largura, self.altura, 0)) glVertex3fv((self.largura, self.altura, 0)) glVertex3fv((0, self.altura, 0)) glVertex3fv((0, self.altura, 0)) glVertex3fv((0, 0, 0)) i = 0 while (i < len(self.pontos) - 1): glVertex3fv((self.pontos[i][0]*self.escala_x, self.pontos[i][1]*self.escala_y, 0)) glVertex3fv((self.pontos[i + 1][0]*self.escala_x, self.pontos[i + 1][1]*self.escala_y, 0)) i += 1 glEnd() glPopMatrix()
def drawwiresphere_worker(params): """ Draw a wireframe sphere. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) """ (color, pos, radius, detailLevel) = params ## assert detailLevel == 1 # true, but leave out for speed from utilities.debug_prefs import debug_pref, Choice_boolean_True #bruce 060415 experiment, re iMac G4 wiresphere bug; fixes it! newway = debug_pref("new wirespheres?", Choice_boolean_True) oldway = not newway # These objects want a constant line color even if they are selected or # highlighted. glColor3fv(color) glDisable(GL_LIGHTING) if oldway: glPolygonMode(GL_FRONT, GL_LINE) glPushMatrix() glTranslatef(pos[0], pos[1], pos[2]) glScale(radius, radius, radius) if oldway: glCallList(drawing_globals.sphereList[detailLevel]) else: glCallList(drawing_globals.wiresphere1list) glEnable(GL_LIGHTING) glPopMatrix() if oldway: glPolygonMode(GL_FRONT, GL_FILL) return
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 draw_path_with_traveler(a_path): """ draws a box where the position of the traveler is on the path. """ #TODO: speed this up. take out the scale as well. draw_path(a_path) # Get where the traveler is, and draw something there. x,y,z = a_path.Where() ##glPushAttrib(GL_ALL_ATTRIB_BITS) ##glMatrixMode(GL_MODELVIEW) ##glLoadIdentity() ##glScale(0.2, 0.2, 0.2) glTranslatef(x,y,z) # now draw a teapot there. glutSolidTeapot(0.1) glTranslatef(-x,-y,-z)
def drawwiresphere_worker(params): """ Draw a wireframe sphere. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) """ (color, pos, radius, detailLevel) = params ## assert detailLevel == 1 # true, but leave out for speed from utilities.debug_prefs import debug_pref, Choice_boolean_True #bruce 060415 experiment, re iMac G4 wiresphere bug; fixes it! newway = debug_pref("new wirespheres?", Choice_boolean_True) oldway = not newway # These objects want a constant line color even if they are selected or # highlighted. glColor3fv(color) glDisable(GL_LIGHTING) if oldway: glPolygonMode(GL_FRONT, GL_LINE) glPushMatrix() glTranslatef(pos[0], pos[1], pos[2]) glScale(radius,radius,radius) if oldway: glCallList(drawing_globals.sphereList[detailLevel]) else: glCallList(drawing_globals.wiresphere1list) glEnable(GL_LIGHTING) glPopMatrix() if oldway: glPolygonMode(GL_FRONT, GL_FILL) return
def draw_path_with_traveler(a_path): """ draws a box where the position of the traveler is on the path. """ #TODO: speed this up. take out the scale as well. draw_path(a_path) # Get where the traveler is, and draw something there. x, y, z = a_path.Where() ##glPushAttrib(GL_ALL_ATTRIB_BITS) ##glMatrixMode(GL_MODELVIEW) ##glLoadIdentity() ##glScale(0.2, 0.2, 0.2) glTranslatef(x, y, z) # now draw a teapot there. glutSolidTeapot(0.1) glTranslatef(-x, -y, -z)
def move_camera(self, amount: float = 0, axis: int = 0): assert -1 < axis < 3, "Invalid axis!" xyz = [0, 0, 0] xyz[axis] = amount x, y, z = xyz glTranslatef(x, y, z)
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 _paintGLBox(self): self._position = (2.0, 2.0, 2.0) # Set fixed translation for now glTranslatef(*self._position) # Translate Box matrix = quaternion_matrix(self._orientation) # convert quaternion to translation matrix glMultMatrixf(matrix) # Rotate Box drawGrandAxis()
def draw(self): # this code is modified from GLPane.drawcompass glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() glMatrixMode( GL_PROJECTION ) # WARNING: we're now in nonstandard matrixmode (for sake of gluPickMatrix and glOrtho -- needed??##k) glPushMatrix() glLoadIdentity() try: glpane = self.env.glpane ## aspect = 1.0 ###WRONG -- should use glpane.aspect (which exists as of 070919) aspect = glpane.aspect # revised by bruce 070919, UNTESTED corner = self.corner delegate = self.delegate ###e should get glpane to do this for us (ie call a method in it to do this if necessary) # (this code is copied from it) glselect = glpane.current_glselect if glselect: # print "%r (ipath %r) setting up gluPickMatrix" % (self, self.ipath) x, y, w, h = glselect gluPickMatrix( x, y, w, h, glGetIntegerv(GL_VIEWPORT) # k is this arg needed? it might be the default... ) # the first three cases here are still ###WRONG if corner == UPPER_RIGHT: glOrtho(-50 * aspect, 5.5 * aspect, -50, 5.5, -5, 500) # Upper Right elif corner == UPPER_LEFT: glOrtho(-5 * aspect, 50.5 * aspect, -50, 5.5, -5, 500) # Upper Left elif corner == LOWER_LEFT: glOrtho(-5 * aspect, 50.5 * aspect, -5, 50.5, -5, 500) # Lower Left else: ## glOrtho(-50*aspect, 5.5*aspect, -5, 50.5, -5, 500) # Lower Right ## glOrtho(-50*aspect, 0, 0, 50, -5, 500) # Lower Right [used now] -- x from -50*aspect to 0, y (bot to top) from 0 to 50 glOrtho(-glpane.width * PIXELS, 0, 0, glpane.height * PIXELS, -5, 500) # approximately right for the checkbox, but I ought to count pixels to be sure (note, PIXELS is a pretty inexact number) glMatrixMode(GL_MODELVIEW) ###k guess 061210 at possible bugfix (and obviously needed in general) -- # do this last to leave the matrixmode standard # (status of bugs & fixes unclear -- hard to test since even Highlightable(projection=True) w/o any change to # projection matrix (test _9cx) doesn't work!) offset = (-delegate.bright, delegate.bbottom) # only correct for LOWER_RIGHT glTranslatef(offset[0], offset[1], 0) self.drawkid(delegate) ## delegate.draw() finally: glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) # be sure to do this last, to leave the matrixmode standard glPopMatrix() return
def draw(self): # this code is modified from GLPane.drawcompass glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() glMatrixMode(GL_PROJECTION) # WARNING: we're now in nonstandard matrixmode (for sake of gluPickMatrix and glOrtho -- needed??##k) glPushMatrix() glLoadIdentity() try: glpane = self.env.glpane ## aspect = 1.0 ###WRONG -- should use glpane.aspect (which exists as of 070919) aspect = glpane.aspect # revised by bruce 070919, UNTESTED corner = self.corner delegate = self.delegate ###e should get glpane to do this for us (ie call a method in it to do this if necessary) # (this code is copied from it) glselect = glpane.current_glselect if glselect: # print "%r (ipath %r) setting up gluPickMatrix" % (self, self.ipath) x,y,w,h = glselect gluPickMatrix( x,y, w,h, glGetIntegerv( GL_VIEWPORT ) #k is this arg needed? it might be the default... ) # the first three cases here are still ###WRONG if corner == UPPER_RIGHT: glOrtho(-50*aspect, 5.5*aspect, -50, 5.5, -5, 500) # Upper Right elif corner == UPPER_LEFT: glOrtho(-5*aspect, 50.5*aspect, -50, 5.5, -5, 500) # Upper Left elif corner == LOWER_LEFT: glOrtho(-5*aspect, 50.5*aspect, -5, 50.5, -5, 500) # Lower Left else: ## glOrtho(-50*aspect, 5.5*aspect, -5, 50.5, -5, 500) # Lower Right ## glOrtho(-50*aspect, 0, 0, 50, -5, 500) # Lower Right [used now] -- x from -50*aspect to 0, y (bot to top) from 0 to 50 glOrtho(-glpane.width * PIXELS, 0, 0, glpane.height * PIXELS, -5, 500) # approximately right for the checkbox, but I ought to count pixels to be sure (note, PIXELS is a pretty inexact number) glMatrixMode(GL_MODELVIEW) ###k guess 061210 at possible bugfix (and obviously needed in general) -- # do this last to leave the matrixmode standard # (status of bugs & fixes unclear -- hard to test since even Highlightable(projection=True) w/o any change to # projection matrix (test _9cx) doesn't work!) offset = (-delegate.bright, delegate.bbottom) # only correct for LOWER_RIGHT glTranslatef(offset[0], offset[1], 0) self.drawkid( delegate) ## delegate.draw() finally: glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) # be sure to do this last, to leave the matrixmode standard glPopMatrix() return
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a Rotary Motor jig as a cylinder along the axis, with a thin cylinder (spoke) to each atom. If <highlighted> is True, the Rotary Motor is draw slightly larger. """ ## print "RMotor _draw_jig",env.redraw_counter # This confirms that Jigs are drawn more times than they ought to need to be, # possibly due to badly organized Jig hit-testing code -- 4 times on mouseenter that highlights them in Build mode # (even after I fixed a bug today in which it redrew the entire model twice each frame); # but it's hard to find something to compare it to for an objective test of whether being a Jig matters, # since atoms, bonds, and chunks all have special behavior of their own. BTW, the suspected bad Jig code might redraw # everything (not only Jigs) this often, even though all it cares about is seeing Jigs in glRenderMode output. # BTW2, on opening a file containing one jig, it was drawn something like 20 times. # [bruce 060724 comments] if highlighted: inc = 0.01 # tested. Fixes bug 1681. mark 060314. else: inc = 0.0 glPushMatrix() try: glTranslatef(self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef(q.angle * 180.0 / pi, q.x, q.y, q.z) orig_center = V(0.0, 0.0, 0.0) bCenter = orig_center - (self.length / 2.0 + inc) * self.axis tCenter = orig_center + (self.length / 2.0 + inc) * self.axis drawcylinder(color, bCenter, tCenter, self.radius + inc, capped=1, opacity=self.opacity) for a in self.atoms: drawcylinder(color, orig_center, a.posn() - self.center, self.sradius + inc, opacity=self.opacity) rotby = self.getrotation() #bruce 050518 # if exception in getrotation, just don't draw the rotation sign # (safest now that people might believe what it shows about amount of rotation) drawRotateSign((0, 0, 0), bCenter, tCenter, self.radius, rotation=rotby) except: #bruce 060208 protect OpenGL stack from exception seen in bug 1445 print_compact_traceback( "exception in RotaryMotor._draw, continuing: ") print " some info that might be related to that exception: natoms = %d" % len( self.atoms) ###@@@ might not keep this glPopMatrix() return
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a ESP Image jig as a plane with an edge and a bounding box. """ glPushMatrix() glTranslatef(self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef(q.angle * 180.0 / math.pi, q.x, q.y, q.z) #bruce 060207 extensively revised texture code re fixing bug 1059 if self.tex_name is not None and self.image_obj: # self.image_obj condition is needed, for clear_esp_image() to work textureReady = True glBindTexture( GL_TEXTURE_2D, self.tex_name ) # maybe this belongs in draw_plane instead? Put it there later. ##e self._initTextureEnv() # sets texture params the way we want them else: textureReady = False drawPlane(self.fill_color, self.width, self.width, textureReady, self.opacity, SOLID=True, pickCheckOnly=self.pickCheckOnly) hw = self.width / 2.0 corners_pos = [ V(-hw, hw, 0.0), V(-hw, -hw, 0.0), V(hw, -hw, 0.0), V(hw, hw, 0.0) ] drawLineLoop(color, corners_pos) # Draw the ESP Image bbox. if self.show_esp_bbox: wo = self.image_offset eo = self.edge_offset drawwirecube(color, V(0.0, 0.0, 0.0), V(hw + eo, hw + eo, wo), 1.0) #drawwirebox # This is for debugging purposes. This draws a green normal vector using # local space coords. Mark 050930 if 0: from graphics.drawing.CS_draw_primitives import drawline drawline(green, V(0.0, 0.0, 0.0), V(0.0, 0.0, 1.0), 0, 3) glPopMatrix() # This is for debugging purposes. This draws a yellow normal vector using # model space coords. Mark 050930 if 0: from graphics.drawing.CS_draw_primitives import drawline from utilities.constants import yellow drawline(yellow, self.center, self.center + self.planeNorm, 0, 3)
def start_render(self): ''' ''' glDisable(GL_DEPTH_TEST) glPushMatrix() glLoadIdentity() glTranslatef(*self.translate)
def _draw_jig(self, glpane, color, highlighted = False): """ Draw an ESPImage jig (self) as a plane with an edge and a bounding box. @note: this is not called during graphicsMode.Draw_model as with most Jigs, but during graphicsMode.Draw_after_highlighting. """ glPushMatrix() glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/math.pi, q.x, q.y, q.z) #bruce 060207 extensively revised texture code re fixing bug 1059 if self.tex_name is not None and self.image_obj: # self.image_obj cond is needed, for clear_esp_image() to work textureReady = True glBindTexture(GL_TEXTURE_2D, self.tex_name) # review: maybe this belongs in draw_plane instead? self._initTextureEnv() # sets texture params the way we want them else: textureReady = False drawPlane(self.fill_color, self.width, self.width, textureReady, self.opacity, SOLID = True, pickCheckOnly = self.pickCheckOnly ) hw = self.width/2.0 corners_pos = [V(-hw, hw, 0.0), V(-hw, -hw, 0.0), V( hw, -hw, 0.0), V( hw, hw, 0.0)] drawLineLoop(color, corners_pos) # Draw the ESP Image bbox. if self.show_esp_bbox: wo = self.image_offset eo = self.edge_offset drawwirecube(color, V(0.0, 0.0, 0.0), V(hw + eo, hw + eo, wo), 1.0) #drawwirebox # This is for debugging purposes. This draws a green normal vector # using local space coords. [Mark 050930] if 0: from graphics.drawing.CS_draw_primitives import drawline drawline(green, V(0.0, 0.0, 0.0), V(0.0, 0.0, 1.0), 0, 3) glpane.kluge_reset_texture_mode_to_work_around_renderText_bug() glPopMatrix() # This is for debugging purposes. This draws a yellow normal vector # using model space coords. [Mark 050930] if 0: from graphics.drawing.CS_draw_primitives import drawline from utilities.constants import yellow drawline(yellow, self.center, self.center + self.planeNorm, 0, 3)
def iniciar_renderizado(self): """Acciones posteriores al renderizado de objetos.""" self.fbos[0].usar() #glClearColor(*self.capa.escena.color)#0.) para fondo transparente glClear(GL_COLOR_BUFFER_BIT) #| GL_DEPTH_BUFFER_BIT) # Transformación de la cámara glLoadIdentity() glScalef(self.acerc, self.acerc, 0.) glTranslatef(-self.pos.x, -self.pos.y, 0.) glRotatef(-self.angulo, 0., 0., 1.)
def move(self, i, j): # note: this separate move/draw API is obsolete, but still used, tho only locally (see paper notes circa 091113) "move from i to j, where both indices are encoded as None = self and 0 = self.thing" #e we might decide to only bother defining the i is None cases, in the API for this, only required for highlighting; # OTOH if we use it internally we might need both cases here assert self._e_is_instance x,y,z = tuple3_from_vec(self.vec) if i is None and j == 0: glTranslatef(x,y,z) ##e we should inline this method (leaving only this statement) into draw, before thing.draw ... elif i == 0 and j is None: glTranslatef(-x, -y, -z) ##e ... and leaving only this statement, after thing.draw return
def draw(self): glPushMatrix() prior = None for a in self.drawables: if prior: # move from prior to a dx = prior.bright + self.gap + a.bleft glTranslatef(dx,0,0) # positive is right, and Row progresses right prior = a self.drawkid(a) ## a.draw() glPopMatrix() return
def applyTransform(self): """ Apply self's transform to the GL matrix stack. (Pushing/popping the stack, if needed, is the caller's responsibility.) @note: this is used for display list primitives in CSDLs, but not for shader primitives in CSDLs. """ (q, v) = self.getRotateTranslate() glTranslatef(v[0], v[1], v[2]) glRotatef(q.angle * 180.0 / math.pi, q.x, q.y, q.z) return
def paintGL(self): if self.parent.ipcon == None: return glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Move Right And Into The Screen glLoadIdentity() glTranslatef(0.0, 0.0, -5.0) glMultMatrixf(self.m) glCallList(self.display_list)
def rotate(self, axis, angle): # rotate the object self.makeCurrent() glMatrixMode(GL_MODELVIEW) glLoadIdentity() t = [self._modelview_matrix[3][0], self._modelview_matrix[3][1], self._modelview_matrix[3][2]] glTranslatef(t[0], t[1], t[2]) glRotated(angle, axis[0], axis[1], axis[2]) glTranslatef(-t[0], -t[1], -t[2]) glMultMatrixd(self._modelview_matrix) # update _modelview_matrix self._modelview_matrix = glGetDoublev(GL_MODELVIEW_MATRIX)
def draw(self): with gx_matrix: glTranslatef(self.x, self.y, 0) set_color(0.2, 0.2, 0.2, 0.5) drawRectangle(size=self.size) self._label.x = 32 self._label.y = (self.height - self._label.height) / 2.0 self._label.draw() if self._icon: self._icon.x = (32 - self._icon.width) / 2.0 self._icon.y = (self.height - self._icon.height) / 2.0 self._icon.draw()
def drawsurface_worker(params): """Draw a surface. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below)""" (pos, radius, tm, nm) = params glPushMatrix() glTranslatef(pos[0], pos[1], pos[2]) glScale(radius,radius,radius) renderSurface(tm, nm) glPopMatrix() return
def Print(self, text): """Print(String text) prints text to the screen""" glPushMatrix() glTranslatef(0.02, 0.96, 0.0) # TODO where does the magic number come from? for character in text: if(character == "\n"): self.rasterPos -= self.y glRasterPos(0, self.rasterPos) else: glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(character)) glPopMatrix()