Skip to content

Instantly share code, notes, and snippets.

@lecram
Last active December 28, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lecram/7469692 to your computer and use it in GitHub Desktop.
Save lecram/7469692 to your computer and use it in GitHub Desktop.
Test for PySDL2's BitmapFont.
# To use this script, save the image from the page below as '7sled.png'.
# http://imgur.com/C2OLhYj
# The script should create a file 'test_bmp_font.bmp' that looks like this:
# http://imgur.com/WFJNRTT
import atexit
import sdl2
import sdl2.ext
sdl2.ext.init()
atexit.register(sdl2.ext.quit)
ffile = b"7sled.png"
fwidth = 70
fheight = 100
surf = sdl2.sdlimage.IMG_Load(ffile).contents
bmpfont = sdl2.ext.BitmapFont(surf, (fwidth, fheight), ["01234-", "56789:"])
s = "01 23 45\n --::-- "
assert bmpfont.can_render(s)
surf = bmpfont.render(s).surface
s = ": :"
assert bmpfont.can_render(s)
bmpfont.render_on(surf, s, (fwidth * 2, 0))
sdl2.SDL_SaveBMP(surf, b"test_bmp_font.bmp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment