pyxel: Pyxel's text(x, y, string, color) function silently fails to print text to the screen.
On my Debian buster machine I added a single call to Pyxel’s text() function to the introductory example code in the README:
import pyxel
pyxel.init(160, 120)
def update():
if pyxel.btnp(pyxel.KEY_Q):
pyxel.quit()
def draw():
pyxel.cls(0)
pyxel.rect(10, 10, 20, 20, 11)
pyxel.text(10, 10, "This is a sentence.", 11)
pyxel.run(update, draw)
and ran it, resulting in the following screenshot, which has the specified rectangle but the text is nowhere to be found:
All apt packages installed successfully as required in the README:
Reading package lists...
Building dependency tree...
Reading state information...
libasound2-dev is already the newest version (1.1.6-1).
libglfw3 is already the newest version (3.2.1-1).
libportaudio2 is already the newest version (19.6.0-1).
python3-pip is already the newest version (9.0.1-2.3).
python3 is already the newest version (3.6.6-1).
0 upgraded, 0 newly installed, 0 to remove and 908 not upgraded.
and pip3 also had no errors installing required packages:
Collecting pyxel
Using cached https://files.pythonhosted.org/packages/3d/2f/25879681cf00bc1d607322b4c59a3cfd768fa9b092910fde72194332ed34/pyxel-0.7.4-py3-none-any.whl
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from pyxel)
Collecting PyOpenGL (from pyxel)
Collecting sounddevice (from pyxel)
Using cached https://files.pythonhosted.org/packages/fb/5d/0e6cf5ce99b99e76a24b573b94f9009d9d2f5cd13a73825d7e681c9a7a96/sounddevice-0.3.11-py2.py3-none-any.whl
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (from pyxel)
Collecting glfw (from pyxel)
Collecting CFFI>=1.0 (from sounddevice->pyxel)
Using cached https://files.pythonhosted.org/packages/6d/c0/47db8f624f3e4e2f3f27be03a93379d1ba16a1450a7b1aacfa0366e2c0dd/cffi-1.11.5-cp36-cp36m-manylinux1_x86_64.whl
Collecting pycparser (from CFFI>=1.0->sounddevice->pyxel)
Installing collected packages: PyOpenGL, pycparser, CFFI, sounddevice, glfw, pyxel
Successfully installed CFFI-1.11.5 PyOpenGL-3.1.0 glfw-1.7.0 pycparser-2.18 pyxel-0.7.4 sounddevice-0.3.11
OS info is as follows:
PRETTY_NAME="Debian GNU/Linux buster/sid"
NAME="Debian GNU/Linux"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
I gave the text() function a look in the codebase but nothing stuck out at me as a potential issue, and no errors are printed to stdout/stderr when I run the above program.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 23 (9 by maintainers)
@yeputons I imported your modification in v0.7.8. I hope it works in your environment.
Dirty hack that worked on my machine, see
shaders.py:327
:My assumption is that the problem is that texture values are floats between
0.0
and1.0
, and we want to distinguish 1/255ths. Unfortunately, 1/255 cannot be represented exactly and it turns out that1/255 * 255
(via OpenGL) is rounded down to 0 on my machine. This effect can be also noted when rendering images withblt
. Say, color 1 becomes 0, 2 becomes 1, 4 becomes 3. So, instead of rounding down withint()
, I now round to the approx. closest integer.I’m not exactly sure what causes that effect or even what are exact values returned by
texture2D() * 255.0
instead of1.0
. I think it should be something like0.9999
, but I haven’t checked and recommend further investigation (a hotfix may be landed in the meantime).cc @olgalupuleac