def _line(self, r1, r2): glColor(1, 1, 1) glLineWidth(1) glBegin(GL_LINES) glVertex3f(r1[0], r1[1], 0.0) glVertex3f(r2[0], r2[1], 0.0) glEnd()
def _paintGLGrid(self): resolutionMillimeters = 1 griddedAreaSize = 100 glLineWidth(1.0) glBegin(GL_LINES) glColor3f(1.0, 1.0, 1.0) glVertex3f(griddedAreaSize, 0, 0) glVertex3f(-griddedAreaSize, 0, 0) glVertex3f(0, griddedAreaSize, 0) glVertex3f(0, -griddedAreaSize, 0) numOfLines = int(griddedAreaSize / resolutionMillimeters) for i in range(numOfLines): glVertex3f(resolutionMillimeters * i, -griddedAreaSize, 0) glVertex3f(resolutionMillimeters * i, griddedAreaSize, 0) glVertex3f(griddedAreaSize, resolutionMillimeters * i, 0) glVertex3f(-griddedAreaSize, resolutionMillimeters * i, 0) glVertex3f(resolutionMillimeters * (-i), -griddedAreaSize, 0) glVertex3f(resolutionMillimeters * (-i), griddedAreaSize, 0) glVertex3f(griddedAreaSize, resolutionMillimeters * (-i), 0) glVertex3f(-griddedAreaSize, resolutionMillimeters * (-i), 0) glEnd()
def __init__(self, title='null'): # self.glview = gl.GLViewWidget() coord = gl.GLAxisItem() glLineWidth(1) coord.setSize(1, 1, 1) #self.glview.addItem(coord) self.glview.setMinimumSize(QtCore.QSize(600, 500)) self.glview.pan(1, 0, 0) self.glview.setCameraPosition(azimuth=180) self.glview.setCameraPosition(elevation=0) self.glview.setCameraPosition(distance=5) self.items = [] # self.view = QtGui.QWidget() self.view.window().setWindowTitle(title) hlayout = QtGui.QHBoxLayout() snap_btn = QtGui.QPushButton('&Snap') def take_snap(): qimg = self.glview.readQImage() qimg.save('1.jpg') snap_btn.clicked.connect(take_snap) hlayout.addWidget(snap_btn) hlayout.addStretch() layout = QtGui.QVBoxLayout() # layout.addLayout(hlayout) layout.addWidget(self.glview) self.view.setLayout(layout)
def drawline_worker(params): """ Draw a line. 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) """ (endpt1, endpt2, dashEnabled, stipleFactor, width, isSmooth) = params ###glDisable(GL_LIGHTING) ###glColor3fv(color) if dashEnabled: glLineStipple(stipleFactor, 0xAAAA) glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) if isSmooth: glEnable(GL_LINE_SMOOTH) glBegin(GL_LINES) glVertex(endpt1[0], endpt1[1], endpt1[2]) glVertex(endpt2[0], endpt2[1], endpt2[2]) glEnd() if isSmooth: glDisable(GL_LINE_SMOOTH) if width != 1: glLineWidth(1.0) # restore default state if dashEnabled: glDisable(GL_LINE_STIPPLE) ###glEnable(GL_LIGHTING) 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 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_line(line_width, color, x1, y1, x2, y2): glLineWidth(line_width) set_color(color) with mode(GL_LINES): glVertex2f(x1, y1) glVertex2f(x2, y2)
def display(self,factor) : ''' Function to display the localview axes. ''' right_arrow = self.right.add_vertex(self.pos,self.right.mult_vector(factor,self.right)) up_arrow = self.up.add_vertex(self.pos,self.up.mult_vector(factor,self.up)) sight_arrow = self.sight.add_vertex(self.pos,self.sight.mult_vector(factor,self.sight)) glLineWidth(4) glColor(255,0,0) glBegin(GL_LINES) glVertex(self.pos.get_vertex()) glVertex(right_arrow.get_vertex()) glEnd() glColor(0,255,0) glBegin(GL_LINES) glVertex(self.pos.get_vertex()) glVertex(up_arrow.get_vertex()) glEnd() glColor(0,0,255) glBegin(GL_LINES) glVertex(self.pos.get_vertex()) glVertex(sight_arrow.get_vertex()) glEnd()
def make_plane(): glNewList(G_OBJ_PLANE, GL_COMPILE) glBegin(GL_LINES) glColor3f(0, 0, 0) for i in range(41): glVertex3f(-10.0 + 0.5* i, 0, -10) glVertex3f(-10.0 + 0.5* i, 0, 10) glVertex3f(-10.0, 0, -10+0.5*i) glVertex3f(10.0, 0, -10+0.5*i) #Axes glEnd() glLineWidth(5) glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(5, 0.0, 0.0) glEnd() glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 5, 0.0) glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 5)
def draw_lines(self): """ draw our line segments, using our current style attrs [which are partly nim] """ # find variables which determine our GL state color = self.fix_color(self.linecolor) dashEnabled = self.dashed width = self.linewidth # set temporary GL state (code copied from drawer.drawline) glDisable(GL_LIGHTING) glColor3fv(color) if dashEnabled: glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) # draw the lines if self._closed_state: glBegin(GL_LINE_LOOP) else: glBegin(GL_LINE_STRIP) for pos in self.points: glVertex3fv(pos) # [note from old code: could be pos + origin if that can matter] glEnd() # restore default GL state [some of this might be moved up to callers] if width != 1: glLineWidth(1.0) if dashEnabled: glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return
def draw_lines(self): "draw our line segments, using our current style attrs [which are partly nim]" # find variables which determine our GL state color = self.fix_color(self.linecolor) dashEnabled = self.dashed width = self.linewidth # set temporary GL state (code copied from drawer.drawline) glDisable(GL_LIGHTING) glColor3fv(color) if dashEnabled: glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) # draw the lines if self._closed_state: glBegin(GL_LINE_LOOP) else: glBegin(GL_LINE_STRIP) for pos in self.points: glVertex3fv( pos ) # [note from old code: could be pos + origin if that can matter] glEnd() # restore default GL state [some of this might be moved up to callers] if width != 1: glLineWidth(1.0) if dashEnabled: glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return
def draw_player(self): glLineWidth(2) glPushMatrix() if self.degree == 90: if not self.check_goal(self.player, self.board): direction = self.get_direction(self.player) self.draw_main_cube(self.player[0], direction) self.draw_secondary_cube(self.player[1], direction) else: direction = self.get_direction(self.previous) self.draw_secondary_cube(self.player[1], direction) if direction != Direction.none and self.get_direction( self.player) == Direction.none: done = self.teleport_player(10, rotating_speed / 2) if self.rotate_before_swap(): if not done: self.steps = 1 self.degree = 0 elif self.check_goal(self.player, self.board): done = self.teleport_player(-10, rotating_speed / 5) if self.rotate_before_swap(): if not done: self.steps = 1 self.degree = 0 else: self.rotate_player() self.draw_main_cube(self.previous[0], direction) glPopMatrix() glLineWidth(1)
def draw(self, time, line_width=None): if self.hidden: return if time <= self.ts: return time = time * 1e-9 pos_start = self.pos path = self.speed * (time - self.ts * 1e-9) * self.dir # max_end = self.pos + (self.speed * self.te * self.dir) # if not int(self.te) == 0 and time > self.te: # pos_end = max_end # else: # pos_end = self.pos + path pos_end = self.pos + path glPushMatrix() if line_width: glLineWidth(line_width) else: glLineWidth(self.line_width) glColor3f(*self.color) glBegin(GL_LINES) glVertex3f(*pos_start) glVertex3f(*pos_end) glEnd() glPopMatrix()
def _init_GL(self): ''' ''' glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_BLEND) glEnable(GL_LINE_SMOOTH) glLineWidth(2.0) glEnable(GL_DEPTH_TEST) # glEnable(GL_TEXTURE_2D) # set the lighting self._set_lighting() # set the background color # glClearColor(0.15, 0.15, 0.15, 1) glClearDepth(1.0) # set the camera glMatrixMode(GL_PROJECTION) # glPushMatrix() glLoadIdentity() self._set_view_volume() glMatrixMode(GL_MODELVIEW) return
def __init__(self): self.app = pg.mkQApp() self.view = gl.GLViewWidget() coord = gl.GLAxisItem() glLineWidth(3) coord.setSize(3,3,3) self.view.addItem(coord)
def paint(self): glColor3f(0.0, 0.0, 0.6) glLineWidth(1.0); glBegin(GL_LINES) glVertex3f(*self.obj_a.position) glVertex3f(*self.obj_b.position) glEnd()
def draw(self, line_width=1, color=(1.0, 0.0, 0.0)): glEnable(GL_DEPTH_TEST) glEnable(GL_LINE_SMOOTH) glShadeModel(GL_FLAT) glPushMatrix() glLineWidth(line_width) glColor3f(*color) glBegin(GL_LINES) glVertex3f(-1.0, 0.0, 0.0) glVertex3f(1.0, 0.0, 0.0) glEnd() glPushMatrix() glTranslated(1.0, 0.0, 0.0) glRotated(90, 0.0, 1.0, 0.0) glutSolidCone(0.05, 0.2, 16, 16) glPopMatrix() glBegin(GL_LINES) glVertex3f(0.0, -1.0, 0.0) glVertex3f(0.0, 1.0, 0.0) glEnd() glPushMatrix() glTranslated(0.0, 1.0, 0.0) glRotated(-90, 1.0, 0.0, 0.0) glutSolidCone(0.05, 0.2, 16, 16) glPopMatrix() glBegin(GL_LINES) glVertex3f(0.0, 0.0, -1.0) glVertex3f(0.0, 0.0, 1.0) glEnd() glPushMatrix() glTranslated(0.0, 0.0, 1.0) glutSolidCone(0.05, 0.2, 16, 16) glPopMatrix() glPopMatrix()
def make_plane(): glNewList(G_OBJ_PLANE, GL_COMPILE) glBegin(GL_LINES) glColor3f(0, 0, 0) for i in xrange(41): glVertex3f(-10.0 + 0.5 * i, 0, -10) glVertex3f(-10.0 + 0.5 * i, 0, 10) glVertex3f(-10.0, 0, -10 + 0.5 * i) glVertex3f(10.0, 0, -10 + 0.5 * i) # Axes glEnd() glLineWidth(5) glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(5, 0.0, 0.0) glEnd() glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 5, 0.0) glEnd() glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 5) glEnd() # Draw the Y. glBegin(GL_LINES) glColor3f(0.0, 0.0, 0.0) glVertex3f(0.0, 5.0, 0.0) glVertex3f(0.0, 5.5, 0.0) glVertex3f(0.0, 5.5, 0.0) glVertex3f(-0.5, 6.0, 0.0) glVertex3f(0.0, 5.5, 0.0) glVertex3f(0.5, 6.0, 0.0) # Draw the Z. glVertex3f(-0.5, 0.0, 5.0) glVertex3f(0.5, 0.0, 5.0) glVertex3f(0.5, 0.0, 5.0) glVertex3f(-0.5, 0.0, 6.0) glVertex3f(-0.5, 0.0, 6.0) glVertex3f(0.5, 0.0, 6.0) # Draw the X. glVertex3f(5.0, 0.0, 0.5) glVertex3f(6.0, 0.0, -0.5) glVertex3f(5.0, 0.0, -0.5) glVertex3f(6.0, 0.0, 0.5) glEnd() glLineWidth(1) glEndList()
def bordes_plano_horizontal(self): if self.programa.ajustes.ver_plano_horizontal.isChecked(): glLineWidth(1) glColor(self.programa.ajustes.color_plano_horizontal) glBegin(GL_LINE_LOOP) for vertex in range(4): glVertex(self.vertices_borde_plano_horizontal[vertex]) glEnd()
def draw_rectangle(width, height, color, line_width=2): glColor3f(*color) glLineWidth(line_width) glBegin(GL_LINE_LOOP) for coords in [[1, 1], [1, -1], [-1, -1], [-1, 1]]: glVertex2f(*shift_scale_point( vec.Vec([width / 2, height / 2]) * vec.Vec(coords))) glEnd()
def _rectangle(self, r1, r2): glColor(1, 1, 1) glLineWidth(1) glBegin(GL_LINE_LOOP) glVertex3f(r1[0], r1[1], 0.0) glVertex3f(r2[0], r1[1], 0.0) glVertex3f(r2[0], r2[1], 0.0) glVertex3f(r1[0], r2[1], 0.0) glEnd()
def draw_lines_2d(lines, color, line_width=2): glColor3f(*color) glLineWidth(line_width) glBegin(GL_LINES) for line in lines: for point in line: glVertex2f(*shift_scale_point(point)) glEnd()
def draw_points_2d(points, color, line_width=2): glColor3f(*color) #draw each point as a line with (almost) identical start and end points glLineWidth(line_width) for point in points: glBegin(GL_LINES) glVertex2f(*shift_scale_point(point)) glVertex2f(*(shift_scale_point(point) + vec.Vec([1, 0]))) glEnd()
def draw_arrowhead(x1, y1, x2, y2, noderadius, arrowwidth=20, angle=20, trans=1.0): ''' Draws an arrow head on the line segment between the coordinate pairs (x1,y1) and (x2,y2). The arrow head is placed in the (x2,y2)-end. ''' if x1 - x2 == 0: if y2 <= y1: LineAngle = math.pi / 2 else: LineAngle = 3 * math.pi / 2 else: LineAngle = math.atan((y2 - y1) / (x2 - x1)) EndAngle1 = LineAngle + angle * math.pi / 180 EndAngle2 = LineAngle - angle * math.pi / 180 xOffset = noderadius * math.cos(LineAngle) yOffset = noderadius * math.sin(LineAngle) if x1 < x2: Y3 = y2 - arrowwidth * math.sin(EndAngle1) Y4 = y2 - arrowwidth * math.sin(EndAngle2) X3 = x2 - arrowwidth * math.cos(EndAngle1) X4 = x2 - arrowwidth * math.cos(EndAngle2) x2 -= xOffset y2 -= yOffset Y3 -= yOffset Y4 -= yOffset X3 -= xOffset X4 -= xOffset else: Y3 = y2 + arrowwidth * math.sin(EndAngle1) Y4 = y2 + arrowwidth * math.sin(EndAngle2) X3 = x2 + arrowwidth * math.cos(EndAngle1) X4 = x2 + arrowwidth * math.cos(EndAngle2) x2 += xOffset y2 += yOffset Y3 += yOffset Y4 += yOffset X3 += xOffset X4 += xOffset glLineWidth(1.0) glColor4f(arrow_color()[0], arrow_color()[1], arrow_color()[2], trans) glBegin(GL_TRIANGLES) glVertex2f(x2, y2) glVertex2f(X3, Y3) glVertex2f(X4, Y4) glEnd()
def draw_border(self): bw, bh = self.size #double size since half the line will be off-screen log("draw_border: %s", self.border) glLineWidth(self.border.size*2) glBegin(GL_LINE_LOOP) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) for px,py in ((0, 0), (bw, 0), (bw, bh), (0, bh)): glVertex2i(px, py) glEnd()
def _draw(self): glLineWidth(4.0) glBegin(GL_LINES) glColor3f(119, 25, 25) for path in list(self._path_queue): glVertex3f(path[0] * self._resolution_meter -4,path[1] * self._resolution_meter,5) glVertex3f(path[0]* self._resolution_meter+4,path[1] * self._resolution_meter,5) glEnd()
def draw_Dierkes_lines(self, result): glPushMatrix() glMatrixMode(GL_MODELVIEW) glColor4f(1.0, 0.0, 0.0, 0.1) glLineWidth(1.0) for line in result["debug_info"]["Dierkes_lines"][::4]: glBegin(GL_LINES) glVertex3f(line[0], line[1], line[2]) glVertex3f(line[3], line[4], line[5]) glEnd() glPopMatrix()
def draw_lines(self, line_width=1): glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) for position in self.line_positions: glPushMatrix() glTranslated(position[0], position[1], 0) glLineWidth(line_width) glBegin(GL_LINES) glVertex3f(0.0, 0.0, self.z_min) glVertex3f(0.0, 0.0, self.z_max) glEnd() glPopMatrix()
def draw(self, line_width=2): glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) glPushMatrix() glTranslated(self.x, self.y, self.z) glLineWidth(line_width) glColor3f(1.0, 1.0, 1.0) glBegin(GL_LINES) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, self.length) glEnd() glPopMatrix()
def drawLineLoop(color, lines, width=1): glDisable(GL_LIGHTING) glColor3fv(color) glLineWidth(width) glBegin(GL_LINE_LOOP) for v in lines: glVertex3fv(v) glEnd() glEnable(GL_LIGHTING) #reset the glLineWidth to 1 if width != 1: glLineWidth(1) return
def drawLineLoop(color,lines, width = 1): glDisable(GL_LIGHTING) glColor3fv(color) glLineWidth(width) glBegin(GL_LINE_LOOP) for v in lines: glVertex3fv(v) glEnd() glEnable(GL_LIGHTING) #reset the glLineWidth to 1 if width!=1: glLineWidth(1) return
def draw_circle_2d(radius, color, n_points=60, line_width=2, draw_origin=vec.zero_vec(2)): glColor3f(*color) glLineWidth(line_width) glBegin(GL_LINE_LOOP) for i in range(n_points): x = math.cos(math.pi * 2 * i / n_points) * radius y = math.sin(math.pi * 2 * i / n_points) * radius p = vec.Vec([x, y]) + draw_origin glVertex2f(*shift_scale_point(p)) glEnd()
def _draw(self): if self._cross is None: return glLineWidth(3.0) glBegin(GL_LINES) glColor3f(1.0, 0.0, 0.0) glVertex3f(self._cross[0] - 20, self._cross[1] - 20, 10) glVertex3f(self._cross[0] + 20, self._cross[1] + 20, 10) glVertex3f(self._cross[0] - 20, self._cross[1] + 20, 10) glVertex3f(self._cross[0] + 20, self._cross[1] - 20, 10) glEnd()
def render_border(self): from OpenGL.GL import glColor3f, glLineWidth, glBegin, glEnd, glVertex3f, GL_LINE_LOOP for border_loop in self.border_loop_list: scale = 1.001 glColor3f(0.0, 0.0, 0.0) glLineWidth(4.0) glBegin(GL_LINE_LOOP) try: for i in border_loop: point = self.vertex_list[i].clone() point *= scale # This idea won't work in all cases. glVertex3f(point.x, point.y, point.z) finally: glEnd()
def draw(self, time, line_width=None): if self.hidden: return time = time * 1e-9 if time <= self.time: return pos_start = self.pos + (self.speed * (-self.time) * self.dir) path = self.speed * (time - self.time) * self.dir if self.length: max_path = self.length * self.dir if np.linalg.norm(max_path) <= np.linalg.norm(path): path = max_path pos_end = self.pos + path glPushMatrix() if line_width: glLineWidth(line_width) else: glLineWidth(self.line_width) glColor3f(*self.color) glBegin(GL_LINES) glVertex3f(*pos_start) glVertex3f(*pos_end) glEnd() glPopMatrix() if self.cherenkov_cone_enabled and self.colourist.cherenkov_cone_enabled: height = np.linalg.norm(pos_end - pos_start) position = pos_end - self.dir * height glEnable(GL_LIGHTING) glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) glColor4f(0.0, 0.0, 0.8, 0.3) glPushMatrix() glTranslated(*position) glPushMatrix() v = np.array(self.dir) glMultMatrixf(transform(v)) glutSolidCone(0.6691 * height, height, 128, 64) glPopMatrix() glPopMatrix() glDisable(GL_LIGHTING)
def _render_highlighted(self) -> None: """Render cube outline on face that is hovered.""" if not self._hovered: return glDisable(GL_DEPTH_TEST) glLineWidth(2.0) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glBindVertexArray(self._vao_outline) glDrawArrays(GL_QUADS, self._hover_id * 4, 4) glEnable(GL_DEPTH_TEST) glLineWidth(1.0) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
def draw_points_3d(points, color, draw_origin, draw_angles, line_width=2): gl.glLoadIdentity() # reset position gl.glTranslatef(*draw_origin) #origin of plotting gl.glRotatef(draw_angles[1], 1, 0, 0) gl.glRotatef(draw_angles[0], 0, 1, 0) glColor3f(*color) #draw each point as a line with (almost) identical start and end points glLineWidth(line_width) for point in points: glBegin(GL_LINES) glVertex3f(*point) glVertex3f(*(point + vec.Vec([0.01, 0, 0]))) glEnd()
def _draw(self): glLineWidth(4.0) glBegin(GL_LINES) glColor3f(0.5, 0.5, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(50.0, 0.0, 1.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 50.0, 1.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 50.0) glEnd()
def draw(self): glDisable(GL_LIGHTING) glLineWidth(self._width) glColor(*self._color) glEnableClientState(GL_VERTEX_ARRAY) if self._vbo: with self._vbo: glVertexPointerf(self._vbo) glDrawArrays(GL_LINE_STRIP, 0, len(self._vbo)) glDisableClientState(GL_VERTEX_ARRAY) glEnable(GL_LIGHTING)
def _initGL(self, extraArgs): """initializes OpenGL and creates the Window""" glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutInitWindowSize(self.size, self.size) glutInitWindowPosition(self.initx, self.inity) glutInit(extraArgs.split(" ")) glutCreateWindow(VERSIONSTRING.encode("ascii")) glutDisplayFunc(self.Draw) glutIdleFunc(glutPostRedisplay) glutReshapeFunc(self.Reshape) glutKeyboardFunc(self.HandleKeys) glutSpecialFunc(self.HandleKeys) glutMouseFunc(self.HandleMouse) glClearColor(*(self.bgcolor + [0.0])) glEnable(GL_LINE_SMOOTH) glLineWidth(1.3)
def draw(self): # draw gestures set_color(1, 1, 1, .6) for touch in getCurrentTouches(): if not 'desktop.gesture' in touch.userdata: continue drawLine(touch.userdata['desktop.gesture'], width=5.) if len(getCurrentTouches()): self.inactivity = 0 return self.inactivity += getFrameDt() if self.inactivity < self.inactivity_timeout: return alpha = (self.inactivity - self.inactivity_timeout) / 3. alpha = boundary(alpha, 0, 1.) w = self.get_parent_window() s2 = Vector(w.size) / 2. self.dt += getFrameDt() * 2 step = math.pi / 20. radius = 50 i = 0 with DO(gx_attrib(GL_LINE_BIT), gx_blending): glLineWidth(3) with gx_begin(GL_LINE_STRIP): while i < math.pi * 2: x, y = math.cos(self.dt - i) * radius, math.sin(self.dt - i) * radius glColor4f(1, 1, 1, min(alpha, i / math.pi)) glVertex2f(x + s2.x, y + s2.y - 70) i += step set_color(1, 1, 1, alpha) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=4) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=20, linewidth=2) label = 'Draw a circle to make the menu appear' k = {'font_size': 24, 'bold': True} pos = Vector(w.size) / 2. + Vector(0, 10) drawLabel(label=label, pos=pos, color=(.5, .5, .5, min(alpha, .5)), **k) pos += Vector(1, -1) drawLabel(label=label, pos=pos, color=(1, 1, 2, alpha), **k)
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if self.paint_box_line_width<=0: return glLineWidth(self.paint_box_line_width+0.5+int(encoding=="scroll")*2) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = get_paint_box_color(encoding) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def display(self): self.world.drawGL() glDisable(GL_LIGHTING) glLineWidth(2.0) glEnableClientState(GL_VERTEX_ARRAY) for (color, vbo) in self.trace_vbos: glColor(*color) with vbo: glVertexPointerf(vbo) glDrawArrays(GL_LINE_STRIP, 0, len(vbo)) glDisableClientState(GL_VERTEX_ARRAY) glEnable(GL_LIGHTING)
def render(self): glLineWidth(3.0) glColor(0.7, 0.0, 0.0, 1.0) gltools.glMove([0.0, 0.0, 0.0]) glBegin(GL_LINE_STRIP) for p in [self.p1, self.C, self.p2]: glVertex(p) glEnd() glColor(0.545, 0.000, 0.000, 1.0) gltools.glMove(self.p1) glutSolidSphere(0.03, 4, 2) glColor(1.000, 0.843, 0.000, 1.0) gltools.glMove(self.C) glutSolidSphere(0.03, 4, 2) glColor(0.294, 0.000, 0.510, 1.0) gltools.glMove(self.p2) glutSolidSphere(0.03, 4, 2) glLineWidth(1.0)
def _paintGLCoorsystem(self): glLineWidth(10.0) glBegin(GL_LINES) glColor3f(1.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(1.0, 0.0, 0.0) glColor3f(0.0, 1.0, 0.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 1.0, 0.0) glColor3f(0.0, 0.0, 1.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 1.0) glEnd()
def _draw(self): try: self._lock.acquire() gridded_area_size = 1500 glLineWidth(1.0) num_of_lines = int(gridded_area_size / self._resolution_meters) glBegin(GL_LINES) glColor3f(0.188, 0.188, 0.188) glVertex3f(gridded_area_size, 0, 0) glVertex3f(-gridded_area_size, 0, 0) glVertex3f(0, gridded_area_size, 0) glVertex3f(0, -gridded_area_size, 0) for i in range(num_of_lines): glVertex3f(self._resolution_meters * i, -gridded_area_size, 0) glVertex3f(self._resolution_meters * i, gridded_area_size, 0) glVertex3f(gridded_area_size, self._resolution_meters * i, 0) glVertex3f(-gridded_area_size, self._resolution_meters * i, 0) glVertex3f(self._resolution_meters * (-i), -gridded_area_size, 0) glVertex3f(self._resolution_meters * (-i), gridded_area_size, 0) glVertex3f(gridded_area_size, self._resolution_meters * (-i), 0) glVertex3f(-gridded_area_size, self._resolution_meters * (-i), 0) glEnd() glLineWidth(3.0) glBegin(GL_LINES) glVertex3f(0, -gridded_area_size, 0) glVertex3f(0, gridded_area_size, 0) glVertex3f(gridded_area_size, 0, 0) glVertex3f(-gridded_area_size, 0, 0) glEnd() finally: self._lock.release()
def __draw(self, widget, event): x = self.__distance * sin(self.__angle) z = self.__distance * cos(self.__angle) gldrawable = widget.get_gl_drawable() glcontext = widget.get_gl_context() # OpenGL begin. if not gldrawable.gl_begin(glcontext): return glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity () gluLookAt(x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) #========================== glPushMatrix() glLineWidth(3) glRotatef(self.__arm_angles[0], 1., 0., 0.) glRotatef(self.__arm_angles[1], 0., 1., 0.) glRotatef(self.__arm_angles[2], 0., 0., 1.) glTranslatef(self.__upper_arm, 0., 0.) #========================== glPushMatrix() glColor3f(30./255., 126./255., 30./255.) glScalef(self.__upper_arm, 0.4, 1.0) self.__draw_cube() # shoulder glPopMatrix() #========================== glTranslatef(self.__upper_arm, 0., 0.) glRotatef(self.__arm_angles[3] , 0., 0., 1.) glTranslatef(self.__forearm, 0., 0.) glPushMatrix() #========================== glScalef(self.__forearm, 0.3, 0.75) glColor3f(126./255., 30./255., 30./255.) self.__draw_cube() # elbow glPopMatrix() glPopMatrix() #========================== if gldrawable.is_double_buffered(): gldrawable.swap_buffers() else: glFlush() gldrawable.gl_end() # OpenGL end return
def draw(self): # extract relative position rx, ry = self.relpos # calculate triangle mx = self.x + rx + self.width * 0.5 + self.trirelpos[0] my = self.y + ry + self.height * 0.5 + self.trirelpos[1] angle = Vector(1, 0).angle(Vector(mx - self.x, my - self.y)) vpos = Vector(mx, my) v1 = Vector(self.trisize, 0).rotate(angle) + vpos v2 = Vector(-self.trisize, 0).rotate(angle) + vpos # draw border if self.bordersize > 0: drawRoundedRectangle( pos=(self.x - self.padding - self.bordersize + rx, self.y - self.padding - self.bordersize + ry), size=(self.width + self.padding * 2 + self.bordersize * 2, self.height + self.padding * 2 + self.bordersize * 2), radius=self.radius, color=self.bordercolor ) glEnable(GL_LINE_SMOOTH) glLineWidth(self.bordersize * 2) drawPolygon((self.x, self.y, v1.x, v1.y, v2.x, v2.y), style=GL_LINE_LOOP) # draw background drawRoundedRectangle( pos=(self.x - self.padding + rx, self.y - self.padding + ry), size=(self.width + self.padding * 2, self.height + self.padding * 2), radius=self.radius, color=self.bgcolor ) drawPolygon((self.x, self.y, v1.x, v1.y, v2.x, v2.y)) # hack to translate label position with gx_matrix: glTranslatef(rx, ry, 0) super(MTSpeechBubble, self).draw()
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if not OPENGL_PAINT_BOX>0: return glDisable(GL_TEXTURE_RECTANGLE_ARB) glDisable(GL_FRAGMENT_PROGRAM_ARB) glLineWidth(OPENGL_PAINT_BOX+0.5) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def draw(self): # draw gestures set_color(1, 1, 1, 0.6) for touch in getCurrentTouches(): if not "desktop.gesture" in touch.userdata: continue drawLine(touch.userdata["desktop.gesture"], width=5.0) if len(getCurrentTouches()): self.inactivity = 0 return self.inactivity += getFrameDt() if self.inactivity < self.inactivity_timeout: return alpha = (self.inactivity - self.inactivity_timeout) / 3.0 alpha = boundary(alpha, 0, 1.0) w = self.get_parent_window() s2 = Vector(w.size) / 2.0 self.dt += getFrameDt() * 2 step = math.pi / 20.0 radius = 50 i = 0 with DO(gx_attrib(GL_LINE_BIT), gx_blending): glLineWidth(3) with gx_begin(GL_LINE_STRIP): while i < math.pi * 2: x, y = math.cos(self.dt - i) * radius, math.sin(self.dt - i) * radius glColor4f(1, 1, 1, min(alpha, i / math.pi)) glVertex2f(x + s2.x, y + s2.y - 70) i += step set_color(1, 1, 1, alpha) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=4) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=20, linewidth=2) label = "Draw a circle to make the menu appear" k = {"font_size": 24, "bold": True} pos = Vector(w.size) / 2.0 + Vector(0, 10) drawLabel(label=label, pos=pos, color=(0.5, 0.5, 0.5, min(alpha, 0.5)), **k) pos += Vector(1, -1) drawLabel(label=label, pos=pos, color=(1, 1, 2, alpha), **k)
def draw(self, time, line_width=None): if self.hidden: return time = time * 1e-9 pos_start = self.start_pos + (constants.c * (-self.time) * self.dir) if time >= self.time: pos_end = self.pos else: path = constants.c * (time - self.time) * self.dir pos_end = self.pos + path glPushMatrix() glLineWidth(self.line_width) glColor3f(*self.color) glBegin(GL_LINES) glVertex3f(*pos_start) glVertex3f(*pos_end) glEnd() glPopMatrix()
def startPatternedDrawing(highlight = False, select = False): """ Start drawing with a patterned style, if either highlight or select is passed as True, and the corresponding preference is set to select a patterned drawing style. This is common code for two different prefs keys, each of which has its own set of settings constants... Return value is True if one of the patterned styles is selected. """ (key, style, solid, pattern, edges, halos) = \ _decodePatternPrefs(highlight, select) if solid: # Nothing to do here for solid colors. return False # Set up stipple-patterned drawing styles. if pattern is not None: glEnable(GL_POLYGON_STIPPLE) glPolygonStipple(pattern) return True # Both polygon edges and halos are drawn in line-mode. if edges or halos: glPolygonMode(GL_FRONT, GL_LINE) glPolygonMode(GL_BACK, GL_LINE) if halos: # Draw wide, unshaded lines, offset a little bit away from the # viewer so that only the silhouette edges are visible. glDisable(GL_LIGHTING) glLineWidth(env.prefs[haloWidth_prefs_key]) glEnable(GL_POLYGON_OFFSET_LINE) glPolygonOffset(0.0, 5.e4) # Constant offset. pass pass return True
def drawAxis(color, pos1, pos2, width = 2): #Ninad 060907 """ Draw chunk or jig axis """ #ninad060907 Note that this is different than draw # I may need this function to draw axis line. see its current implementation # in branch "ninad_060908_drawAxis_notAsAPropOfObject" glDisable(GL_LIGHTING) glColor3fv(color) glLineStipple(3, 0x1C47) # dash-dot-dash line glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) glBegin(GL_LINES) glVertex(pos1[0], pos1[1], pos1[2]) glVertex(pos2[0], pos2[1], pos2[2]) glEnd() if width != 1: glLineWidth(1.0) # restore default state glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return