def __rect(x, y, width, height, color, fill=False): """ Draws a rectangle :param x: the x coordinate of the lower-left corner of the rectangle :param y: the y coordinate of the lower-left corner of the rectangle :param width: the width of the rectangle :param height: the height of the rectangle :param color: RGB color of the rectangle [R,G,B] scaled between [0,1] :param fill: whether to fill the rectangle or just stroke it :return: None """ # Set the color in the OpenGL Context (State) gl.glColor3f(color[0], color[1], color[2]) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) # Configure rectangle (fill or not) if fill: # Delimits the vertices of a primitive or group of primitives gl.glBegin(gl.GL_POLYGON) else: # Delimits the vertices of a primitive or group of primitives gl.glBegin(gl.GL_LINES) # Draw the vertices of the rectangle __rect_vertices(x, y, width, height) # Delimits the vertices of a primitive or group of primitives gl.glEnd()
def drawBody(self, body): # type: (Dict[str, Any]) -> None """Draw a body""" pos = body['position'] rpy = body['rotation'] r, p, y = rpy[0], rpy[1], rpy[2] gl.glPushMatrix() gl.glTranslatef(pos[0], pos[1], pos[2]) gl.glRotatef(np.rad2deg(y), 0.0, 0.0, 1.0) gl.glRotatef(np.rad2deg(p), 0.0, 1.0, 0.0) gl.glRotatef(np.rad2deg(r), 1.0, 0.0, 0.0) self.drawCoords() rel_pos = body['center'] gl.glTranslatef(rel_pos[0], rel_pos[1], rel_pos[2]) transparent = 'transparent' in body and body['transparent'] dim = body['size3'] gl.glScalef(dim[0], dim[1], dim[2]) self.setMaterial(body['material']) if body['geometry'] is 'box': if transparent: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) # Wireframe self.drawCube() if transparent: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) elif body['geometry'] is 'mesh': self.drawMesh(body['name']) gl.glPopMatrix()
def on_draw(): # clears the background with the background color gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # wire-frame mode gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) data_points.draw() # gl.glPointSize(10) # pyglet.graphics.draw(len(data_points), gl.GL_POINTS, #v3f/stream c4B/static # ('v3f', data_points.reshape(-1)), # ('c4B', data_points_color.reshape(-1))) # gl.glPointSize(1) # gl.glBegin(gl.GL_POINTS) gl.glBegin(gl.GL_LINES) gl.glColor4fv((gl.GLfloat * 4)(1, 0, 0, 1)) gl.glVertex3f(10.0, 10.0, 20) gl.glVertex3f(0.0, 0.0, 20) gl.glEnd() surface.draw('b') surface1.draw('g')
def drawRect(self, mode=0, color1=0, color2=0, color3=0, color4=0): if color1 == 0: color1 = PyColor(0, 0, 0) if color2 == 0: color2 = PyColor(0, 0, 0) if color3 == 0: color3 = PyColor(0, 0, 0) if color4 == 0: color4 = PyColor(0, 0, 0) if mode != 0: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) else: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) # self.batch.add(4, graphics.GL_QUADS, # ('v2i', (self.p1.x, self.p1.y, # self.p1.x + self.w, self.p1.y, # self.p1.x + self.w, self.p1.y + self.h, # self.p1.x, self.p1.y + self.h)), # ('c3B', (color1.r, color1.g, color1.b, # color2.r, color2.g, color2.b, # color3.r, color3.g, color3.b, # color4.r, color4.g, color4.b))) self.batch.add(4, gl.GL_QUADS, None, ('v2i', [self.p1.x, self.p1.y, self.p1.x + self.w, self.p1.y, self.p1.x + self.w, self.p1.y + self.h, self.p1.x, self.p1.y + self.h]), ('c4B', [color1.r, color1.g, color1.b, 255] * 4))
def _draw_wireframe_display_list(self, dl): pgl.glPushAttrib(pgl.GL_ENABLE_BIT | pgl.GL_POLYGON_BIT) pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_LINE) pgl.glEnable(pgl.GL_POLYGON_OFFSET_LINE) pgl.glPolygonOffset(-0.005, -50.0) pgl.glCallList(dl) pgl.glPopAttrib()
def drawFocusedBlock(self): block = self.game.world.hitTest(self.game.player.position, self.game.player.sightVector())[0] if block and self.game.world[block] != self.game.textures.edge: x, y, z, = block glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) draw(24, GL_QUADS, ('v3f/static', cube_vertices(x, y, z, 0.5),), ('c3B/static', (0, 0, 0,) * 24,)) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
def update_flags(self): """ Check the view flags and call what is needed with gl to handle it correctly. """ # view mode, filled vs wirefrom if self.view['wireframe']: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) else: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) # backface culling on or off if self.view['cull']: gl.glEnable(gl.GL_CULL_FACE) else: gl.glDisable(gl.GL_CULL_FACE) # case where we WANT an axis and NO vertexlist # is stored internally if self.view['axis'] and self._axis is None: from .. import creation # create an axis marker sized relative to the scene axis = creation.axis(origin_size=self.scene.scale / 100) # create ordered args for a vertex list args = rendering.mesh_to_vertexlist(axis) # store the axis as a reference self._axis = self.batch.add_indexed(*args) # case where we DON'T want an axis but a vertexlist # IS stored internally elif not self.view['axis'] and self._axis is not None: # remove the axis from the rendering batch self._axis.delete() # set the reference to None self._axis = None
def on_key_press(symbol, modifiers): mode_f = mode_b = None shade_model = None if symbol == key._1: gl.glEnable(gl.GL_LINE_STIPPLE) elif symbol == key._2: gl.glDisable(gl.GL_LINE_STIPPLE) elif symbol == key._3: mode_f = mode_b = gl.GL_FILL shade_model = gl.GL_FLAT elif symbol == key._4: mode_f = gl.GL_POINT mode_b = gl.GL_LINE shade_model = gl.GL_SMOOTH elif symbol == key._5: gl.glEnable(gl.GL_POINT_SMOOTH) elif symbol == key._6: gl.glDisable(gl.GL_POINT_SMOOTH) elif symbol == key._7: mode_f = mode_b = gl.GL_FILL shade_model = gl.GL_SMOOTH if mode_f is not None: gl.glPolygonMode(gl.GL_FRONT, mode_f) gl.glPolygonMode(gl.GL_BACK, mode_b) gl.glShadeModel(shade_model)
def drawnvc( self, normals, points, colors, idxs ): '''draw tri mesh using glDrawElements using input normals points colors and indexes''' n = 1 for dim in idxs.shape: n *= dim iptr = vecutil.numpy2pointer(idxs) nptr = vecutil.numpy2pointer(normals) vptr = vecutil.numpy2pointer(points) cptr = vecutil.numpy2pointer(colors) mode = self.ui.fillmodes[self.ui.fillmode] gl.glPolygonMode( gl.GL_FRONT, mode ) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glEnableClientState(gl.GL_NORMAL_ARRAY) gl.glEnableClientState(gl.GL_COLOR_ARRAY) gl.glVertexPointer(3, gl.GL_FLOAT, 0, vptr) gl.glNormalPointer( gl.GL_FLOAT, 0, nptr) gl.glColorPointer(3, gl.GL_FLOAT, 0, cptr) gl.glDrawElements(gl.gl.GL_TRIANGLES, n, gl.GL_UNSIGNED_INT, iptr) gl.glDisableClientState(gl.GL_VERTEX_ARRAY) gl.glDisableClientState(gl.GL_NORMAL_ARRAY) gl.glDisableClientState(gl.GL_COLOR_ARRAY) gl.glPolygonMode( gl.GL_FRONT, gl.GL_FILL )
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 update_flags(self): """ Check the view flags, and call required GL functions. """ # view mode, filled vs wirefrom if self.view['wireframe']: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) else: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) # set fullscreen or windowed self.set_fullscreen(fullscreen=self.view['fullscreen']) # backface culling on or off if self.view['cull']: gl.glEnable(gl.GL_CULL_FACE) else: gl.glDisable(gl.GL_CULL_FACE) # case where we WANT an axis and NO vertexlist # is stored internally if self.view['axis'] and self._axis is None: from .. import creation # create an axis marker sized relative to the scene axis = creation.axis(origin_size=self.scene.scale / 100) # create ordered args for a vertex list args = rendering.mesh_to_vertexlist(axis) # store the axis as a reference self._axis = self.batch.add_indexed(*args) # case where we DON'T want an axis but a vertexlist # IS stored internally elif not self.view['axis'] and self._axis is not None: # remove the axis from the rendering batch self._axis.delete() # set the reference to None self._axis = None if self.view['grid'] and self._grid is None: try: # create a grid marker from ..path.creation import grid bounds = self.scene.bounds center = bounds.mean(axis=0) center[2] = bounds[0][2] side = bounds.ptp(axis=0)[:2].max() # create an axis marker sized relative to the scene grid_mesh = grid( side=side, count=4, transform=translation_matrix(center)) args = rendering.convert_to_vertexlist(grid_mesh) # create ordered args for a vertex list self._grid = self.batch.add_indexed(*args) except BaseException: util.log.warning( 'failed to create grid!', exc_info=True) elif not self.view['grid'] and self._grid is not None: self._grid.delete() self._grid = None
def draw_bboxes(self): gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) vs = [] for a in self.level.get_actors(): if hasattr(a, 'bounds'): vs += a.bounds().vertices() pyglet.graphics.draw(len(vs) // 2, gl.GL_QUADS, ('v2f', vs)) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
def update_flags(self): if self.view['wireframe']: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) else: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) if self.view['cull']: gl.glEnable(gl.GL_CULL_FACE) else: gl.glDisable(gl.GL_CULL_FACE)
def draw_focused_block(self): """Draw black edges around the block that is currently under the crosshairs. """ block = self.player.hit(self.world.area.blocks)[0] if block: x, y, z = block vertex_data = cube_vertices(x, y, z, 0.51) GL.glColor3d(0, 0, 0) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) pyglet.graphics.draw(24, GL.GL_QUADS, ('v3f/static', vertex_data)) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
def draw(self): previous_draw_mode = gl.GLint(0) gl.glGetIntegerv(gl.GL_POLYGON_MODE, byref(previous_draw_mode)) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) self.shader.use() gl.glBindVertexArray(self.array) # gl.glDrawElements(gl.GL_TRIANGLES, self.width * self.height * 6, gl.GL_UNSIGNED_INT, None) gl.glDrawElementsInstanced(gl.GL_TRIANGLES, Chunk.cells * 6, gl.GL_UNSIGNED_INT, None, self.instances) gl.glBindVertexArray(0) self.shader.clear() gl.glPolygonMode(gl.GL_FRONT_AND_BACK, previous_draw_mode.value)
def draw_focused_block(self): """ Draw black edges around the block that is currently under the crosshairs. """ vector = self.get_sight_vector() block = self.model.hit_test(self.position, vector)[0] if block: x, y, z = block vertex_data = cube_vertices(x, y, z, 0.51) gl.glColor3d(0, 0, 0) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) pyglet.graphics.draw(24, gl.GL_QUADS, ('v3f/static', vertex_data)) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
def on_draw(self): glClearColor(0.1, 0.1, 0.1, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) self.projection = pyrr.matrix44.create_perspective_projection( radians(self.camera.zoom), self.width / self.height, 0.1, 1000.0) self.view = self.camera.get_view_matrix() self.shader.set_uniform("projection", self.projection) self.shader.set_uniform("view", self.view) # Draw! glBindVertexArray(self.chunk.vao) # Normally we'd translate before drawing a chunk model = pyrr.Matrix44() self.shader.set_uniform("model", model) glDrawArrays(GL_TRIANGLES, 0, len(self.chunk.vertices) // 3)
def draw(self): gl.glPolygonMode(gl.GL_FRONT_AND_BACK, self.style) gl.glColor4f(*self.color) if self.style == gl.GL_LINE: gl.glBegin(gl.GL_LINE_LOOP) else: gl.glBegin(gl.GL_TRIANGLE_FAN) gl.glVertex2f(self.x, self.y) for i in xrange(16 + 1): angle = float(2 * math.pi * i) / 16 gl.glVertex2f(self.x + math.cos(angle) * self.radius, self.y + math.sin(angle) * self.radius) gl.glEnd() gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
def on_key_press(self, symbol, modifiers): if symbol == pyglet.window.key.F and (modifiers & pyglet.window.key.MOD_ACCEL): director.window.set_fullscreen(not director.window.fullscreen) return True elif symbol == pyglet.window.key.P and (modifiers & pyglet.window.key.MOD_ACCEL): import cocos.scenes.pause as pause pause_sc = pause.get_pause_scene() if pause: director.push(pause_sc) return True elif symbol == pyglet.window.key.W and (modifiers & pyglet.window.key.MOD_ACCEL): # import wired if not self.wired: gl.glDisable(gl.GL_TEXTURE_2D) gl.glPolygonMode(gl.GL_FRONT, gl.GL_LINE) gl.glPolygonMode(gl.GL_BACK, gl.GL_LINE) # wired.wired.install() # wired.wired.uset4F('color', 1.0, 1.0, 1.0, 1.0 ) self.wired = True else: gl.glEnable(gl.GL_TEXTURE_2D) gl.glPolygonMode(gl.GL_FRONT, gl.GL_FILL) gl.glPolygonMode(gl.GL_BACK, gl.GL_FILL) self.wired = False # wired.wired.uninstall() return True elif symbol == pyglet.window.key.X and (modifiers & pyglet.window.key.MOD_ACCEL): director.show_FPS = not director.show_FPS return True elif symbol == pyglet.window.key.I and (modifiers & pyglet.window.key.MOD_ACCEL): from .layer import PythonInterpreterLayer if not director.show_interpreter: if director.python_interpreter is None: director.python_interpreter = cocos.scene.Scene(PythonInterpreterLayer()) director.python_interpreter.enable_handlers(True) director.python_interpreter.on_enter() director.show_interpreter = True else: director.python_interpreter.on_exit() director.show_interpreter = False return True elif symbol == pyglet.window.key.S and (modifiers & pyglet.window.key.MOD_ACCEL): import time pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot-%d.png' % (int(time.time()))) return True if symbol == pyglet.window.key.ESCAPE: director.pop() return True
def draw_focused_block(self): """ Draw black edges around the block that is currently under the crosshairs. """ vector = self.get_sight_vector() block = self.model.hit_test(self.position, vector)[0] if block: x, y, z = block vertex_data=[] for v in util.cube_v([x, y, z], 0.51): vertex_data.extend(v) gl.glLineWidth(3) gl.glColor3d(0, 0, 0) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) pyglet.graphics.draw(24, gl.GL_QUADS, ('v3f/static', vertex_data)) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) gl.glLineWidth(1)
def on_key_press(self, symbol, modifiers): if symbol == pyglet.window.key.F and (modifiers & pyglet.window.key.MOD_ACCEL): director.window.set_fullscreen(not director.window.fullscreen) return True elif symbol == pyglet.window.key.P and (modifiers & pyglet.window.key.MOD_ACCEL): import cocos.scenes.pause as pause pause_sc = pause.get_pause_scene() if pause: director.push(pause_sc) return True elif symbol == pyglet.window.key.W and (modifiers & pyglet.window.key.MOD_ACCEL): # import wired if not self.wired: gl.glDisable(gl.GL_TEXTURE_2D) gl.glPolygonMode(gl.GL_FRONT, gl.GL_LINE) gl.glPolygonMode(gl.GL_BACK, gl.GL_LINE) # wired.wired.install() # wired.wired.uset4F('color', 1.0, 1.0, 1.0, 1.0 ) self.wired = True else: gl.glEnable(gl.GL_TEXTURE_2D) gl.glPolygonMode(gl.GL_FRONT, gl.GL_FILL) gl.glPolygonMode(gl.GL_BACK, gl.GL_FILL) self.wired = False # wired.wired.uninstall() return True elif symbol == pyglet.window.key.X and (modifiers & pyglet.window.key.MOD_ACCEL): director.show_FPS = not director.show_FPS return True elif symbol == pyglet.window.key.I and (modifiers & pyglet.window.key.MOD_ACCEL): from .layer import PythonInterpreterLayer if not director.show_interpreter: if director.python_interpreter is None: director.python_interpreter = cocos.scene.Scene(PythonInterpreterLayer()) director.python_interpreter.on_enter() director.show_interpreter = True else: director.python_interpreter.on_exit() director.show_interpreter = False return True elif symbol == pyglet.window.key.S and (modifiers & pyglet.window.key.MOD_ACCEL): import time pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot-%d.png' % (int(time.time()))) return True if symbol == pyglet.window.key.ESCAPE: director.pop() return True
def draw(self): gl.glPolygonMode( gl.GL_FRONT_AND_BACK, self.style ) gl.glColor4f(*self.color) gl.glPushMatrix() gl.glTranslatef( self.x, self.y, 0 ) gl.glRotatef( - self.angle, 0, 0, 1 ) gl.glBegin(gl.GL_QUADS) gl.glVertex2f( - self.w /2, - self.h /2 ) gl.glVertex2f( - self.w /2, self.h /2 ) gl.glVertex2f( self.w /2, self.h /2 ) gl.glVertex2f( self.w /2, - self.h /2 ) gl.glEnd() gl.glPopMatrix() gl.glPolygonMode( gl.GL_FRONT_AND_BACK, gl.GL_FILL )
def __init__(self, visuals, **args): self.visuals = visuals pyglet.window.Window.__init__(self, **args) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable( gl.GL_VERTEX_ARRAY ) gl.glEnable( gl.GL_LINE_SMOOTH ) gl.glEnable( gl.GL_POLYGON_SMOOTH ) gl.glHint( gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST ) gl.glHint( gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST ) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) self.texture = None
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 on_draw(self): self.clear() xscale = float(self.board_width) / self.columns yscale = float(self.board_height) / self.rows # Draw grid. for y, row in enumerate(self.board): for x, cell in enumerate(row): left = int(x * xscale) top = self.height - int(y * yscale) right = int((x + 1) * xscale) bottom = self.height - int((y + 1) * yscale) r = (left, top, right, top, right, bottom, left, bottom) # Draw a square. gl.glLineWidth(self.EDGE_WIDTH) pyglet.graphics.draw(4, gl.GL_LINE_LOOP, ('v2f', r), ('c4B', self.EDGE_COLOR * 4)) # Draw the things on the square. if cell == common.APPLE: w, h = self.apple.size self.apple.blit(left + (xscale - w) / 2.0, top - h, width=w, height=h) elif cell.isalpha(): # Snake... colour = self.bots[cell.lower()][1] + (255,) gl.glPolygonMode(gl.GL_FRONT, gl.GL_FILL) pyglet.graphics.draw(4, gl.GL_POLYGON, ('v2f', r), ('c4B', colour * 4), ) if cell.isupper(): # Snake head w, h = self.eyes.size self.eyes.blit(left, top - h, width=w, height=h)
def polygon(vertices: List[Vector], theme=Theme()): # batch = pyglet.graphics.Batch() n_vertices = len(vertices) vertices = vectors2vertices(vertices) if theme.fill: gl.glPolygonMode(gl.GL_FRONT, gl.GL_FILL) pyglet.graphics.draw(n_vertices, gl.GL_POLYGON, ('v2f', vertices), ('c4f', n_vertices * theme.fill.normalized)) if theme.stroke: gl.glLineWidth(float(theme.stroke_weight)) gl.glPolygonMode(gl.GL_FRONT, gl.GL_LINE) pyglet.graphics.draw(n_vertices, gl.GL_POLYGON, ('v2f', vertices), ('c4f', n_vertices * theme.stroke.normalized)) gl.glPolygonMode(gl.GL_FRONT, gl.GL_POINT) gl.glPointSize(float(theme.stroke_weight)) pyglet.graphics.draw(n_vertices, gl.GL_POLYGON, ('v2f', vertices), ('c4f', n_vertices * theme.stroke.normalized))
def unset_state(self): gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
def set_state(self): gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
def _draw_solid_display_list(self, dl): pgl.glPushAttrib(pgl.GL_ENABLE_BIT | pgl.GL_POLYGON_BIT) pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL) pgl.glCallList(dl) pgl.glPopAttrib()
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() glTranslatef(0, 0, -self.dist) glMultMatrixd(build_rotmatrix(self.basequat)) # Rotate according to trackball glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.2, 0.2, 0.2, 1)) glTranslatef(- self.build_dimensions[3] - self.platform.width / 2, - self.build_dimensions[4] - self.platform.depth / 2, 0) # Move origin to bottom left of platform # Draw platform glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glDisable(GL_LIGHTING) self.platform.draw() glEnable(GL_LIGHTING) # Draw mouse glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) inter = self.mouse_to_plane(self.mousepos[0], self.mousepos[1], plane_normal = (0, 0, 1), plane_offset = 0, local_transform = False) if inter is not None: glPushMatrix() glTranslatef(inter[0], inter[1], inter[2]) glBegin(GL_TRIANGLES) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(1, 0, 0, 1)) glNormal3f(0, 0, 1) glVertex3f(2, 2, 0) glVertex3f(-2, 2, 0) glVertex3f(-2, -2, 0) glVertex3f(2, -2, 0) glVertex3f(2, 2, 0) glVertex3f(-2, -2, 0) glEnd() glPopMatrix() # Draw objects glDisable(GL_CULL_FACE) glPushMatrix() glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.3, 0.7, 0.5, 1)) for i in self.parent.models: model = self.parent.models[i] glPushMatrix() glTranslatef(*(model.offsets)) glRotatef(model.rot, 0.0, 0.0, 1.0) glTranslatef(*(model.centeroffset)) glScalef(*model.scale) model.batch.draw() glPopMatrix() glPopMatrix() glEnable(GL_CULL_FACE) # Draw cutting plane if self.parent.cutting: # FIXME: make this a proper Actor axis = self.parent.cutting_axis fixed_dist = self.parent.cutting_dist dist, plane_width, plane_height = self.get_cutting_plane(axis, fixed_dist) if dist is not None: glPushMatrix() if axis == "x": glRotatef(90, 0, 1, 0) glRotatef(90, 0, 0, 1) glTranslatef(0, 0, dist) elif axis == "y": glRotatef(90, 1, 0, 0) glTranslatef(0, 0, -dist) elif axis == "z": glTranslatef(0, 0, dist) glDisable(GL_CULL_FACE) glBegin(GL_TRIANGLES) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0, 0.9, 0.15, 0.3)) glNormal3f(0, 0, self.parent.cutting_direction) glVertex3f(plane_width, plane_height, 0) glVertex3f(0, plane_height, 0) glVertex3f(0, 0, 0) glVertex3f(plane_width, 0, 0) glVertex3f(plane_width, plane_height, 0) glVertex3f(0, 0, 0) glEnd() glEnable(GL_CULL_FACE) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glEnable(GL_LINE_SMOOTH) orig_linewidth = (GLfloat)() glGetFloatv(GL_LINE_WIDTH, orig_linewidth) glLineWidth(4.0) glBegin(GL_LINE_LOOP) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0, 0.8, 0.15, 1)) glVertex3f(0, 0, 0) glVertex3f(0, plane_height, 0) glVertex3f(plane_width, plane_height, 0) glVertex3f(plane_width, 0, 0) glEnd() glLineWidth(orig_linewidth) glDisable(GL_LINE_SMOOTH) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) glPopMatrix() glPopMatrix()
def init_gui(): global main_window, sched_queue, current_time, fps_limit config = pyglet.gl.Config( double_buffer=True, buffer_size=32, aux_buffers=0, sample_buffers=0, samples=0, red_size=8, green_size=8, blue_size=8, alpha_size=8, depth_size=0, stencil_size=0, accum_red_size=0, accum_green_size=0, accum_blue_size=0, accum_alpha_size=0, ) from options import options z = options.zoom main_window = pyglet.window.Window( width=int(WINDOW_WIDTH * z), height=int(WINDOW_HEIGHT * z), caption=u'东方符斗祭', config=config, visible=False ) sched_queue = [] from pyglet.gl import gl_info vendor = gl_info.get_vendor().lower() if 'amd' in vendor or 'ati' in vendor: pyglet.options['graphics_vbo'] = False # AMD: Do you have QA team for your OpenGL driver ???? from pyglet.graphics import vertexbuffer assert not vertexbuffer._enable_vbo # custom font renderer from .font import AncientPixFont pyglet.font._font_class = AncientPixFont # main window setup {{ glClearColor(1, 1, 1, 1) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # glEnable(GL_SCISSOR_TEST) glPolygonMode(GL_FRONT, GL_FILL) glPolygonMode(GL_BACK, GL_LINE) def_overlay = Overlay() def_overlay.name = 'Overlay' def_overlay.switch() # }} main window setup fps = pyglet.clock.ClockDisplay() fps_limit = 60 delay = 1. / fps_limit current_time = time() @main_window.event def on_draw(): global current_time current_time = time() Overlay.cur_overlay.draw() fps.draw() @main_window.event def on_close(): # HACK: suppress exceptions, # dont want to explain.... pyglet.clock.tick = lambda a: 0.0 pyglet.app.exit() @hook(main_window) def on_key_press(ori, symbol, modifiers): if symbol == pyglet.window.key.ESCAPE: return pyglet.event.EVENT_HANDLED return ori(symbol, modifiers) def _dispatch_msg(dt): global sched_queue import gevent # give logics a chance to run gevent.sleep(0.001) if not sched_queue: return for func in sched_queue: func() sched_queue = [] pyglet.clock.schedule_interval(_dispatch_msg, delay)
def gl_set_polygon_mode(on): # view mode, filled vs wireframe if on: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) else: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)