libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
413 stars 36 forks source link

tdl.screenshot not working? #40

Closed keytonw closed 5 years ago

keytonw commented 6 years ago

Trying to do a simple screenshot test. No bug but nothing happens. Do I need to initialized differently to get it to work?

import tdl

def handle_keys(user_input):
    # Movement keys
    if user_input.key == 'UP':
        return {'move': (0, -1)}
    elif user_input.key == 'DOWN':
        return {'move': (0, 1)}
    elif user_input.key == 'LEFT':
        return {'move': (-1, 0)}
    elif user_input.key == 'RIGHT':
        return {'move': (1, 0)}

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle full screen
        return {'fullscreen': True}
    elif user_input.key == 'ESCAPE':
        # Exit the game
        return {'exit': True}

    # No key was pressed
    return {}

def main():
    screen_width = 80
    screen_height = 50
    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)

    root_console = tdl.init(screen_width, screen_height, title='Roguelike Tutorial Revised', fullscreen=True)

    while not tdl.event.is_window_closed():
        root_console.draw_char(player_x, player_y, '@', bg=None, fg=(255, 255, 255))
        tdl.flush()

        root_console.draw_char(player_x, player_y, ' ', bg=None)

        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                break
        else:
            user_input = None

        if not user_input:
            continue
        action = handle_keys(user_input)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            tdl.screenshot() ###############################
            dx, dy = move
            player_x += dx
            player_y += dy

        if exit:
            return True

        if fullscreen:
            tdl.set_fullscreen(not tdl.get_fullscreen())
            return True

if __name__ == "__main__":
    main()
HexDecimal commented 6 years ago

I can confirm the bug exists in libtcod itself. The screenshot code is non-trivial, so it will take a little while to fix.

The bug seems to be limited to the SDL renderer, so if you add renderer='GLSL' to tdl.init you should able to take screenshots.

keytonw commented 6 years ago

Thanks, Kyle. Confirmed that setting the renderer works like a charm. Appreciate the quick response! Have a good rest of your weekend...

HexDecimal commented 5 years ago

The regression in the old SDL renderer is fixed. You can now take screenshots with it active.