def setUp(self): super().setUp() x, y, w, h = (0, 0, 200, 200) self.vb = self.renderer.new_vertex_buffer( [ gl.make_vba( gl.ContentKind.vertex, [gl.vec2f(x, y), gl.vec2f(x, y + h), gl.vec2f(x + w, y + h), gl.vec2f(x + w, y)], gl.ContentHint.static_content, ), gl.make_vba( gl.ContentKind.tex_coord0, [gl.vec2f(0, 0), gl.vec2f(0, 1), gl.vec2f(1, 1), gl.vec2f(1, 0)], gl.ContentHint.static_content, ), ] ) self.indices = self.renderer.new_index_buffer( gl.make_vba(gl.ContentKind.index, [0, 1, 2, 3], gl.ContentHint.static_content) ) from os import path self.texture = self.renderer.new_texture( gl.Surface(Path(path.join(path.dirname(__file__), "texture_test.bmp"))) ) self.texture.generate_mipmap() self.texture.min_filter_bilinear(gl.TextureFilter.linear) self.texture.mag_filter(gl.TextureFilter.linear)
def setUp(self): self.window = create_window( "PainterSetup", 200, 200, WindowFlags.hidden, Name.OpenGL ) self.renderer = self.window.renderer # Should be created before any shader self.target = self.renderer.context.new_render_target() gen = self.renderer.generate_shader(gl.ShaderType.vertex) for i in self.vs_inputs: gen.input(*i) for o in self.vs_outputs: gen.output(*o) for p in self.vs_parameters: gen.parameter(*p) self.vs = gen.routine(self.VSRoutine, "main").shader() gen = self.renderer.generate_shader(gl.ShaderType.fragment) for i in self.fs_inputs: gen.input(*i) for o in self.fs_outputs: gen.output(*o) for p in self.fs_parameters: gen.parameter(*p) self.fs = gen.routine(self.FSRoutine, "main").shader() x, y, w, h = ( 11, 42, 120, 140 ) self.shader = self.renderer.new_shader_program([self.fs, self.vs]) self.vb = self.renderer.new_vertex_buffer([ gl.make_vba( gl.ContentKind.vertex, list(gl.vec3f(*v) for v in [ (x, y, 0), (x, y + h, 0), (x + w, y + h, 0), (x + w, y, 0), ]), gl.ContentHint.static_content ), make_vba( ContentKind.color, [ Color3f('#e00'), Color3f('#9cd'), Color3f('#ffc'), Color3f('#00f'), ], ContentHint.static_content ) ]) self.indices = self.renderer.new_index_buffer( make_vba( ContentKind.index, [ 0, 1, 2, 3], ContentHint.static_content ) )
def setUp(self): super().setUp() x, y, w, h = ( 10, 10, 180, 180 ) self.vb = self.renderer.new_vertex_buffer([ gl.make_vba( gl.ContentKind.vertex, [ gl.vec3f(x, y, 0), gl.vec3f(x, y + h, 0), gl.vec3f(x + w, y + h, 0), gl.vec3f(x + w, y, 0), ], gl.ContentHint.static_content ), gl.make_vba( gl.ContentKind.tex_coord0, [ gl.vec2f(0, 0), gl.vec2f(0, 1), gl.vec2f(1, 1), gl.vec2f(1, 0), ], gl.ContentHint.static_content ) ]) self.indices = self.renderer.new_index_buffer( gl.make_vba( gl.ContentKind.index, [ 0, 1, 2, 3], gl.ContentHint.static_content ) )
def create(game, size, border, tile_width, tile_height, rows): mat = gl.Material('ground') mat.ambient = gl.col3f('#888') mat.diffuse = gl.col3f('#000') mat.specular = gl.col3f('#000') #mat.shininess = 0 #mat.shading_model = gl.material.ShadingModel.gouraud mat.add_color( gl.ShaderParameterType.vec3, gl.StackOperation.add ) coords = [] colors = [] indices = list(range(size.x * size.y * 4)) for i in range(size.x): x = i * tile_width + border for j in range(size.y): y = j * tile_height + border coords.extend([ gl.vec3f(x, y, 0), gl.vec3f(x, y + tile_height, 0), gl.vec3f(x + tile_width, y + tile_height, 0), gl.vec3f(x + tile_width, y, 0), ]) colors.extend([ gl.col3f('#356712'), gl.col3f('#356712'), gl.col3f('#356712'), gl.col3f('#356712'), ]) ground_vb = game.renderer.new_vertex_buffer([ gl.make_vba( gl.ContentKind.vertex, coords, gl.ContentHint.static_content ), gl.make_vba( gl.ContentKind.color, colors, gl.ContentHint.static_content ) ]) ground_ib = game.renderer.new_index_buffer( gl.make_vba( gl.ContentKind.index, indices, gl.ContentHint.static_content ) ) # Set initial color #colors_attr = ground_vb[1] #colors_attr[0] = gl.col3f('blue') #colors_attr[1] = gl.col3f('blue') #ground_vb.reload(1) board = game.entity_manager.create( 'board', ib = ground_ib, vb = ground_vb, size = size, tile_height = tile_height, tile_width = tile_width, border = border, rows = rows, event_manager = game.event_manager, ) transform = board.add_component( Transform( gl.matrix.translate( #gl.matrix.scale( gl.mat4f(), # gl.vec3f(size, size, 1) #), gl.vec3f(-.5, -.5, 0) ) ) ) board.add_component(Bindable(mat)) board.add_component(Drawable(DrawGround(board, len(indices)))) board.add_component(Controller(CellManager(board = board))) return board