def test_create(ctx): program = ctx.program( vertex_shader=""" #version 330 in vec2 in_vert; void main() { gl_Position = vec4(in_vert, 0.0, 1.0); } """, fragment_shader=""" #version 330 out vec4 outColor; void main() { outColor = vec4(1.0); } """, ) quad = geometry.quad_2d_fs() query = ctx.query() with query: quad.render(program) assert query.time_elapsed > 0 assert query.samples_passed >= SCREEN_WIDTH * SCREEN_HEIGHT assert query.primitives_generated == 2 query = None
def setup(self): """ Set up the game and initialize the variables. """ # Offscreen stuff self.program = self.ctx.program( vertex_shader=''' #version 330 in vec2 in_vert; in vec2 in_uv; out vec2 v_uv; void main() { gl_Position = vec4(in_vert, 0.0, 1.0); v_uv = in_uv; } ''', fragment_shader=''' #version 330 uniform sampler2D tex; uniform float angle; uniform float zoom; in vec2 v_uv; out vec4 f_color; void main() { mat3 rotate = mat3( cos(angle), -sin(angle), 0.5, sin(angle), cos(angle), 0.5, 0.0, 0.0, 1.0 ); mat3 scale = mat3( 1.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 1.0 ); f_color = texture(tex, (rotate * scale * vec3(v_uv + vec2(-0.5, -0.5), 1.0)).xy * zoom); } ''', ) self.color_attachment = self.ctx.texture((SCREEN_WIDTH, SCREEN_HEIGHT)) self.offscreen = self.ctx.framebuffer( color_attachments=[self.color_attachment]) self.quad_fs = geometry.quad_2d_fs() self.t0 = time.time() self.frame = 0
def __init__(self, size, kernel_size=5, sigma: float = 2, mu: float = 0, multiplier: float = 5, step: int = 1): super().__init__(size, kernel_size=kernel_size) self._gaussian_1 = GaussianBlur((size[0], size[1]), kernel_size=kernel_size, sigma=sigma, multiplier=multiplier, step=step) self._gaussian_2 = GaussianBlur((size[0] // 4, size[1] // 4), kernel_size=kernel_size, sigma=sigma, multiplier=multiplier, step=step) self._gaussian_3 = GaussianBlur((size[0] // 8, size[1] // 8), kernel_size=kernel_size, sigma=sigma, multiplier=multiplier, step=step) # Program and buffer doing contrast / brightness / luma luma_tex = self.ctx.texture((self.width // 2, self.height // 2), components=3) luma_tex.wrap_x = self.ctx.CLAMP_TO_EDGE luma_tex.wrap_y = self.ctx.CLAMP_TO_EDGE self._cb_luma_buffer = self.ctx.framebuffer( color_attachments=[luma_tex]) # Buffer for the converted luma values self._cb_luma_program = self.ctx.load_program( vertex_shader= ':resources:shaders/postprocessing/glow_filter_vs.glsl', fragment_shader= ':resources:shaders/postprocessing/glow_filter_fs.glsl') # Program for combining the original buffer and the blurred buffer self._combine_program = self.ctx.load_program( vertex_shader= ':resources:shaders/texture_default_projection_vs.glsl', fragment_shader= ':resources:shaders/postprocessing/gaussian_combine_fs.glsl') self._quad_fs = geometry.quad_2d_fs()
def setup(self): """ Set up the game and initialize the variables. """ # Offscreen stuff self.program = self.ctx.load_program( vertex_shader=arcade.resources.shaders.vertex.default_projection, fragment_shader=arcade.resources.shaders.fragment.texture) self.color_attachment = self.ctx.texture((SCREEN_WIDTH, SCREEN_HEIGHT), components=4) self.offscreen = self.ctx.framebuffer( color_attachments=[self.color_attachment]) self.quad_fs = geometry.quad_2d_fs() self.mini_map_quad = geometry.quad_2d(size=(0.5, 0.5), pos=(0.75, 0.75)) # Sprite lists self.player_list = arcade.SpriteList() self.coin_list = arcade.SpriteList() # Score self.score = 0 # Set up the player # Character image from kenney.nl self.player_sprite = arcade.Sprite( ":resources:images/animated_characters/female_person/femalePerson_idle.png", SPRITE_SCALING_PLAYER) self.player_sprite.center_x = 50 self.player_sprite.center_y = 50 self.player_list.append(self.player_sprite) # Create the coins for i in range(COIN_COUNT): # Create the coin instance # Coin image from kenney.nl coin = arcade.Sprite(":resources:images/items/coinGold.png", SPRITE_SCALING_COIN) # Position the coin coin.center_x = random.randrange(SCREEN_WIDTH) coin.center_y = random.randrange(SCREEN_HEIGHT) # Add the coin to the lists self.coin_list.append(coin)
def __init__(self, size: Tuple[int, int], kernel_size=5, sigma=2, multiplier=1, step=1): super().__init__(size, kernel_size=5, sigma=2, multiplier=1, step=1) color_attachment = self.ctx.texture(size, components=3, wrap_x=self.ctx.CLAMP_TO_EDGE, wrap_y=self.ctx.CLAMP_TO_EDGE) self._fbo = self.ctx.framebuffer(color_attachments=color_attachment) self._program = self.ctx.load_program( # defines=self._create_kernel(), vertex_shader= ':resources:shaders/texture_default_projection_vs.glsl', fragment_shader= ':resources:shaders/postprocessing/gaussian_blur_x_fs.glsl', ) self._quad_fs = geometry.quad_2d_fs()
def __init__(self, width: int, height: int): """Create a RenderTargetTexture. :param int width: Width of the render target in pixels :param int height: Height of the render target in pixels """ self.window = get_window() if not self.window: raise RuntimeError("No window found") self.width = width self.height = height self._background_color: Color = (0, 0, 0) self.ctx = self.window.ctx self._fbo = self.ctx.framebuffer(color_attachments=[ self.ctx.texture((width, height), components=4) ]) self._quad_fs = geometry.quad_2d_fs()
def __init__(self, source: str): self.window = get_window() if not self.window: raise RuntimeError("No window found") self.ctx = self.window.ctx self.source: str = source self.mouse_pos = 0, 0 self.quad = geometry.quad_2d_fs() self.program = self.ctx.program( vertex_shader=("#version 330\n" "\n" "in vec2 in_vert;\n" "in vec2 in_uv;\n" "out vec2 v_uv;\n" "\n" "void main() {\n" " gl_Position = vec4(in_vert, 0.0, 1.0);\n" " v_uv = in_uv;\n" "}\n"), fragment_shader=("#version 330\n" "\n" "uniform sampler2D background;\n" "uniform float iTime;\n" "uniform vec2 iMouse;\n" "uniform vec2 iResolution;\n" "\n" "in vec2 v_uv;\n" "out vec4 out_color;\n" "\n" f"{self.source}\n" "\n" "void main() {\n" " vec4 color;\n" " mainImage(color, gl_FragCoord.xy);\n" " out_color = color;\n" "}\n"), )
def setup(self): """LOOK機能、character_screen画面, level_up画面、ノーマルstate時のUIの初期化を行う ミニマップ作成の情報もここで渡す """ self.engine.setup() viewport(self.engine.player.center_x, self.engine.player.center_y) # ここでminimapの作成を行う # ------------------------------------------------------------------------------ # ミニマップの描画位置指定 screen_size = (SCREEN_WIDTH, SCREEN_HEIGHT) self.program = self.ctx.load_program( vertex_shader=arcade.resources.shaders.vertex.default_projection, fragment_shader=arcade.resources.shaders.fragment.texture) # ピクセルの色を保存するために色の添付ファイルを追加します self.color_attachment = self.ctx.texture((screen_size), components=4, filter=(gl.GL_NEAREST, gl.GL_NEAREST)) # 必要な色を添付したフレームバッファを作成する self.offscreen = self.ctx.framebuffer( color_attachments=[self.color_attachment]) self.quad_fs = geometry.quad_2d_fs() self.mini_map_quad = geometry.quad_2d( size=(0.31, .31), pos=(.824, -.8)) # ------------------------------------------------------------------------------- # Lコマンドで呼び出すlook機能 self.select_UI = SelectUI(engine=self.engine) self.character_UI = CharacterScreenUI(engine=self.engine) self.level_up_window = LevelupUI() self.level_up_flower = LevelUpFlower(self.engine) self.normal_UI = NormalUI(self.engine)
def __init__(self, width, height, title): super().__init__(width, height, title, resizable=False) # Use the standard cube self.cube = geometry.cube() # Simple color lighting program for cube self.program = self.ctx.program( vertex_shader=""" #version 330 uniform mat4 projection; uniform mat4 modelview; in vec3 in_position; in vec3 in_normal; in vec2 in_uv; out vec3 normal; out vec3 pos; out vec2 uv; void main() { vec4 p = modelview * vec4(in_position, 1.0); gl_Position = projection * p; mat3 m_normal = transpose(inverse(mat3(modelview))); normal = m_normal * in_normal; pos = p.xyz; uv = in_uv; } """, fragment_shader=""" #version 330 uniform sampler2D texture0; uniform bool use_texture; out vec4 fragColor; in vec3 normal; in vec3 pos; in vec2 uv; void main() { float l = dot(normalize(-pos), normalize(normal)); if (use_texture) { fragColor = vec4(texture(texture0, uv).rgb * (0.25 + abs(l) * 0.75), 1.0); } else { fragColor = vec4(1.0) * (0.25 + abs(l) * 0.75); } } """, ) # Program for drawing fullscreen quad with texture self.quad_program = self.ctx.program( vertex_shader=""" #version 330 in vec2 in_vert; in vec2 in_uv; out vec2 uv; void main() { gl_Position = vec4(in_vert, 0.0, 1.0); uv = in_uv; } """, fragment_shader=""" #version 330 uniform sampler2D texture0; in vec2 uv; out vec4 fragColor; void main() { fragColor = texture(texture0, uv); } """, ) self.quad_fs = geometry.quad_2d_fs() self.on_resize(*self.get_size()) self.time = 0 self.frame = 0 self.fbo1 = self.ctx.framebuffer( color_attachments=[self.ctx.texture((self.get_size()))], depth_attachment=self.ctx.depth_texture(self.get_size()), ) self.fbo2 = self.ctx.framebuffer( color_attachments=[self.ctx.texture((self.get_size()))], depth_attachment=self.ctx.depth_texture(self.get_size()), )
def test_quad_2d_fs(ctx): geometry.quad_2d_fs()