sdl rendering progress?

This commit is contained in:
Lukas Nöllemeyer 2024-08-19 18:17:25 +02:00
parent 467c6606da
commit af941dc848
5 changed files with 22 additions and 13 deletions

View file

@ -53,16 +53,18 @@ def main_draw() -> None:
if not g.screens:
return
g.background.clear()
g.foreground.clear()
g.foreground.rgba["bg"][:] = 0
g.foreground.rgba["fg"][:] = 0
g.screens[-1].on_draw(g.background)
# g.context.present(g.background)
# g.sdl_renderer.copy(g.console_render.render(g.background))
# g.foreground.blit(g.background, fg_alpha=1.0, bg_alpha=0.0)
bg_tex = g.console_render.render(g.background)
fg_tex = g.console_render.render(g.foreground)
# g.foreground.blit(g.background, fg_alpha=1.0, bg_alpha=0.0)
bg_tex = g.console_render1.render(g.background)
bg_tex.blend_mode = 1
fg_tex = g.console_render2.render(g.foreground)
fg_tex.blend_mode = 1
with g.sdl_renderer.set_render_target(bg_tex):
g.sdl_renderer.copy(fg_tex)
@ -119,7 +121,7 @@ def draw_previous_screens(screen: Screen, console: tcod.console.Console, dim: bo
return
prev_screen.on_draw(console)
if dim and screen is g.screens[-1]:
g.foreground.rgb["fg"] //= 4
g.foreground.rgb["bg"] //= 4
g.background.rgb["fg"] //= 4
g.background.rgb["bg"] //= 4
g.foreground.rgba["fg"] //= 4
g.foreground.rgba["bg"] //= 4
g.background.rgba["fg"] //= 4
g.background.rgba["bg"] //= 4

View file

@ -62,7 +62,7 @@ def _draw_entity(entity: tcod.ecs.Entity, camera_pos, camera_radius_x, camera_ra
map_pos = world_pos_to_map_pos(pos)
if g.world[None].components[Map].fov[map_pos.y, map_pos.x]:
graphic = entity.components[Graphic]
g.foreground.rgba[["ch", "fg", "bg"]][screen_pos.y + camera_radius_y, screen_pos.x + camera_radius_x] = graphic.ch, graphic.fg, graphic.bg
g.foreground.rgba[["ch", "fg"]][screen_pos.y + camera_radius_y, screen_pos.x + camera_radius_x] = graphic.ch, graphic.fg
@attrs.define()
@ -86,6 +86,7 @@ class MainScreen(Screen):
def on_draw(self, console: tcod.console.Console) -> None:
"""Draw the standard screen."""
console = g.background
centers = [a.components[Position] for a in g.world.Q.all_of(tags=[IsPlayer])]
camera_pos = sum(centers, start=Position(0,0))
camera_pos = camera_pos.mod(len(centers))

View file

@ -7,9 +7,11 @@ from typing import Protocol
import attrs
import tcod.console
import tcod.constants
import tcod.event
from tcod.event import KeySym
import g
from game.constants import DIRECTION_KEYS
from game.screens import Pop, Screen, ScreenResult, draw_previous_screens
@ -93,6 +95,6 @@ class ListMenu(Screen):
def on_draw(self, console: tcod.console.Console) -> None:
"""Render the menu."""
draw_previous_screens(self, console)
draw_previous_screens(self, g.foreground)
for i, item in enumerate(self.items):
item.on_draw(console, x=self.x, y=self.y + i, highlight=i == self.selected)
item.on_draw(g.foreground, x=self.x, y=self.y + i, highlight=i == self.selected)