New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mattjquinn opened this Issue Aug 3, 2018 · 23 comments

Comments

Projects
None yet
6 participants
@mattjquinn

mattjquinn commented Aug 3, 2018

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.

@mattjquinn mattjquinn changed the title from Pyxel's text(x, y, string, col) function silently fails to print text to the screen. to Pyxel's text(x, y, string, color) function silently fails to print text to the screen. Aug 3, 2018

@KevinVanKiwi

This comment has been minimized.

Show comment
Hide comment
@KevinVanKiwi

KevinVanKiwi Aug 3, 2018

Just checked it on my system and it works for me, which is strange.

  • Win10
  • Python 3.6.2
  • pyxel 0.7.4

pyxel-180803-202815

Code is the same:

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)

KevinVanKiwi commented Aug 3, 2018

Just checked it on my system and it works for me, which is strange.

  • Win10
  • Python 3.6.2
  • pyxel 0.7.4

pyxel-180803-202815

Code is the same:

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)

@kitao kitao added the bug label Aug 4, 2018

@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 4, 2018

Owner

@mattjquinn Hi, what will happen when the example #3 (draw api sample) runs on your environment?

Owner

kitao commented Aug 4, 2018

@mattjquinn Hi, what will happen when the example #3 (draw api sample) runs on your environment?

@mattjquinn

This comment has been minimized.

Show comment
Hide comment
@mattjquinn

mattjquinn Aug 4, 2018

Example #3 also has missing text. It also appears that clip() doesn't work either, though the screen changes colors and one of the sprites moves as expected:

2018-08-04-135618_1600x900_scrot

Example #1 is also missing the top line of text as well:

2018-08-04-135547_1600x900_scrot

mattjquinn commented Aug 4, 2018

Example #3 also has missing text. It also appears that clip() doesn't work either, though the screen changes colors and one of the sprites moves as expected:

2018-08-04-135618_1600x900_scrot

Example #1 is also missing the top line of text as well:

2018-08-04-135547_1600x900_scrot

@matju

This comment has been minimized.

Show comment
Hide comment
@matju

matju Aug 4, 2018

I have a similar issue - except I'm on MacOS Sierra. brew and pip3 installed everything OK.

In my case:

  • Example 1 doesn't render any text
  • Clipping doesn't work for Example 3
  • Some fragments of text are rendered for Example 3 (see screenshot)
  • Example 3's circles don't render properly

pyxel-180804-130423

matju commented Aug 4, 2018

I have a similar issue - except I'm on MacOS Sierra. brew and pip3 installed everything OK.

In my case:

  • Example 1 doesn't render any text
  • Clipping doesn't work for Example 3
  • Some fragments of text are rendered for Example 3 (see screenshot)
  • Example 3's circles don't render properly

pyxel-180804-130423

@timbledum

This comment has been minimized.

Show comment
Hide comment
@timbledum

timbledum Aug 5, 2018

Fine on my mac at home, but getting no text displayed on my windows 10 work computer. No install issues. Tried on 3.6 and 3.7, including fresh environment.

capture

Do we have opengl version issues perhaps? I'm finding it hard to figure out what version is installed on windows though.

timbledum commented Aug 5, 2018

Fine on my mac at home, but getting no text displayed on my windows 10 work computer. No install issues. Tried on 3.6 and 3.7, including fresh environment.

capture

Do we have opengl version issues perhaps? I'm finding it hard to figure out what version is installed on windows though.

@matju

This comment has been minimized.

Show comment
Hide comment
@matju

matju Aug 5, 2018

In my case I'm running MacOS 10.12.6 on a MacBook Pro (13-inch, 2016, Four Thunderbolt 3 ports) with Intel Iris Graphics 550 - apparently this supports OpenGL 4.1.

brew list --versions reports python 3.7.0 and glfw 3.2.1.

pip3 list reports:

Package     Version
----------- -------
cffi        1.11.5 
glfw        1.7.0  
numpy       1.15.0 
Pillow      5.2.0  
pip         18.0   
pycparser   2.18   
PyOpenGL    3.1.0  
pyxel       0.7.6  
setuptools  40.0.0 
sounddevice 0.3.11 
wheel       0.31.1 

matju commented Aug 5, 2018

In my case I'm running MacOS 10.12.6 on a MacBook Pro (13-inch, 2016, Four Thunderbolt 3 ports) with Intel Iris Graphics 550 - apparently this supports OpenGL 4.1.

brew list --versions reports python 3.7.0 and glfw 3.2.1.

pip3 list reports:

Package     Version
----------- -------
cffi        1.11.5 
glfw        1.7.0  
numpy       1.15.0 
Pillow      5.2.0  
pip         18.0   
pycparser   2.18   
PyOpenGL    3.1.0  
pyxel       0.7.6  
setuptools  40.0.0 
sounddevice 0.3.11 
wheel       0.31.1 
@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 6, 2018

Owner

@matju Appearently, you environment has enough specs to run Pyxel.

Now I'm wondering there is some informal OpenGL code and it causes this bug.

Could you try change line 139 of the example #3 from pyxel.blt(x, y, 0, 0, 0, 16, 16) to pyxel.blt(x, y, 4, 0, 0, 16, 16)?

By this change, Pyxel draws the system font texture with blt command.
If some characters with blue color are shown, it means the system font texture is available and the shader for text has some problem. If not, the system font texture has some problem.

Owner

kitao commented Aug 6, 2018

@matju Appearently, you environment has enough specs to run Pyxel.

Now I'm wondering there is some informal OpenGL code and it causes this bug.

Could you try change line 139 of the example #3 from pyxel.blt(x, y, 0, 0, 0, 16, 16) to pyxel.blt(x, y, 4, 0, 0, 16, 16)?

By this change, Pyxel draws the system font texture with blt command.
If some characters with blue color are shown, it means the system font texture is available and the shader for text has some problem. If not, the system font texture has some problem.

@mattjquinn

This comment has been minimized.

Show comment
Hide comment
@mattjquinn

mattjquinn Aug 6, 2018

@kitao Using OpenGL 4.2, I made the change to line 139; only difference was the first cat being replaced by a black square:

2018-08-06-074258_1600x900_scrot

Output of glxinfo is

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile 
OpenGL core profile version string: 4.2 (Core Profile) Mesa 17.3.6
OpenGL core profile shading language version string: 4.20
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 17.3.6
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 17.3.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
OpenGL ES profile extensions:

Is there any advice you can give us for debugging issues with system font resources that Pyxel expects to be present?

mattjquinn commented Aug 6, 2018

@kitao Using OpenGL 4.2, I made the change to line 139; only difference was the first cat being replaced by a black square:

2018-08-06-074258_1600x900_scrot

Output of glxinfo is

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile 
OpenGL core profile version string: 4.2 (Core Profile) Mesa 17.3.6
OpenGL core profile shading language version string: 4.20
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 17.3.6
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 17.3.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
OpenGL ES profile extensions:

Is there any advice you can give us for debugging issues with system font resources that Pyxel expects to be present?

@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 6, 2018

Owner

@mattjquinn Thank you! It seems that the image bank #5 of Pyxel is not available.
Potential possibility is your environment doesn't allow to use five textures at the same time, or shader setting of Pyxel for textures is informal OpenGL code.

If possible, could you change line.40 of constants.py of Pyxel from `RENDERER_IMAGE_COUNT = 5' to 'RENDERER_IMAGE_COUNT = 2'?

If the example #3 works by this change, the cause is the number of the texture unit.

Owner

kitao commented Aug 6, 2018

@mattjquinn Thank you! It seems that the image bank #5 of Pyxel is not available.
Potential possibility is your environment doesn't allow to use five textures at the same time, or shader setting of Pyxel for textures is informal OpenGL code.

If possible, could you change line.40 of constants.py of Pyxel from `RENDERER_IMAGE_COUNT = 5' to 'RENDERER_IMAGE_COUNT = 2'?

If the example #3 works by this change, the cause is the number of the texture unit.

@mattjquinn

This comment has been minimized.

Show comment
Hide comment
@mattjquinn

mattjquinn Aug 6, 2018

No luck @kitao; after decreasing from 5 to 2, the only difference is that the background behind the first cat is gray:

2018-08-06-081121_1600x900_scrot

So you're saying that since this doesn't work, I should look into environment limitations on using five textures at the same time?

mattjquinn commented Aug 6, 2018

No luck @kitao; after decreasing from 5 to 2, the only difference is that the background behind the first cat is gray:

2018-08-06-081121_1600x900_scrot

So you're saying that since this doesn't work, I should look into environment limitations on using five textures at the same time?

@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 6, 2018

Owner

@mattjquinn Sorry! You also need to the example #3.

Now, the System Font image number is 1, so please change the same line of the example #3 to pyxel.blt(x, y, 1, 0, 0, 16, 16).

Owner

kitao commented Aug 6, 2018

@mattjquinn Sorry! You also need to the example #3.

Now, the System Font image number is 1, so please change the same line of the example #3 to pyxel.blt(x, y, 1, 0, 0, 16, 16).

@mattjquinn

This comment has been minimized.

Show comment
Hide comment
@mattjquinn

mattjquinn Aug 6, 2018

Still no luck: first cat is now completely blacked out:

2018-08-06-081849_1600x900_scrot

mattjquinn commented Aug 6, 2018

Still no luck: first cat is now completely blacked out:

2018-08-06-081849_1600x900_scrot

@matju

This comment has been minimized.

Show comment
Hide comment
@matju

matju Aug 6, 2018

@kitao If I change line 139 of example 3 to pyxel.blt(x, y, 4, 0, 0, 16, 16) then the first cat is replaced with some faint blue text:

pyxel-180806-073320

matju commented Aug 6, 2018

@kitao If I change line 139 of example 3 to pyxel.blt(x, y, 4, 0, 0, 16, 16) then the first cat is replaced with some faint blue text:

pyxel-180806-073320

@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 6, 2018

Owner

@matju Thank you for checking. This is the image I expected. So in your case, the number of the texture or size may be the cause. (Though I don't know it can cause breaking text rendering like this.)

Could you try to just change the `RENDERER_IMAGE_COUNT' of constant.py to some number less than 5 to make sure the number of the texture cause this?

Owner

kitao commented Aug 6, 2018

@matju Thank you for checking. This is the image I expected. So in your case, the number of the texture or size may be the cause. (Though I don't know it can cause breaking text rendering like this.)

Could you try to just change the `RENDERER_IMAGE_COUNT' of constant.py to some number less than 5 to make sure the number of the texture cause this?

@yeputons

This comment has been minimized.

Show comment
Hide comment
@yeputons

yeputons 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

yeputons commented 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

@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 6, 2018

Owner

Hi, @yeputons
Thank you for good information! I understood what happen in your environment.
So in your environment, all color drawn with blt and text command changes rather than text is not drawn?

Owner

kitao commented Aug 6, 2018

Hi, @yeputons
Thank you for good information! I understood what happen in your environment.
So in your environment, all color drawn with blt and text command changes rather than text is not drawn?

@yeputons

This comment has been minimized.

Show comment
Hide comment
@yeputons

yeputons Aug 7, 2018

@kitao Color drawn with blt changes, yes, but text is not drawn at all: font is passed through a texture with 0/1 values, and 1 gets rounded down to 0 in texture_color, so the shader assumes that all pixels are zero and does not draw anything.

yeputons commented Aug 7, 2018

@kitao Color drawn with blt changes, yes, but text is not drawn at all: font is passed through a texture with 0/1 values, and 1 gets rounded down to 0 in texture_color, so the shader assumes that all pixels are zero and does not draw anything.

@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 7, 2018

Owner

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

Owner

kitao commented Aug 7, 2018

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

@timbledum

This comment has been minimized.

Show comment
Hide comment
@timbledum

timbledum Aug 7, 2018

This fixed it for me!

timbledum commented Aug 7, 2018

This fixed it for me!

@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 7, 2018

Owner

Good!

Owner

kitao commented Aug 7, 2018

Good!

@kitao kitao closed this Aug 7, 2018

@kitao kitao reopened this Aug 7, 2018

@mattjquinn

This comment has been minimized.

Show comment
Hide comment
@mattjquinn

mattjquinn Aug 8, 2018

Yes fixed for me as well.

mattjquinn commented Aug 8, 2018

Yes fixed for me as well.

@kitao kitao closed this Aug 8, 2018

@matju

This comment has been minimized.

Show comment
Hide comment
@matju

matju Aug 8, 2018

Sorry to disappoint but I have the same problem in Pyxel 0.7.8...

pyxel-180808-234521

$ pip3 list
Package     Version
----------- -------
cffi        1.11.5 
glfw        1.7.0  
numpy       1.15.0 
Pillow      5.2.0  
pip         18.0   
pycparser   2.18   
PyOpenGL    3.1.0  
pyxel       0.7.8  
setuptools  40.0.0 
sounddevice 0.3.11 
wheel       0.31.1 

matju commented Aug 8, 2018

Sorry to disappoint but I have the same problem in Pyxel 0.7.8...

pyxel-180808-234521

$ pip3 list
Package     Version
----------- -------
cffi        1.11.5 
glfw        1.7.0  
numpy       1.15.0 
Pillow      5.2.0  
pip         18.0   
pycparser   2.18   
PyOpenGL    3.1.0  
pyxel       0.7.8  
setuptools  40.0.0 
sounddevice 0.3.11 
wheel       0.31.1 
@kitao

This comment has been minimized.

Show comment
Hide comment
@kitao

kitao Aug 8, 2018

Owner

@matju In your case, texts are drawn partially and circles are not drawn. So I split your case as #45
Let me ask more information in #45

Owner

kitao commented Aug 8, 2018

@matju In your case, texts are drawn partially and circles are not drawn. So I split your case as #45
Let me ask more information in #45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment