def level_draw(self, camera): gl.glLoadIdentity() gl.glBegin(gl.GL_TRIANGLES) gl.glColor3f(1.0, 1.0, 1.0) secs = 0 necs = 0 for sector in self.sectors: if camera.inCamera(sector.x, sector.y, sector.w, sector.h): secs += 1 for node in sector.nodes: necs += 1 if node.e4: node2 = node.e4.end if node2.e6: node3 = node2.e6.end gl.glColor3f(*TriNode.color[node.mat]) gl.glVertex2f(node.vx - camera.x, node.vy - camera.y) gl.glColor3f(*TriNode.color[node2.mat]) gl.glVertex2f(node2.vx - camera.x, node2.vy - camera.y) gl.glColor3f(*TriNode.color[node3.mat]) gl.glVertex2f(node3.vx - camera.x, node3.vy - camera.y) if node.e5: node2 = node.e5.end if node2.e3: node3 = node2.e3.start gl.glColor3f(*TriNode.color[node.mat]) gl.glVertex2f(node.vx - camera.x, node.vy - camera.y) gl.glColor3f(*TriNode.color[node2.mat]) gl.glVertex2f(node2.vx - camera.x, node2.vy - camera.y) gl.glColor3f(*TriNode.color[node3.mat]) gl.glVertex2f(node3.vx - camera.x, node3.vy - camera.y) gl.glEnd() #print(secs, necs) gl.glBegin(gl.GL_LINES) gl.glColor3f(1.0, 1.0, 1.0) for sector in self.sectors: if camera.inCamera(sector.x, sector.y, sector.w, sector.h): for node in sector.nodes: for edge in node.leftEdgeList(): gl.glVertex2f(edge.start.vx - camera.x, edge.start.vy - camera.y) gl.glVertex2f(edge.end.vx - camera.x, edge.end.vy - camera.y) gl.glEnd() if self.selected: s = self.selected sz = 4 gl.glBegin(gl.GL_QUADS) gl.glColor3f(1.0, 0.0, 0.0) gl.glVertex2d(s.vx - sz - camera.x, s.vy - sz - camera.y) gl.glVertex2d(s.vx - sz - camera.x, s.vy + sz - camera.y) gl.glVertex2d(s.vx + sz - camera.x, s.vy + sz - camera.y) gl.glVertex2d(s.vx + sz - camera.x, s.vy - sz - camera.y) gl.glEnd()
def __draw_tile(self, tile_color: (int, int, int, int)): gl.glColor4f(*tile_color) gl.glBegin(gl.GL_QUADS) gl.glVertex2d(0, 0) gl.glVertex2d(self.__tile_size, 0) gl.glVertex2d(self.__tile_size, self.__tile_size) gl.glVertex2d(0, self.__tile_size) gl.glEnd()
def __draw_tile(self, color: (int, int, int, int), dimension: int): gl.glColor4f(*color) gl.glBegin(gl.GL_QUADS) gl.glVertex2d(0, 0) gl.glVertex2d(0, dimension) gl.glVertex2d(dimension, dimension) gl.glVertex2d(dimension, 0) gl.glEnd()
def __draw_tile(self, x: int, y: int): tile_color = self.__white_tile_color if (x + y) % 2 == 0 else self.__black_tile_color gl.glColor4f(*tile_color) gl.glBegin(gl.GL_QUADS) gl.glVertex2d(0, 0) gl.glVertex2d(self.__tile_size, 0) gl.glVertex2d(self.__tile_size, self.__tile_size) gl.glVertex2d(0, self.__tile_size) gl.glEnd()
def level_draw(self, camera): gl.glLoadIdentity() gl.glBegin(gl.GL_TRIANGLES) gl.glColor3f(1.0,1.0,1.0) secs = 0 necs = 0 for sector in self.sectors: if camera.inCamera(sector.x, sector.y, sector.w, sector.h): secs += 1 for node in sector.nodes: necs += 1 if node.e4: node2 = node.e4.end if node2.e6: node3 = node2.e6.end gl.glColor3f(*TriNode.color[node.mat]) gl.glVertex2f(node.vx-camera.x, node.vy-camera.y) gl.glColor3f(*TriNode.color[node2.mat]) gl.glVertex2f(node2.vx-camera.x, node2.vy-camera.y) gl.glColor3f(*TriNode.color[node3.mat]) gl.glVertex2f(node3.vx-camera.x, node3.vy-camera.y) if node.e5: node2 = node.e5.end if node2.e3: node3 = node2.e3.start gl.glColor3f(*TriNode.color[node.mat]) gl.glVertex2f(node.vx-camera.x, node.vy-camera.y) gl.glColor3f(*TriNode.color[node2.mat]) gl.glVertex2f(node2.vx-camera.x, node2.vy-camera.y) gl.glColor3f(*TriNode.color[node3.mat]) gl.glVertex2f(node3.vx-camera.x, node3.vy-camera.y) gl.glEnd() #print(secs, necs) gl.glBegin(gl.GL_LINES) gl.glColor3f(1.0,1.0,1.0) for sector in self.sectors: if camera.inCamera(sector.x, sector.y, sector.w, sector.h): for node in sector.nodes: for edge in node.leftEdgeList(): gl.glVertex2f(edge.start.vx-camera.x, edge.start.vy-camera.y) gl.glVertex2f(edge.end.vx-camera.x, edge.end.vy-camera.y) gl.glEnd() if self.selected: s = self.selected sz = 4 gl.glBegin(gl.GL_QUADS) gl.glColor3f(1.0,0.0,0.0) gl.glVertex2d(s.vx-sz-camera.x, s.vy-sz-camera.y) gl.glVertex2d(s.vx-sz-camera.x, s.vy+sz-camera.y) gl.glVertex2d(s.vx+sz-camera.x, s.vy+sz-camera.y) gl.glVertex2d(s.vx+sz-camera.x, s.vy-sz-camera.y) gl.glEnd()
def drawGL(self): gl.glVertex2d(*self.rt) gl.glVertex2d(*self.rb) gl.glVertex2d(*self.lb) gl.glVertex2d(*self.lt)
def __init__(self, font_name, size): FT = freetype2.FT # easier access to constants self.lib = freetype2.get_default_lib() # Load font and check it is monotype face = self.lib.find_face(font_name) face.set_char_size(size=size, resolution=90) if face.face_flags & FT.FACE_FLAG_FIXED_WIDTH == 0: raise 'Font is not monotype' # Determine largest glyph size width, height, ascender, descender = 0, 0, 0, 0 for c in range(32, 128): face.load_char(c, FT.LOAD_RENDER | FT.LOAD_FORCE_AUTOHINT) bitmap = face.glyph.bitmap width = max(width, bitmap.width) ascender = max(ascender, face.glyph.bitmap_top) descender = max(descender, bitmap.rows - face.glyph.bitmap_top) height = ascender + descender # Generate texture data Z = numpy.zeros((height * 6, width * 16), dtype=numpy.ubyte) for j in range(6): for i in range(16): face.load_char(32 + j * 16 + i, FT.LOAD_RENDER | FT.LOAD_FORCE_AUTOHINT) bitmap = face.glyph.bitmap.copy_with_array() x = i * width + face.glyph.bitmap_left y = j * height + ascender - face.glyph.bitmap_top Z[y:y + bitmap.rows, x:x + bitmap.width].flat = bitmap.buffer # Bound texture self.texture_ids = (pyglet.gl.GLuint * 1)() gl.glGenTextures(1, self.texture_ids) self.texture_id = self.texture_ids[0] gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture_id) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_ALPHA, Z.shape[1], Z.shape[0], 0, gl.GL_ALPHA, gl.GL_UNSIGNED_BYTE, Z.tostring()) # Generate display lists dx, dy = width / float(Z.shape[1]), height / float(Z.shape[0]) self.base = gl.glGenLists(8 * 16) for i in range(8 * 16): c = chr(i) x = i % 16 y = i // 16 - 2 gl.glNewList(self.base + i, gl.GL_COMPILE) if (c == '\n'): gl.glPopMatrix() gl.glTranslatef(0, -height, 0) gl.glPushMatrix() elif (c == '\t'): gl.glTranslatef(4 * width, 0, 0) elif (i >= 32): gl.glBegin(gl.GL_QUADS) gl.glTexCoord2d((x) * dx, (y + 1) * dy), gl.glVertex2d(0, -height) gl.glTexCoord2d((x) * dx, (y) * dy), gl.glVertex2d(0, 0) gl.glTexCoord2d((x + 1) * dx, (y) * dy), gl.glVertex2d(width, 0) gl.glTexCoord2d((x + 1) * dx, (y + 1) * dy), gl.glVertex2d(width, -height) gl.glEnd() gl.glTranslatef(width, 0, 0) gl.glEndList()