question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pyxel's text(x, y, string, color) function silently fails to print text to the screen.

See original GitHub issue

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:

2018-08-03-120320_1600x900_scrot

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kitaocommented, Aug 7, 2018

@yeputons I imported your modification in v0.7.8. I hope it works in your environment.

1reaction
yeputonscommented, Aug 6, 2018

Dirty hack that worked on my machine, see shaders.py:327:

-#define texture_color(index) int(texture2D(u_texture[index], uv).r * 255.0)
+#define texture_color(index) int(texture2D(u_texture[index], uv).r * 255.0 + 0.5)

My assumption is that the problem is that texture values are floats between 0.0 and 1.0, and we want to distinguish 1/255ths. Unfortunately, 1/255 cannot be represented exactly and it turns out that 1/255 * 255 (via OpenGL) is rounded down to 0 on my machine. This effect can be also noted when rendering images with blt. Say, color 1 becomes 0, 2 becomes 1, 4 becomes 3. So, instead of rounding down with int(), 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 of 1.0. I think it should be something like 0.9999, but I haven’t checked and recommend further investigation (a hotfix may be landed in the meantime).

cc @olgalupuleac

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I print colored text to the terminal? - Stack Overflow
I like sty and I am trying to format my string with sty, one issue is that , when I print multiple colors,...
Read more >
PySimpleGUI
import PySimpleGUI as sg sg.theme('DarkAmber') # Add a touch of color # All the stuff inside your window. layout = [ [sg.Text('Some text...
Read more >
DEVICE Procedure - IDL Reference - L3HarrisGeospatial.com
The DEVICE procedure provides device-dependent control over the current graphics device (as set by the SET_PLOT routine). The IDL graphics procedures and ...
Read more >
Annotated List of Command-line Options - ImageMagick
Below is list of command-line options recognized by the ImageMagick command-line tools. If you want a description of a particular option, ...
Read more >
3.1 Using Data Types - Introduction to Programming in Java
Color compatibility. The luminance value is also crucial in determining whether two colors are compatible, in the sense that printing text in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found