def draw(self): # program['Projection'].write(get_projection().tobytes()) with self.vao: gl.glLineWidth(self.line_width) 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.glEnable(gl.GL_PRIMITIVE_RESTART) gl.glPrimitiveRestartIndex(2**32 - 1) self.vao.render(mode=self.mode)
def draw(self): """ Draw this shape. Drawing this way isn't as fast as drawing multiple shapes batched together in a ShapeElementList. """ assert(self.line_width == 1) gl.glLineWidth(self.line_width) 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.glEnable(gl.GL_PRIMITIVE_RESTART) gl.glPrimitiveRestartIndex(2 ** 32 - 1) self.vao.render(self.program, mode=self.mode)
def render(self): self.set_colliding_flag() self.gl_vertices = self.get_gl_vertices() # Without this, number of points in polygon is undefined to pyglet. gl.glEnable(gl.GL_PRIMITIVE_RESTART) gl.glPrimitiveRestartIndex(-1) gl.glEnable(gl.GL_LINE_SMOOTH) vertices = round(len(self.gl_vertices) / 2) gl.glColor4f(*self.color) draw(vertices, gl.GL_POLYGON, ('v2f', self.gl_vertices)) if (self.colliding): gl.glLineWidth(const.BORDER_WIDTH) gl.glColor4f(*const.COLOR_COLLIDING[self.colliding]) draw(vertices - 1, gl.GL_LINE_LOOP, ('v2f', self.gl_vertices[:-2] )) # Exclude last vertex (the primitive restart) gl.glDisable(gl.GL_LINE_SMOOTH)
def primitive_restart_index(self, value: int): self._primitive_restart_index = value gl.glPrimitiveRestartIndex(value)