Formázási javítások és tipográfiai karakter spritok és definíciók

This commit is contained in:
markojozsef
2026-09-10 18:19:24 +02:00
parent ac86f1f9e8
commit 10fd39db7d
5 changed files with 204 additions and 65 deletions

59
src/renderers.py Normal file
View File

@@ -0,0 +1,59 @@
import arcade
class TextureRenderer:
def __init__(self, ctx):
self.ctx = ctx
self.program = ctx.program(
vertex_shader="""
#version 330
in vec2 in_vert;
in vec2 in_uv;
out vec2 uv;
uniform vec2 screen_size;
uniform vec4 bounds;
void main() {
// Convert quad coordinates from [-1, 1] to [0, 1]
vec2 local = in_vert * 0.5 + 0.5;
// bounds = x, y, width, height in pixels
vec2 pixel_pos = bounds.xy + local * bounds.zw;
// Convert pixels to NDC
vec2 ndc = pixel_pos / screen_size * 2.0 - 1.0;
gl_Position = vec4(ndc, 0.0, 1.0);
uv = in_uv;
}
""",
fragment_shader="""
#version 330
uniform sampler2D tex;
in vec2 uv;
out vec4 color;
void main() {
color = texture(tex, uv);
}
""",
)
self.quad = arcade.gl.geometry.quad_2d_fs()
def render(self, texture, x, y, width, height):
self.program["screen_size"] = (self.ctx.screen.width,
self.ctx.screen.height)
self.program["bounds"] = (x, y, width, height)
texture.use(0)
self.program["tex"] = 0
self.quad.render(self.program)