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

Custom font not properly loaded with auto renderer #64

Closed PFGimenez closed 5 years ago

PFGimenez commented 5 years ago

That's me again

Problem

When I load a custom non-square font with the auto renderer (GLSL), the font is not properly loaded. In this example, I try to print "Hello World!". It works fine with the SDL renderer.

What I expect (obtained with the SDL renderer): screenshot3

What I see with the auto renderer (again, the yellow border is drawn by my OS): screenshot2

Minimal example code

import time

import tcod

# Setup the font.
tcod.console_set_custom_font(
    'Andux_cp866ish.png',
    tcod.FONT_LAYOUT_ASCII_INROW,
    )

# Initialize the root console in a context.
with tcod.console_init_root(20, 10, 'title') as root_console:
    root_console.print_(x=0, y=0, string='Hello World!')
    tcod.console_flush() # Show the console.
    time.sleep(3) # Wait 3 seconds.
# The window is closed here, after the above context exits.

Configuration

I use python 3.7.2+, python-tcod 8.3.2 and SDL 2.0.9 on Debian testing. I got the same problem with another computer (Ubuntu 18.04) with SDL 2.0.8.

Resource

The custom font can be downloaded here: http://dwarffortresswiki.org/images/4/4a/Andux_cp866ish.png

HexDecimal commented 5 years ago

Does this issue persist if you change the flags to tcod.FONT_LAYOUT_ASCII_INROW | tcod.FONT_TYPE_GREYSCALE?

PFGimenez commented 5 years ago

I'm afk at the moment, I can test in about one hour.

PFGimenez commented 5 years ago

This is the result with tcod.FONT_LAYOUT_ASCII_INROW | tcod.FONT_TYPE_GREYSCALE: screenshot4

(it's completely black)

HexDecimal commented 5 years ago

The magic pink background could mess up the font loader, anything other than white on black is ambiguous. Here's a version with a black background:

andux_cp866ish

PFGimenez commented 5 years ago

It works ! Thank you. Is it normal that the pink version worked with the libtcod version of http://rogueliketutorials.com ?

HexDecimal commented 5 years ago

I'm not sure, maybe?

There are two font loaders in libtcod: the original one for the SDL, OPENGL, and GLSL renderers; and the one made by me for the SDL2 and OPENGL2 renderers.

When I tested the font with SDL, OPENGL, and GLSL I got three different results.

My font loader ignores the FONT_TYPE_GREYSCALE flag and individually converts greyscale glyphs to white-with-alpha, but assumes any glyph with colors will provide its own alpha. As expected the font loads as white on pink glyphs multiplied by the foreground color with this loader.

PFGimenez commented 5 years ago

If the problem comes from the font I used, I guess you can close this issue.

HexDecimal commented 5 years ago

I was confused about the tileset format for a little while but it looks like it's just using magic pink as a key-color. I could eventually add automatic support for this in the new font loader.

PFGimenez commented 5 years ago

I noticed that libtcod guesses automatically the key color using the space (' ') character, if it can help you : https://github.com/libtcod/libtcod/blob/master/src/libtcod/sys_sdl_c.cpp#L330

HexDecimal commented 5 years ago

You can now use those tilesets as-is in the latest versions of python-tcod and libtcod, as long as it's using one of the newer renderers.