def drawFocus(self): glColor4f(0, 0, 0, 0.4) glPushMatrix() glLoadIdentity() glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluOrtho2D(0, self.width, 0, self.height) glLineStipple(1, 0xf0f0) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) glVertex2f(1, 0) glVertex2f(self.width, 0) glVertex2f(self.width, self.height - 1) glVertex2f(1, self.height - 1) glEnd() glDisable(GL_LINE_STIPPLE) glPopMatrix() # restore PROJECTION glMatrixMode(GL_MODELVIEW) glPopMatrix()
def draw(self): from miru.context import context gl.glEnable(gl.GL_LINE_STIPPLE) gl.glLineStipple(1, 0x51315) gl.glColor4f(*self.color) for c in self.metaCamera.cameras: vp = c.projection x = vp.x == 0 and 1 or vp.x width = vp.x == 0 and vp.width - 1 or vp.width width = (vp.x + vp.width) >= context.window.width and width - 1 or width y = vp.y == 0 and 1 or vp.y height = vp.y == 0 and vp.height - 1 or vp.height height = (vp.y + vp.height) >= context.window.height and height - 1 or height gl.glBegin(gl.GL_LINE_LOOP) gl.glVertex2f(x, y) gl.glVertex2f(x, y + height) gl.glVertex2f(x + width, y + height) gl.glVertex2f(x + width, y) gl.glEnd() gl.glDisable(gl.GL_LINE_LOOP) gl.glColor4f(1,1,1,1)
def render(self): """ Draws Line """ p1 = self.a2 p2 = self.b2 gl.glColor4f(*self.color) color = (gl.GLfloat * 4)(*self.color) gl.glPushMatrix() gl.glTranslatef(self.x, self.y, -self.z) # translate to GL loc ppint gl.glRotatef(self.rotation, 0, 0, 0.1) if self.style: gl.glEnable(gl.GL_LINE_STIPPLE) gl.glLineStipple(1, self.style) ## else : ## glDisable(GL_LINE_STIPPLE) if self.stroke <= 0: self.stroke = 1 gl.glLineWidth(self.stroke) gl.glBegin(gl.GL_LINES) gl.glVertex2i(int(p1[0]), int(p1[1])) # draw pixel points gl.glVertex2i(int(p2[0]), int(p2[1])) gl.glEnd() if self.style: gl.glDisable(gl.GL_LINE_STIPPLE) gl.glPopMatrix()
def draw(self, state = [0,0,0]): gl.glEnable (gl.GL_LINE_SMOOTH); gl.glHint (gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glLoadIdentity() gl.glLineWidth(1) gl.glColor3f(.7,.7,.7) draw_rect((-.5,0), (.5,-.01)) draw_rect((-.01,0),(.01,1)) gl.glTranslatef(0,self.r_roller,0); gl.glPushMatrix(); gl.glTranslatef(state[0]*self.r_roller, 0, 0) gl.glColor3f(0,0,0) gl.glLineWidth(3) # gl.glPushMatrix() gl.glRotatef(-R2D*state[0],0,0,1) draw_mass_center(self.r_roller, (0,0)) # gl.glPopMatrix() gl.glRotatef(-R2D*state[1], 0, 0, 1) gl.glTranslatef(0,self.r_roller,0) gl.glPushMatrix() gl.glRotatef(R2D*(state[1]+state[0]),0,0,1) gl.glPushAttrib(gl.GL_ENABLE_BIT); gl.glColor3f(.7,.2,.2) gl.glLineStipple(1, 0xF00F) # [1] gl.glEnable(gl.GL_LINE_STIPPLE) draw_line((0,0),(0,1)) gl.glPopAttrib() gl.glPopMatrix() gl.glTranslatef(-state[1] * self.r_roller,0,0) gl.glColor3f(0,0,0) draw_rect( (-self.l_board/2,0), (self.l_board/2,.02)) gl.glColor3f(.5,.5,.5) draw_rect((-.01,0), (.01,self.h_body)) gl.glPushMatrix() gl.glTranslatef(0, self.h_body, 0) gl.glRotatef(R2D*state[2], 0, 0, 1) gl.glColor3f(0,0,0); draw_mass_center(.1, (0,0)) gl.glPopMatrix() if len(state) >= 8: gl.glPushMatrix() gl.glTranslatef(0, self.h_body, 0) gl.glRotatef(R2D*state[3], 0, 0, 1) gl.glTranslatef(0, -self.h_body+self.r_roller+.05, 0) gl.glColor3f(0,0,0); draw_mass_center(.03, (0,0)) gl.glPopMatrix() gl.glPopMatrix();
def draw_line(x1, y1, x2, y2, width=2): glLineStipple(1, 0xFF) glEnable(GL_LINE_STIPPLE) glLineWidth(width) glBegin(GL_LINES) glVertex2f(x1, y1) glVertex2f(x2, y2) glEnd()
def drawVertex(self, x, y, z=0, v=(), color=(0, 0, 0, 1), stroke=0, rotation=0.0, style=0): gl.glColor4f(*self.color) gl.glPushMatrix() gl.glTranslatef(x, y, -z) gl.glRotatef(self.rotation, 0, 0, 0.1) if self.style: gl.glEnable(gl.GL_LINE_STIPPLE) gl.glLineStipple(1, style) ## else : ## glDisable(GL_LINE_STIPPLE) ## 0xF0F0 # dashed line ## 0xF00F # long dashed line ## 0x8888 # dotted lines ## glRect(x1,y,1,x1,x2) ## glRectiv(v1,v2) # oposite vertex of rectangle # -- start drawing if self.stroke: # outlined polygon gl.glLineWidth(self.stroke) gl.glBegin(gl.GL_LINE_LOOP) else: # filled polygon if len(v) == 4: gl.glBegin(gl.GL_QUADS) elif len(v) > 4: gl.glBegin(gl.GL_POLYGON) else: gl.glBegin( gl.GL_TRIANGLES) # which type of polygon are we drawing? for p in v: gl.glVertex3f(p[0], p[1], 0) # draw each vertex gl.glEnd() # -- end drawing if self.style: gl.glDisable(gl.GL_LINE_STIPPLE) gl.glPopMatrix()
def dont_draw(self): super(Actor, self).draw() from pyglet import gl # TODO this is all almost certainly not the nicest way to do any of # this. gl.glColor3f(1, 1, 0) # NOTE: a vertex list has a .draw() but it does its own thang that # includes setting the color v = list(self._vertex_list.vertices) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) gl.glLineStipple(1, 0x5555) gl.glEnable(gl.GL_LINE_STIPPLE) gl.glBegin(gl.GL_QUADS) gl.glVertex2f(v[0], v[1]) gl.glVertex2f(v[2], v[3]) gl.glVertex2f(v[4], v[5]) gl.glVertex2f(v[6], v[7]) gl.glEnd() gl.glDisable(gl.GL_LINE_STIPPLE) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) # Draw a dot at the anchor point gl.glPushMatrix() self.transform() n = 2 / self.scale gl.glBegin(gl.GL_QUADS) gl.glVertex2f(n, n) gl.glVertex2f(n, -n) gl.glVertex2f(-n, -n) gl.glVertex2f(-n, n) gl.glEnd() gl.glPopMatrix() gl.glColor3f(1, 1, 1)
def enable(self): glEnable(GL_LINE_STIPPLE) glLineStipple(1, self.style)
def on_draw(): window.clear() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(-wx, wx, -wy, wy, -1, 1) gl.glBegin(gl.GL_QUADS) gl.glColor3f(1, 0.5, 1) gl.glVertex3f(d, d, 0) gl.glColor3f(1, 1, 0.5) gl.glVertex3f(d, -d, 0) gl.glColor3f(0.5, 1, 1) gl.glVertex3f(-d, -d, 0) gl.glColor3f(1, 0.5, 0.5) gl.glVertex3f(-d, d, 0) gl.glColor3f(1, 1, 1) gl.glEnd() pattern = '0b1111000011110000' gl.glLineStipple(2, int(pattern, 2)) gl.glColor3f(1, 0.5, 0.5) gl.glBegin(gl.GL_LINES) gl.glVertex3f(-20*d, 0, 0) gl.glVertex3f(20*d, 0, 0) gl.glVertex3f(0, -20*d, 0) gl.glVertex3f(0, 20*d, 0) gl.glEnd() gl.glDisable(gl.GL_LINE_STIPPLE) gl.glColor3f(1, 1, 1) gl.glBegin(gl.GL_LINE_LOOP) for i in range(0, 5): gl.glVertex3f(f(2*np.pi*i/5, d)[0], f(2*np.pi*i/5, d)[1], 0) gl.glEnd() gl.glBegin(gl.GL_POINTS) gl.glVertex3f(0, 0, 0) gl.glEnd() gl.glDisable(gl.GL_POINT_SMOOTH) gl.glBegin(gl.GL_POINTS) for i in range(0, 5): gl.glVertex3f(f(2*np.pi*i/5, d)[0], f(2*np.pi*i/5, d)[1], 0) gl.glEnd() graphics.draw(3, gl.GL_TRIANGLES, ('v2f', ( f((2*np.pi*1/3)+ np.pi/2, d/3)[0], f((2*np.pi*1/3)+ np.pi/2, d/3)[1], f((2*np.pi*2/3)+ np.pi/2, d/3)[0], f((2*np.pi*2/3)+ np.pi/2, d/3)[1], f((2*np.pi*3/3)+ np.pi/2, d/3)[0], f((2*np.pi*3/3)+ np.pi/2, d/3)[1] )), ('c3f', ( 1, 0, 0, 0, 1, 0, 0, 0, 1 )))
def enable(self): gl.glEnable(gl.GL_LINE_STIPPLE) gl.glLineStipple(1, self.style)
def enable(self): """Apply line style""" gl.glEnable(gl.GL_LINE_STIPPLE) gl.glLineStipple(1, self.style)
def _set_dashed_lines(self): """Sets OpenGL to draw dashed lines.""" glLineStipple(1, 0x00FF) glEnable(GL_LINE_STIPPLE)