def draw_bounding_box(self, x, y, screen_height): bb = self.get_bounding_box() bb = [bb['min_x'], bb['min_y'], bb['max_x'], bb['max_y']] vertices = () for _ in bb: vertices += (_.x,) vertices += (screen_height - _.y,) # get opengl vertices of type GLfloat vertices_gl = (GLfloat * len(vertices))(*vertices) # set the color glColor4ub(0, 255, 0, 255); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); # turn on blend for alpha channel glEnable(GL_BLEND) # tell open GL were passing a vertex array glEnableClientState(GL_VERTEX_ARRAY) # create a pointer to vertices_gl glVertexPointer(2, GL_FLOAT, 0, vertices_gl) # draw the array glDrawArrays(GL_POLYGON, 0, len(vertices) // 2) glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
def on_draw(self): self.parent.set_caption(str(pyglet.clock.get_fps())) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glColor4ub(*[255,255,255,255]) self.room.bg.blit(0,0) self.room.render() gl.glColor4ub(255,255,255,255) self.player.draw() self.room.lightbatch.draw() self.player.draw_eye() self.player.draw_integrity() if self.pause: gl.glColor4ub(50,50,50,150) left = self.message['text'].x-self.message['text'].width/2 -5 down = self.message['text'].y-self.message['text'].height/2 -5 right = self.message['text'].x+self.message['text'].width/2 + 5 up = self.message['text'].y+self.message['text'].height/2 + 5 gl.glRecti(left,down,right,up) gl.glLineWidth(2) gl.glColor4ub(200,200,200,200) gl.glBegin(gl.GL_LINE_LOOP) gl.glVertex2i(left,down) gl.glVertex2i(left,up) gl.glVertex2i(right,up) gl.glVertex2i(right,down) gl.glEnd() gl.glLineWidth(1) gl.glColor4ub(255,255,255,255) self.message['text'].draw() self.message['helper'].draw() self.message['sprite'].draw()
def on_draw(self): """ Render the screen. """ start = time.time() float_size = ctypes.sizeof(ctypes.c_float) record_len = 10 * float_size GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glEnableClientState(GL.GL_VERTEX_ARRAY) GL.glColor4ub(255, 0, 0, 255) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.rect_vbo.vbo_id) GL.glVertexPointer(2, GL.GL_FLOAT, record_len, 0) for i in range(len(self.shape_list)): shape = self.shape_list[i] GL.glLoadIdentity() GL.glTranslatef(shape.x, shape.y, 0) GL.glDrawArrays(GL.GL_QUADS, i * 8, 8) # GL.glDrawArrays(GL.GL_QUADS, # 0, # self.rect_vbo.size) elapsed = time.time() - start print(elapsed)
def draw_button(self, x, y, point_down, over): if over and self.pressed: border = SCROLL_BAR_PRESSED elif over: border = SCROLL_BAR_OVER else: border = SCROLL_BAR_BORDER draw_rectangle(x, y, x + self.width, y + self.buttonHeight, border) draw_rectangle(x + 1, y + 1, x + self.width - 1, y + self.buttonHeight - 1, SCROLL_BAR_BUTTON) glBegin(GL_TRIANGLES) glColor4ub(*SCROLL_BAR_POINTER) singleX = self.width / 3.0 upperX = self.width / 2.0 singleY = self.buttonHeight / 3.0 if point_down: y -= 1 glVertex2f(singleX + x, singleY * 2 + y) glVertex2f(upperX + x, singleY + y) glVertex2f(singleX * 2 + x, singleY * 2 + y) else: glVertex2f(singleX + x, singleY + y) glVertex2f(upperX + x, singleY * 2 + y) glVertex2f(singleX * 2 + x, singleY + y) glEnd()
def draw_rectangle(x1, y1, x2, y2, r, g, b): gl.glColor4ub(r, g, b, 255) gl.glBegin(gl.GL_QUADS) gl.glVertex2f(x1, y1) gl.glVertex2f(x2, y1) gl.glVertex2f(x2, y2) gl.glVertex2f(x1, y2) gl.glEnd()
def draw(self): gl.glPushMatrix() self.transform() gl.glBegin(gl.GL_QUADS) gl.glColor4ub(*self.color4) for v in self.vertexes: gl.glVertex3i(*v) gl.glEnd() gl.glPopMatrix()
def draw_rectangle_outline(center_x, center_y, width, height, color, border_width=1, tilt_angle=0): """ Draw a rectangle outline. Args: :x: x coordinate of top left rectangle point. :y: y coordinate of top left rectangle point. :width: width of the rectangle. :height: height of the rectangle. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :border_width: width of the lines, in pixels. :angle: rotation of the rectangle. Defaults to zero. Returns: None Raises: None Example: >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> arcade.draw_rectangle_outline(278, 150, 45, 105, \ arcade.color.BRITISH_RACING_GREEN, 2) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) GL.glLoadIdentity() GL.glTranslatef(center_x, center_y, 0) if tilt_angle: GL.glRotatef(tilt_angle, 0, 0, 1) # Set line width GL.glLineWidth(border_width) # Set color if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_LINE_LOOP) GL.glVertex3f(-width // 2, -height // 2, 0.5) GL.glVertex3f(width // 2, -height // 2, 0.5) GL.glVertex3f(width // 2, height // 2, 0.5) GL.glVertex3f(-width // 2, height // 2, 0.5) GL.glEnd()
def draw_bone(self, bone): p1 = bone.get_start() p2 = bone.get_end() gl.glColor4ub(*self.color) gl.glLineWidth(5) gl.glBegin(gl.GL_LINES) gl.glVertex2f(*p1) gl.glVertex2f(*p2) gl.glEnd()
def draw_rectangle(x1, y1, x2, y2, color): if color is None: return glColor4ub(*(color + (255, ))) glBegin(GL_QUADS) glVertex2f(x1, y1) glVertex2f(x2, y1) glVertex2f(x2, y2) glVertex2f(x1, y2) glEnd()
def draw_rectangle(x1, y1, x2, y2, color): if color is None: return glColor4ub(*(color + (255,))) glBegin(GL_QUADS) glVertex2f(x1, y1) glVertex2f(x2, y1) glVertex2f(x2, y2) glVertex2f(x1, y2) glEnd()
def draw_lines(point_list, color, border_width=1): """ Draw a set of lines. Draw a line between each pair of points specified. Args: :point_list: List of points making up the lines. Each point is in a list. So it is a list of lists. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :border_width: Width of the line in pixels. Returns: None Raises: None Example: >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> point_list = ((390, 450), \ (450, 450), \ (390, 480), \ (450, 480), \ (390, 510), \ (450, 510)) >>> arcade.draw_lines(point_list, arcade.color.BLUE, 3) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) GL.glLoadIdentity() # Set line width GL.glLineWidth(border_width) # Set color if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_LINES) for point in point_list: GL.glVertex3f(point[0], point[1], 0.5) GL.glEnd()
def draw_scores(self): """ Draws the scoreboard """ gl.glBegin(gl.GL_QUADS) gl.glColor4ub(*[0,0,0,180]) gl.glVertex2f(0,0) gl.glVertex2f(0,self.win.height) gl.glVertex2f(self.win.width,self.win.height) gl.glVertex2f(self.win.width,0) gl.glEnd() self.scores.draw()
def draw_scores(self): """ Draws the scoreboard """ gl.glBegin(gl.GL_QUADS) gl.glColor4ub(*[0, 0, 0, 180]) gl.glVertex2f(0, 0) gl.glVertex2f(0, self.win.height) gl.glVertex2f(self.win.width, self.win.height) gl.glVertex2f(self.win.width, 0) gl.glEnd() self.scores.draw()
def draw(self): gl.glPushMatrix() self.transform() gl.glBegin(gl.GL_QUADS) gl.glColor4ub(*(255, 255, 255, 255)) for v in self.vertexes_out: gl.glVertex3i(*v) gl.glColor4ub(*(0, 150, 0, 255)) for v in self.vertexes_in: gl.glVertex3i(*v) gl.glEnd() gl.glPopMatrix()
def render_rect_filled(shape, x, y): """ Render the shape at the right spot. """ # Set color GL.glDisable(GL.GL_BLEND) GL.glColor4ub(shape.color[0], shape.color[1], shape.color[2], 255) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, shape.vbo_id) GL.glVertexPointer(2, GL.GL_FLOAT, 0, 0) GL.glLoadIdentity() GL.glTranslatef(x + shape.width / 2, y + shape.height / 2, 0) GL.glDrawArrays(GL.GL_QUADS, 0, shape.size)
def draw_line(start_x, start_y, end_x, end_y, color, border_width=1): """ Draw a line. Args: :start_x: x position of line starting point. :start_y: y position of line starting point. :end_x: x position of line ending point. :end_y: y position of line ending point. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :border_width: Width of the line in pixels. Returns: None Raises: None Example: >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> arcade.draw_line(270, 495, 300, 450, arcade.color.WOOD_BROWN, 3) >>> color = (127, 0, 127, 127) >>> arcade.draw_line(280, 495, 320, 450, color, 3) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) GL.glLoadIdentity() # Set line width GL.glLineWidth(border_width) # Set color if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_LINES) GL.glVertex3f(start_x, start_y, 0.5) GL.glVertex3f(end_x, end_y, 0.5) GL.glEnd()
def draw(self): """ Draws all of the tiles and tray """ gl.glPushMatrix() gl.glTranslated(self.rect.x, self.rect.y, 0) for y in range(self.height): for x in range(self.width): gl.glBegin(gl.GL_QUADS) gl.glColor3ub(*[30 + ((x + y) % 2) * 50] * 3) gl.glVertex2f(x * TILE_SIZE * self.scale, y * TILE_SIZE * self.scale) gl.glVertex2f((x + 1) * TILE_SIZE * self.scale, y * TILE_SIZE * self.scale) gl.glVertex2f((x + 1) * TILE_SIZE * self.scale, (y + 1) * TILE_SIZE * self.scale) gl.glVertex2f(x * TILE_SIZE * self.scale, (y + 1) * TILE_SIZE * self.scale) gl.glEnd() for y in range(self.height): for x in range(self.width): if self(x, y): self(x, y).draw((x + 0.5) * TILE_SIZE * self.scale, (y + 0.5) * TILE_SIZE * self.scale, self.scale) if self(x, y).highlighted: gl.glBegin(gl.GL_QUADS) gl.glColor4ub(*[255, 0, 0, 180]) gl.glVertex2f(x * TILE_SIZE * self.scale, y * TILE_SIZE * self.scale) gl.glVertex2f((x + 1) * TILE_SIZE * self.scale, y * TILE_SIZE * self.scale) gl.glVertex2f((x + 1) * TILE_SIZE * self.scale, (y + 1) * TILE_SIZE * self.scale) gl.glVertex2f(x * TILE_SIZE * self.scale, (y + 1) * TILE_SIZE * self.scale) gl.glEnd() row = 0 col = 0 for tile in self.tray: if col == self.tray_cols: col = 0 row += 1 x = self.tray_start_x + ((col + 0.5) * self.tray_cols_width) y = self.rect.height - ((row + 0.5) * self.tray_cols_width) tile.draw(x, y, TRAY_SCALE * self.scale * 9 / 10) col += 1 gl.glPopMatrix() if self.dragging: self.dragging.draw(self.dragging.x, self.dragging.y, self.scale * DRAG_SCALE)
def draw_polygon_outline(point_list, color, border_width=1): """ Draw a polygon outline. Also known as a "line loop." Args: :point_list: List of points making up the lines. Each point is in a list. So it is a list of lists. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :border_width: Width of the line in pixels. Returns: None Raises: None >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> point_list = ((30, 240), \ (45, 240), \ (60, 255), \ (60, 285), \ (45, 300), \ (30, 300)) >>> arcade.draw_polygon_outline(point_list, arcade.color.SPANISH_VIOLET, 3) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) # Set line width GL.glLineWidth(border_width) GL.glLoadIdentity() # Set color if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_LINE_LOOP) for point in point_list: GL.glVertex3f(point[0], point[1], 0.5) GL.glEnd()
def draw(self): p = self.pos w = self.get_width() p += v(-1, 0) * w * self.anchor gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) col = self.color + (self.alpha,) gl.glColor4ub(*col) for d in self.get_digits(): img = self.images[d] img.blit(*p) p += v(1, 0) * img.width gl.glColor4f(1, 1, 1, 1)
def draw_rectangle_filled(center_x, center_y, width, height, color, tilt_angle=0): """ Draw a filled-in rectangle. Args: :x: x coordinate of top left rectangle point. :y: y coordinate of top left rectangle point. :width: width of the rectangle. :height: height of the rectangle. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :angle: rotation of the rectangle. Defaults to zero. Example: >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> arcade.draw_rectangle_filled(390, 150, 45, 105, arcade.color.BLUSH) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) # Set color if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glLoadIdentity() GL.glTranslatef(center_x, center_y, 0) if tilt_angle: GL.glRotatef(tilt_angle, 0, 0, 1) GL.glBegin(GL.GL_QUADS) GL.glVertex3f(-width // 2, -height // 2, 0.5) GL.glVertex3f(width // 2, -height // 2, 0.5) GL.glVertex3f(width // 2, height // 2, 0.5) GL.glVertex3f(-width // 2, height // 2, 0.5) GL.glEnd()
def draw(self): """ Draw everything in the list. """ # gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glLoadIdentity() gl.glTranslatef(self.center_x, self.center_y, 0) if self.angle: gl.glRotatef(self.angle, 0, 0, 1) last_color = None last_line_width = None gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST) for shape in self.shape_list: if shape.vbo_color_id is not None: gl.glEnableClientState(gl.GL_COLOR_ARRAY) else: gl.glDisableClientState(gl.GL_COLOR_ARRAY) if last_color is None or last_color != shape.color: last_color = shape.color if len(shape.color) == 4: gl.glColor4ub(shape.color[0], shape.color[1], shape.color[2], shape.color[3]) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) elif len(shape.color) == 3: gl.glDisable(gl.GL_BLEND) gl.glColor4ub(shape.color[0], shape.color[1], shape.color[2], 255) if shape.line_width and last_line_width != shape.line_width: last_line_width = shape.line_width gl.glLineWidth(shape.line_width) if shape.vbo_color_id is None: stripped_render(shape) else: stripped_render_with_colors(shape)
def draw_polygon_filled(point_list, color): """ Draw a polygon that is filled in. Args: :point_list: List of points making up the lines. Each point is in a list. So it is a list of lists. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. Returns: None Raises: None >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> point_list = ((150, 240), \ (165, 240), \ (180, 255), \ (180, 285), \ (165, 300), \ (150, 300)) >>> arcade.draw_polygon_filled(point_list, arcade.color.SPANISH_VIOLET) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) GL.glLoadIdentity() # Set color if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_POLYGON) for point in point_list: GL.glVertex3f(point[0], point[1], 0.5) GL.glEnd()
def draw_points(point_list, color, size): """ Draw a set of points. Args: :point_list: List of points Each point is in a list. So it is a list of lists. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :size: Size of the point in pixels. Returns: None Raises: None Example: >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> point_list = ((165, 495), \ (165, 480), \ (165, 465), \ (195, 495), \ (195, 480), \ (195, 465)) >>> arcade.draw_points(point_list, arcade.color.ZAFFRE, 10) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glLoadIdentity() GL.glPointSize(size) if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_POINTS) for point in point_list: GL.glVertex3f(point[0], point[1], 0.5) GL.glEnd()
def blit_image(self, matrix, position, scale, image): x, y = image.width * scale, image.height * scale # dx = self.x + position[0] # dy = self.y + position[1] dx, dy = position gl.glEnable(image.target) gl.glBindTexture(image.target, image.id) gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) # blit img points = [ (-dx, -dy), (x - dx, -dy), (x - dx, y - dy), (-dx, y - dy) ] a, b, _, c, d, _, e, f, _, g, h, _ = image.texture.tex_coords textures = [a, b, c, d, e, f, g, h] np = [matrix * euclid.Point2(*p) for p in points] gl.glColor4ub(255, 255, 255, self.alpha) gl.glBegin(gl.GL_QUADS) gl.glTexCoord2f(a, b) gl.glVertex2f(*np[0]) gl.glTexCoord2f(c, d) gl.glVertex2f(*np[1]) gl.glTexCoord2f(e, f) gl.glVertex2f(*np[2]) gl.glTexCoord2f(g, h) gl.glVertex2f(*np[3]) gl.glEnd() gl.glColor4ub(255, 255, 255, 255) # pyglet.graphics.draw(4, GL_QUADS, # ("v2f", new_points), # ("t2f", textures), # ("c4B", [255, 255, 255, self.alpha] * 4), # ) gl.glPopAttrib() gl.glDisable(image.target)
def draw(self, offset_x, offset_y, screen_height): vertices = self.get_screen_relative_vertices(offset_x, offset_y, screen_height) # get opengl vertices of type GLfloat vertices_gl = (GLfloat * len(vertices))(*vertices) # set the color glColor4ub(*self.color); # turn on blend for alpha channel glEnable(GL_BLEND) # tell open GL were passing a vertex array glEnableClientState(GL_VERTEX_ARRAY) # create a pointer to vertices_gl glVertexPointer(2, GL_FLOAT, 0, vertices_gl) # draw the array glDrawArrays(GL_POLYGON, 0, len(vertices) // 2)
def on_draw(self): """ Render the screen. """ # This command has to happen before we start drawing gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glLoadIdentity() gl.glTranslatef(self.center_x, self.center_y, 0) for shape in self.shape_list: gl.glVertexPointer(2, gl.GL_FLOAT, 0, 0) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, shape.vbo_id) gl.glDrawArrays(gl.GL_QUADS, 0, shape.size) gl.glColor4ub(shape.color[0], shape.color[1], shape.color[2], 255)
def draw(self): """ Draws all of the tiles and tray """ gl.glPushMatrix() gl.glTranslated(self.rect.x,self.rect.y,0) for y in range(self.height): for x in range(self.width): gl.glBegin(gl.GL_QUADS) gl.glColor3ub(*[30+((x+y)%2)*50]*3) gl.glVertex2f(x*TILE_SIZE*self.scale,y*TILE_SIZE*self.scale) gl.glVertex2f((x+1)*TILE_SIZE*self.scale,y*TILE_SIZE*self.scale) gl.glVertex2f((x+1)*TILE_SIZE*self.scale,(y+1)*TILE_SIZE*self.scale) gl.glVertex2f(x*TILE_SIZE*self.scale,(y+1)*TILE_SIZE*self.scale) gl.glEnd() for y in range(self.height): for x in range(self.width): if self(x,y): self(x,y).draw((x+0.5)*TILE_SIZE*self.scale,(y+0.5)*TILE_SIZE*self.scale,self.scale) if self(x,y).highlighted: gl.glBegin(gl.GL_QUADS) gl.glColor4ub(*[255,0,0,180]) gl.glVertex2f(x*TILE_SIZE*self.scale,y*TILE_SIZE*self.scale) gl.glVertex2f((x+1)*TILE_SIZE*self.scale,y*TILE_SIZE*self.scale) gl.glVertex2f((x+1)*TILE_SIZE*self.scale,(y+1)*TILE_SIZE*self.scale) gl.glVertex2f(x*TILE_SIZE*self.scale,(y+1)*TILE_SIZE*self.scale) gl.glEnd() row = 0 col = 0 for tile in self.tray: if col == self.tray_cols: col = 0 row += 1 x = self.tray_start_x + ((col+0.5)*self.tray_cols_width) y = self.rect.height - ((row+0.5)*self.tray_cols_width) tile.draw(x,y,TRAY_SCALE*self.scale*9/10) col += 1 gl.glPopMatrix() if self.dragging: self.dragging.draw(self.dragging.x,self.dragging.y,self.scale*DRAG_SCALE)
def draw_point(x, y, color, size): """ Draw a point. Args: :x: x position of point. :y: y position of point. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :size: Size of the point in pixels. Returns: None Raises: None Example: >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> arcade.draw_point(60, 495, arcade.color.RED, 10) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glLoadIdentity() GL.glPointSize(size) if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_POINTS) GL.glVertex3f(x, y, 0.5) GL.glEnd()
def render_rectangle_filled(shape, center_x, center_y, color, tilt_angle=0): """ Render a rectangle previously created by the ``create_rectangle`` command. """ # Set color if len(color) == 4: GL.glColor4ub(shape.color[0], shape.color[1], shape.color[2], shape.color[3]) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) elif len(color) == 3: GL.glDisable(GL.GL_BLEND) GL.glColor4ub(shape.color[0], shape.color[1], shape.color[2], 255) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, shape.vbo_id) GL.glVertexPointer(2, GL.GL_FLOAT, 0, 0) GL.glLoadIdentity() GL.glTranslatef(center_x + shape.width / 2, center_y + shape.height / 2, 0) if tilt_angle != 0: GL.glRotatef(tilt_angle, 0, 0, 1) GL.glDrawArrays(GL.GL_QUADS, 0, shape.size)
def render_ellipse_filled(shape, center_x, center_y, color, angle=0): """ Render an ellipse previously created with the ``create_ellipse`` function. """ # Set color if len(color) == 4: GL.glColor4ub(shape.color[0], shape.color[1], shape.color[2], shape.color[3]) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) elif len(color) == 3: GL.glDisable(GL.GL_BLEND) GL.glColor4ub(shape.color[0], shape.color[1], shape.color[2], 255) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, shape.vbo_id) GL.glVertexPointer(2, GL.GL_FLOAT, 0, 0) GL.glLoadIdentity() GL.glTranslatef(center_x, center_y, 0) if angle: GL.glRotatef(angle, 0, 0, 1) GL.glDrawArrays(GL.GL_TRIANGLE_FAN, 0, shape.size)
def draw(self): if self.updateDraw: self.updateDraw = False current = self.height - self.borderPad for item in self.lines: line = item.get_label() line.y = current current -= line.height self.update_scrollbar() glDisable(GL_TEXTURE_2D) glPushMatrix() glTranslatef(self.x, self.y - self.height, 0) # border if self.border: if self.border3d: draw_rectangle(0, 0, self.width, self.height, BORDER_COLOR_3D_1) draw_rectangle(1, 1, self.width - 1, self.height - 1, BORDER_COLOR_3D_2) draw_rectangle(2, 2, self.width - 2, self.height - 2, BORDER_COLOR_3D_3) else: draw_rectangle(0, 0, self.width, self.height, BORDER_COLOR) # background pad = self.borderPad glColor4ub(*(self.backColor + (255, ))) glBegin(GL_QUADS) glVertex2f(pad, pad) glVertex2f(self.width - pad, pad) glVertex2f(self.width - pad, self.height - pad) glVertex2f(pad, self.height - pad) glEnd() glPushAttrib(GL_SCISSOR_BIT) x, y, width, height = self.player.get_scissor_box( self.x + self.borderPad, self.y - self.height + self.borderPad, self.listWidth, self.height - self.borderPad * 2) glScissor(x, y, width, height) glEnable(GL_SCISSOR_TEST) glTranslatef(0, self.yOffset, 0) for index, item in enumerate(self.lines): line = item.get_label() color = None if self.selected == index: color = (139, 190, 228) elif self.over == index: color = (191, 219, 240) if color is not None: draw_rectangle(pad, line.y - line.height, self.listWidth + self.borderPad, line.y, color) line.draw() glPopAttrib() glPopMatrix() if self.scrollBar is not None: self.scrollBar.draw()
def set_state(self): super().set_state() if not self.color_is_disabled(): gl.glColor4ub(*get_color(self.color))
def set_state(self): gl.glPushAttrib(gl.GL_CURRENT_BIT | gl.GL_LINE_BIT) gl.glColor4ub(*self.color) gl.glLineWidth(self.stroke_width)
def draw_ellipse_outline(center_x, center_y, width, height, color, border_width=1, tilt_angle=0): """ Draw the outline of an ellipse. Args: :center_x: x position that is the center of the circle. :center_y: y position that is the center of the circle. :height: height of the ellipse. :width: width of the ellipse. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :border_width: Width of the circle outline in pixels. :tilt_angle: Angle in degrees to tilt the ellipse. Returns: None Raises: None Example: >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> arcade.draw_ellipse_outline(540, 273, 15, 36, arcade.color.AMBER, 3) >>> color = (127, 0, 127, 127) >>> arcade.draw_ellipse_outline(540, 336, 15, 36, color, 3, 45) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ num_segments = 128 GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) GL.glLoadIdentity() GL.glTranslatef(center_x, center_y, 0) GL.glRotatef(tilt_angle, 0, 0, 1) GL.glLineWidth(border_width) # Set color if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_LINE_LOOP) for i in range(num_segments): theta = 2.0 * 3.1415926 * i / num_segments x = width * math.cos(theta) y = height * math.sin(theta) GL.glVertex3f(x, y, 0.5) GL.glEnd() GL.glLoadIdentity()
def draw( self ): glColor4ub(255, 255, 255, 255) glPushMatrix() self.transform() self.img.blit(0,0) glPopMatrix()
def draw_line_strip(point_list, color, border_width=1): """ Draw a line strip. A line strip is a set of continuously connected line segments. Args: :point_list: List of points making up the line. Each point is in a list. So it is a list of lists. :color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :border_width: Width of the line in pixels. Returns: None Raises: None Example: >>> import arcade >>> arcade.open_window("Drawing Example", 800, 600) >>> arcade.set_background_color(arcade.color.WHITE) >>> arcade.start_render() >>> point_list = ((510, 450), \ (570, 450), \ (510, 480), \ (570, 480), \ (510, 510), \ (570, 510)) >>> arcade.draw_line_strip(point_list, arcade.color.TROPICAL_RAIN_FOREST, \ 3) >>> color = (127, 0, 127, 127) >>> point_list = ((510, 455), \ (570, 455), \ (510, 485), \ (570, 485), \ (510, 515), \ (570, 515)) >>> arcade.draw_line_strip(point_list, color, 3) >>> arcade.finish_render() >>> arcade.quick_run(0.25) """ GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) # Set line width GL.glLineWidth(border_width) GL.glLoadIdentity() # Set color if len(color) == 4: GL.glColor4ub(color[0], color[1], color[2], color[3]) elif len(color) == 3: GL.glColor4ub(color[0], color[1], color[2], 255) GL.glBegin(GL.GL_LINE_STRIP) for point in point_list: GL.glVertex3f(point[0], point[1], 0.5) GL.glEnd()