def draw(self, win=None): """Draw the current frame to a particular visual.Window (or to the default win for this object if not specified). The current position in the movie will be determined automatically. This method should be called on every frame that the movie is meant to appear. """ if (self.status == NOT_STARTED or (self.status == FINISHED and self.loop)): self.play() elif self.status == FINISHED and not self.loop: return if win is None: win = self.win self._selectWindow(win) self._updateFrameTexture() # will check if it's needed # scale the drawing frame and get to centre of field GL.glPushMatrix() # push before drawing, pop after # push the data for client attributes GL.glPushClientAttrib(GL.GL_CLIENT_ALL_ATTRIB_BITS) self.win.setScale('pix') # move to centre of stimulus and rotate vertsPix = self.verticesPix # bind textures GL.glActiveTexture(GL.GL_TEXTURE1) GL.glBindTexture(GL.GL_TEXTURE_2D, 0) GL.glEnable(GL.GL_TEXTURE_2D) GL.glActiveTexture(GL.GL_TEXTURE0) GL.glBindTexture(GL.GL_TEXTURE_2D, self._texID) GL.glEnable(GL.GL_TEXTURE_2D) # sets opacity (1,1,1 = RGB placeholder) GL.glColor4f(1, 1, 1, self.opacity) array = (GL.GLfloat * 32)( 1, 1, # texture coords vertsPix[0, 0], vertsPix[0, 1], 0., # vertex 0, 1, vertsPix[1, 0], vertsPix[1, 1], 0., 0, 0, vertsPix[2, 0], vertsPix[2, 1], 0., 1, 0, vertsPix[3, 0], vertsPix[3, 1], 0., ) # 2D texture array, 3D vertex array GL.glInterleavedArrays(GL.GL_T2F_V3F, 0, array) GL.glDrawArrays(GL.GL_QUADS, 0, 4) GL.glPopClientAttrib() GL.glPopAttrib() GL.glPopMatrix() # unbind the textures GL.glActiveTexture(GL.GL_TEXTURE0) GL.glBindTexture(GL.GL_TEXTURE_2D, 0) GL.glEnable(GL.GL_TEXTURE_2D) # implicitly disables 1D
def batch_draw(csl): glPushMatrix() glLoadIdentity() vertices = [] for cs in csl: ax, ay = cs.abs_coords() if cs.ft_anim: qs = cs.question_scale bs = cs.back_scale aa = cs.ftanim_alpha ca = cs.ftanim_cardalpha if cs.gray: c = (.66, .66, .66, ca) else: c = (1., 1., 1., ca) vertices += cs.img.get_t2c4n3v3_vertices(c, ax, ay) n, s = cs.number, cs.suit if n: vertices += game_res.cardnum[s % 2 * 13 + n - 1].get_t2c4n3v3_vertices(c, ax + 5, ay + 105) if s: vertices += game_res.suit[s - 1].get_t2c4n3v3_vertices(c, ax + 6, ay + 94) c = (1, 1, 1, aa) if qs: vertices += game_res.card_question.get_t2c4n3v3_vertices(c, ax+(1-qs)*45, ay, 0, qs*91) if bs: vertices += game_res.card_hidden.get_t2c4n3v3_vertices(c, ax+(1-bs)*45, ay, 0, bs*91) else: a = cs.alpha if cs.gray: c = (.66, .66, .66, a) else: c = (1., 1., 1., a) vertices += cs.img.get_t2c4n3v3_vertices(c, ax, ay) resides_in = cs.card.resides_in if resides_in and resides_in.type == 'showncards': vertices += game_res.card_showncardtag.get_t2c4n3v3_vertices(c, ax, ay) n, s = cs.number, cs.suit if n: vertices += game_res.cardnum[s % 2 * 13 + n - 1].get_t2c4n3v3_vertices(c, ax + 5, ay + 105) if s: vertices += game_res.suit[s-1].get_t2c4n3v3_vertices(c, ax+6, ay+94) vertices += game_res.card_shinesoft.get_t2c4n3v3_vertices( (1., 1., 1., cs.shine_alpha), ax-6, ay-6 ) if vertices: n = len(vertices) buf = (GLfloat*n)() buf[:] = vertices glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glInterleavedArrays(GL_T2F_C4F_N3F_V3F, 0, buf) with get_atlas('card').texture: glDrawArrays(GL_QUADS, 0, n/12) glPopClientAttrib() glPopMatrix()
def batch_draw_status(gcps): glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) vertices = [] for port in gcps: p = port.player if not getattr(p, 'ui_meta', False): continue hp = game_res.hp; hp_bg = game_res.hp_bg if getattr(p, 'dead', False): hp = hp.grayed hp_bg = hp_bg.grayed # hp bar w = hp.width x = port.x; y = port.y for i in xrange(getattr(p, 'maxlife', 0)): vertices.extend( hp_bg.get_t4f_v4f_vertices(5+x+i*w, 56+y) ) for i in xrange(max(getattr(p, 'life', 0), 0)): vertices.extend( hp.get_t4f_v4f_vertices(5+x+i*w, 56+y) ) nums = game_res.num for port in gcps: x, y, w, h = port.x, port.y, port.width, port.height p = port.player try: n = len(p.cards) + len(p.showncards) seq = str(n) ox = (32 - len(seq)*14)//2 for i, ch in enumerate(seq): n = ord(ch) - ord('0') #x, y = w - 34 + ox + i*14, 68 vertices.extend(nums[n].get_t4f_v4f_vertices( x + w - 34 + ox + i*14, y + 68 )) except AttributeError: pass if vertices: with nums[0].owner: n = len(vertices) buf = (GLfloat*n)() buf[:] = vertices glInterleavedArrays(GL_T4F_V4F, 0, buf) glDrawArrays(GL_QUADS, 0, n/8) glPopClientAttrib()
def draw(self): """Render the particle system.""" if not self.live_particles: return if self.dirty_indices: indices = [p.slot for p in self.live_particles if not p.dead] self.indices = (gl.GLuint * len(indices))(*indices) self.dirty_indices = False gl.glPointSize(self.particle_class.size) gl.glInterleavedArrays(gl.GL_C4F_N3F_V3F, 0, self.data) gl.glDrawElements(gl.GL_POINTS, len(self.indices), gl.GL_UNSIGNED_INT, self.indices)
def batch_draw_status(gcps): glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) vertices = [] for port in gcps: char = port.character if not char: continue hp, hp_bg = L('thb-hp'), L('thb-hp_bg') if char.dead: hp = hp.grayed hp_bg = hp_bg.grayed # hp bar w = hp.width x, y = port.x, port.y for i in xrange(char.maxlife): vertices.extend( hp_bg.get_t4f_v4f_vertices(5+x+i*w, 56+y) ) for i in xrange(max(char.life, 0)): vertices.extend( hp.get_t4f_v4f_vertices(5+x+i*w, 56+y) ) nums = L('thb-num') for port in gcps: x, y, w = port.x, port.y, port.width char = port.character if not char: continue n = len(char.cards) + len(char.showncards) seq = str(n) ox = (32 - len(seq)*14)//2 for i, ch in enumerate(seq): n = ord(ch) - ord('0') # x, y = w - 34 + ox + i*14, 68 vertices.extend(nums[n].get_t4f_v4f_vertices( x + w - 34 + ox + i*14, y + 68 )) if vertices: with nums[0].owner: n = len(vertices) buf = (GLfloat*n)() buf[:] = vertices glInterleavedArrays(GL_T4F_V4F, 0, buf) glDrawArrays(GL_QUADS, 0, n/8) glPopClientAttrib()
def draw_image(self, img, rect=None, force_copy=False): """ Renders a GraphicsContextArray into this GC """ xform = self.get_ctm() x0 = xform[4] y0 = xform[5] image = image_as_array(img) shape = image.shape if shape[2] == 4: fmt = "RGBA" else: fmt = "RGB" aii = ArrayImage(image, format=fmt) texture = aii.texture # The texture coords consists of (u,v,r) for each corner of the # texture rectangle. The coordinates are stored in the order # bottom left, bottom right, top right, top left. x, y, w, h = rect texture.width = w texture.height = h t = texture.tex_coords points = array([ [x, y+h], [x+w, y+h], [x+w, y], [x, y], ]) p = transform_points(affine_from_values(*xform), points) a = (gl.GLfloat*32)( t[0], t[1], t[2], 1., p[0,0], p[0,1], 0, 1., t[3], t[4], t[5], 1., p[1,0], p[1,1], 0, 1., t[6], t[7], t[8], 1., p[2,0], p[2,1], 0, 1., t[9], t[10], t[11], 1., p[3,0], p[3,1], 0, 1., ) gl.glPushAttrib(gl.GL_ENABLE_BIT) gl.glEnable(texture.target) gl.glBindTexture(texture.target, texture.id) gl.glPushClientAttrib(gl.GL_CLIENT_VERTEX_ARRAY_BIT) gl.glInterleavedArrays(gl.GL_T4F_V4F, 0, a) gl.glDrawArrays(gl.GL_QUADS, 0, 4) gl.glPopClientAttrib() gl.glPopAttrib()
def batch_draw(csl): glPushMatrix() glLoadIdentity() vertices = [] for cs in csl: ax, ay = cs.abs_coords() vertices += cs.img.get_t4f_v4f_vertices(ax, ay) s = cs.card.suit n = cs.card.number ssuit = L('thb-smallsuit') snum = L('thb-smallnum') if n == 10: # special case # g[0].blit(1+g[0].vertices[0], 33+g[0].vertices[1]) # g[1].blit(5+g[1].vertices[0], 33+g[1].vertices[1]) vertices += snum[s % 2 * 14 + 10].get_t4f_v4f_vertices( ax - 1, ay + 31) vertices += snum[s % 2 * 14 + 0].get_t4f_v4f_vertices( ax + 3, ay + 31) else: vertices += snum[s % 2 * 14 + n].get_t4f_v4f_vertices( ax + 1, ay + 31) vertices += ssuit[s - 1].get_t4f_v4f_vertices(ax + 1, ay + 22) if cs.selected: vertices += L('thb-card-small-selected').get_t4f_v4f_vertices( ax, ay) else: vertices += L('thb-card-small-frame').get_t4f_v4f_vertices( ax, ay) n = len(vertices) buf = (GLfloat * n)() buf[:] = vertices glColor3f(1., 1., 1.) glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glInterleavedArrays(GL_T4F_V4F, 0, buf) with get_atlas('card').texture: glDrawArrays(GL_QUADS, 0, n / 8) glPopClientAttrib() glPopMatrix()
def batch_draw(csl): glPushMatrix() glLoadIdentity() vertices = [] for cs in csl: ax, ay = cs.abs_coords() vertices += cs.img.get_t4f_v4f_vertices(ax, ay) s = cs.card.suit n = cs.card.number ssuit = game_res.smallsuit snum = game_res.smallnum if n == 10: # special case # g[0].blit(1+g[0].vertices[0], 33+g[0].vertices[1]) # g[1].blit(5+g[1].vertices[0], 33+g[1].vertices[1]) vertices += snum[s % 2 * 14 + 10].get_t4f_v4f_vertices(ax - 1, ay + 31) vertices += snum[s % 2 * 14 + 0].get_t4f_v4f_vertices(ax + 3, ay + 31) else: vertices += snum[s % 2 * 14 + n].get_t4f_v4f_vertices(ax + 1, ay + 31) vertices += ssuit[s - 1].get_t4f_v4f_vertices(ax + 1, ay + 22) if cs.selected: vertices += game_res.scardframe_selected.get_t4f_v4f_vertices(ax, ay) else: vertices += game_res.scardframe_normal.get_t4f_v4f_vertices(ax, ay) n = len(vertices) buf = (GLfloat*n)() buf[:] = vertices glColor3f(1., 1., 1.) glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glInterleavedArrays(GL_T4F_V4F, 0, buf) with get_atlas('card').texture: glDrawArrays(GL_QUADS, 0, n/8) glPopClientAttrib() glPopMatrix()
def batch_draw(csl): glPushMatrix() glLoadIdentity() vertices = [] for cs in csl: ax, ay = cs.abs_coords() if cs.ft_anim: qs = cs.question_scale bs = cs.back_scale aa = cs.ftanim_alpha ca = cs.ftanim_cardalpha if cs.gray: c = (.66, .66, .66, ca) else: c = (1., 1., 1., ca) vertices += cs.img.get_t2c4n3v3_vertices(c, ax, ay) n, s = cs.number, cs.suit if n: vertices += L('thb-cardnum')[s % 2 * 13 + n - 1].get_t2c4n3v3_vertices(c, ax + 5, ay + 105) if s: vertices += L('thb-suit')[s - 1].get_t2c4n3v3_vertices(c, ax + 6, ay + 94) c = (1, 1, 1, aa) if qs: vertices += L('thb-card-question').get_t2c4n3v3_vertices(c, ax+(1-qs)*45, ay, 0, qs*91) if bs: vertices += L('thb-card-hidden').get_t2c4n3v3_vertices(c, ax+(1-bs)*45, ay, 0, bs*91) else: a = cs.alpha if cs.gray: c = (.66, .66, .66, a) else: c = (1., 1., 1., a) vertices += cs.img.get_t2c4n3v3_vertices(c, ax, ay) resides_in = cs.card.resides_in if resides_in and resides_in.type == 'showncards': vertices += L('thb-card-showncardtag').get_t2c4n3v3_vertices(c, ax, ay) n, s = cs.number, cs.suit if n: vertices += L('thb-cardnum')[s % 2 * 13 + n - 1].get_t2c4n3v3_vertices(c, ax + 5, ay + 105) if s: vertices += L('thb-suit')[s-1].get_t2c4n3v3_vertices(c, ax+6, ay+94) if cs.selected: c = (0., 0., 2., 1.0) else: c = (1., 1., 1., cs.shine_alpha) vertices += L('thb-card-shinesoft').get_t2c4n3v3_vertices(c, ax-6, ay-6) if vertices: n = len(vertices) buf = (GLfloat*n)() buf[:] = vertices glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glInterleavedArrays(GL_T2F_C4F_N3F_V3F, 0, buf) with get_atlas('card').texture: glDrawArrays(GL_QUADS, 0, n/12) glPopClientAttrib() glPopMatrix()
def draw_image(self, img, rect=None, force_copy=False): """ Renders a GraphicsContextArray into this GC """ xform = self.get_ctm() image = image_as_array(img) shape = image.shape if shape[2] == 4: fmt = "RGBA" else: fmt = "RGB" aii = ArrayImage(image, format=fmt) texture = aii.texture # The texture coords consists of (u,v,r) for each corner of the # texture rectangle. The coordinates are stored in the order # bottom left, bottom right, top right, top left. x, y, w, h = rect texture.width = w texture.height = h t = texture.tex_coords points = array([ [x, y + h], [x + w, y + h], [x + w, y], [x, y], ]) p = transform_points(affine_from_values(*xform), points) a = (gl.GLfloat * 32)( t[0], t[1], t[2], 1., p[0, 0], p[0, 1], 0, 1., t[3], t[4], t[5], 1., p[1, 0], p[1, 1], 0, 1., t[6], t[7], t[8], 1., p[2, 0], p[2, 1], 0, 1., t[9], t[10], t[11], 1., p[3, 0], p[3, 1], 0, 1., ) gl.glPushAttrib(gl.GL_ENABLE_BIT) gl.glEnable(texture.target) gl.glBindTexture(texture.target, texture.id) gl.glPushClientAttrib(gl.GL_CLIENT_VERTEX_ARRAY_BIT) gl.glInterleavedArrays(gl.GL_T4F_V4F, 0, a) gl.glDrawArrays(gl.GL_QUADS, 0, 4) gl.glPopClientAttrib() gl.glPopAttrib()
def DrawFixedImage(self, ImageViewModel, color, BoundingBox=None, z=None): '''Draw a fixed image, bounding box indicates the visible area. Everything is drawn if BoundingBox is None''' if z is None: z = self.z if hasattr(self.rendercache, 'FixedImageDataGrid'): FixedImageDataGrid = self.rendercache.FixedImageDataGrid else: FixedImageDataGrid = [] for i in range(0, ImageViewModel.NumCols): FixedImageDataGrid.append([None] * ImageViewModel.NumRows) self.rendercache.FixedImageDataGrid = FixedImageDataGrid if color is None: color = (1.0, 1.0, 1.0, 1.0) for ix in range(0, ImageViewModel.NumCols): column = ImageViewModel.ImageArray[ix] cacheColumn = FixedImageDataGrid[ix] for iy in range(0, ImageViewModel.NumRows): texture = column[iy] t = (0.0, 0.0, z, 1.0, 0.0, z, 1.0, 1.0, z, 0.0, 1.0, z) w, h = ImageViewModel.TextureSize x = ImageViewModel.TextureSize[1] * ix y = ImageViewModel.TextureSize[0] * iy # Check bounding box if it exists if not BoundingBox is None: if not nornir_imageregistration.spatial.Rectangle.contains(BoundingBox, [y, x, y + h, x + w]): continue array = None if cacheColumn[iy] is None: array = (gl.GLfloat * 32)( t[0], t[1], t[2], 1., x, y, z, 1., t[3], t[4], t[5], 1., x + w, y, z, 1., t[6], t[7], t[8], 1., x + w, y + h, z, 1., t[9], t[10], t[11], 1., x, y + h, z, 1.) cacheColumn[iy] = array else: array = cacheColumn[iy] gl.glEnable(gl.GL_TEXTURE_2D) gl.glDisable(gl.GL_CULL_FACE) pyglet.gl.glColor4f(color[0], color[1], color[2], color[3]) gl.glBindTexture(gl.GL_TEXTURE_2D, texture) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST) gl.glPushClientAttrib(gl.GL_CLIENT_VERTEX_ARRAY_BIT) gl.glInterleavedArrays(gl.GL_T4F_V4F, 0, array) gl.glDrawArrays(gl.GL_QUADS, 0, 4) gl.glPopClientAttrib() pyglet.gl.glColor4f(1.0, 1.0, 1.0, 1.0)
def DrawFixedImage(self, ImageViewModel, color, BoundingBox=None, z=None): '''Draw a fixed image, bounding box indicates the visible area. Everything is drawn if BoundingBox is None''' if z is None: z = self.z if hasattr(self.rendercache, 'FixedImageDataGrid'): FixedImageDataGrid = self.rendercache.FixedImageDataGrid else: FixedImageDataGrid = [] for i in range(0, ImageViewModel.NumCols): FixedImageDataGrid.append([None] * ImageViewModel.NumRows) self.rendercache.FixedImageDataGrid = FixedImageDataGrid if color is None: color = (1.0, 1.0, 1.0, 1.0) gl.glEnable(gl.GL_TEXTURE_2D) gl.glDisable(gl.GL_CULL_FACE) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST) pyglet.gl.glColor4f(color[0], color[1], color[2], color[3]) for ix in range(0, ImageViewModel.NumCols): column = ImageViewModel.ImageArray[ix] cacheColumn = FixedImageDataGrid[ix] for iy in range(0, ImageViewModel.NumRows): texture = column[iy] t = (0.0, 0.0, z, 1.0, 0.0, z, 1.0, 1.0, z, 0.0, 1.0, z) w, h = ImageViewModel.TextureSize x = ImageViewModel.TextureSize[1] * ix y = ImageViewModel.TextureSize[0] * iy # Check bounding box if it exists if not BoundingBox is None: if not nornir_imageregistration.spatial.Rectangle.contains(BoundingBox, [y, x, y + h, x + w]): continue array = None if cacheColumn[iy] is None: array = (gl.GLfloat * 32)( t[0], t[1], t[2], 1., x, y, z, 1., t[3], t[4], t[5], 1., x + w, y, z, 1., t[6], t[7], t[8], 1., x + w, y + h, z, 1., t[9], t[10], t[11], 1., x, y + h, z, 1.) cacheColumn[iy] = array else: array = cacheColumn[iy] gl.glBindTexture(gl.GL_TEXTURE_2D, texture) gl.glPushClientAttrib(gl.GL_CLIENT_VERTEX_ARRAY_BIT) gl.glInterleavedArrays(gl.GL_T4F_V4F, 0, array) gl.glDrawArrays(gl.GL_QUADS, 0, 4) gl.glPopClientAttrib() pyglet.gl.glColor4f(1.0, 1.0, 1.0, 1.0)
def draw(self): glInterleavedArrays(self._draw_data_encoding_mode, 0, self.c_draw_data) glDrawArrays(self._draw_shape, 0, self._n_vertices)