Skip to content

Instantly share code, notes, and snippets.

@HexDecimal
Last active January 31, 2022 04:46
Show Gist options
  • Save HexDecimal/7a950acafa92a60377d038ba411827b2 to your computer and use it in GitHub Desktop.
Save HexDecimal/7a950acafa92a60377d038ba411827b2 to your computer and use it in GitHub Desktop.
Example of the experimental SDL port in python-tcod.
import tcod
import tcod.render
# Font file is at https://github.com/libtcod/python-tcod/blob/4385a4d65f20a6e1eefc8ab0a243c0d869adec45/fonts/libtcod/dejavu16x16_gs_tc.png
FONT = "dejavu16x16_gs_tc.png"
tileset = tcod.tileset.load_tilesheet(FONT, 32, 8, tcod.tileset.CHARMAP_TCOD)
console = tcod.Console(20, 8)
console.print(0, 0, "Hello World")
sdl_window = tcod.sdl.video.new_window(
console.width * tileset.tile_width,
console.height * tileset.tile_height,
flags=tcod.lib.SDL_WINDOW_RESIZABLE,
)
sdl_renderer = tcod.sdl.render.new_renderer(sdl_window, target_textures=True)
atlas = tcod.render.SDLTilesetAtlas(sdl_renderer, tileset)
console_render = tcod.render.SDLConsoleRender(atlas)
while True:
sdl_renderer.copy(console_render.render(console))
sdl_renderer.present()
for event in tcod.event.wait():
if isinstance(event, tcod.event.Quit):
raise SystemExit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment