AshPowers
Posts: 76
Joined: Thu Apr 20, 2017 12:10 am
Location: Ormond Beach, FL
Contact: Website

pi3d - Sprites laying over textblock????

Fri May 05, 2017 6:35 pm

pi3d.textblock is being "overdrawn" by pi3d.imagesprite

text is actually on the screen, behind the "background" sprite that takes up the entire display area. Other sprites are showing up along with the background sprite. When I do not draw the background sprite, I can see my textblock right there on the screen so I know it is placing the textblock properly and displaying it - it is just being overwritten by the sprites.

I have tried drawing the textblock both before and after drawing the background sprite but no joy.

Not using any 3d components - pi3d just draws a LOT faster than pygame blit.
pi3d.Camera(is_3d=False)

Code: Select all

text = pi3d.PointText(pointFont, CAMERA, max_chars=200, point_size=64)
newtext = pi3d.TextBlock(-200, 200, 2, 0.0, 10, data_obj-eg_object, attr="fps",
                  text_format="fps:{2.1f}", size = 0.99, spacing = "C", space=1.1,
                  colour=(1, 1, 1, 1.0))
text.add_text_block(newtext)
text.draw()

background = pi3d.ImageSprite("background08-s", shader, w=1920, h=720, z=2)

while Display.loop_running():
text.regen()
text.draw()
background.draw()

User avatar
paddyg
Posts: 1918
Joined: Sat Jan 28, 2012 11:57 am

Re: pi3d - Sprites laying over textblock????

Sat May 06, 2017 9:42 am

@AshPowers, thanks for struggling on with various pi3d quirks; I will add them to the FAQ for the sake of others.

The lack of GPU memory symptoms are so varied they're quite hard to figure out, especially if you're just getting to grips with a new module.

The PointText/TextBlock system that Matt developed is very fast and flexible but also quite complicated, especially hard to follow as the demo tries to showcase all the features! One subtlety that isn't obvious is the fact that 'extra' info is being shoehorned into the array passed to the shader, critically the z value of each vertex (i.e. each character) contains both the depth *and* the size. Coupled with the use of medium precision floats this means that the behaviour of the depth and size values of TextBlock seem very strange.

Depth as specified in TextBlock doesn't match up with the normal depth of 2D objects such as ImageSprite (this is different from the 2D v 3D depth difference mentioned here) Keep the TextBlock z values small and the other objects large (i.e. 0.5 may be in front of normal 2D z of 6.0 but behind 5.9 so play safe with a value of 50.0)

Size varies from 0.05 to 0.99 (subject to float precision) however if you use a size of more than 1.0 it will effect the spacing! Try using 0.99, 1.99, 2.99 etc.

Code: Select all

import pi3d
import time

class EgClass(object):
  def __init__(self):
    self.fps, self.st, self.fr = 0.0, None, None
  def update(self):
    if not self.st:
      self.st = time.time()
      self.fr = 0
    else:
      self.fr += 1
      self.fps = self.fr / (time.time() - self.st)

eg_object = EgClass() # create an instance of the example class

DISPLAY = pi3d.Display.create()
CAMERA = pi3d.Camera(is_3d=False)
shader = pi3d.Shader('uv_flat')
pointFont = pi3d.Font('fonts/NotoSans-Regular.ttf')

text = pi3d.PointText(pointFont, CAMERA, max_chars=200, point_size=64)
newtext = pi3d.TextBlock(-200, 200, 0.1, 0.0, 10, data_obj=eg_object, attr="fps",
          text_format="fps:{:2.1f}", size=0.99, spacing="C", space=1.1,
          colour=(1, 1, 1, 1.0))
text.add_text_block(newtext)

background = pi3d.ImageSprite("textures/PATRN.PNG", shader, w=1920, h=720, z=2)

while DISPLAY.loop_running():
  text.regen()
  background.draw() # blend edges of text by drawing after background.
  text.draw()
  eg_object.update()
Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

AshPowers
Posts: 76
Joined: Thu Apr 20, 2017 12:10 am
Location: Ormond Beach, FL
Contact: Website

Re: pi3d - Sprites laying over textblock????

Sat May 06, 2017 12:43 pm

Hi Paddy!
I feel a bit starstruck! I've seen SO many of your posts since picking up this RPi3 three weeks ago and all of the searches I've done while picking up Python - immensly helpful!. :) I have been on this project some 200+ hours already in that time and over 300 lines of solid code in this automotive dashboard program now.

https://www.youtube.com/watch?v=QmEUdLDB-uM

It took me a couple of hours to trim down my program to just the basics, with only one sprite and one textblock and finally figured out the quirks with the "Z" component to get it working, just as you have pointed out.

The video above was taken before switching from strings to textblock for the digital value production but you get the gist. :) Now if I can just get this bluetooth rfcomm exception handling code running solid, I'll be in the game. (Working on using my Android smartphone as the remote control for this to setup boost control and other options).

User avatar
paddyg
Posts: 1918
Joined: Sat Jan 28, 2012 11:57 am

Re: pi3d - Sprites laying over textblock????

Sat May 06, 2017 4:28 pm

That dashboard looks amazing, it's really uplifting to see the stuff people do with the Raspberry Pi, especially if they've not been coding long (three weeks of python is very little to be fixing things like this).

On your serial try catch question. You've probably sorted it out from douglas and daves' posts, but I think you need to do your serial opening outside the while loop then do *everything* to the serial object inside a try (especially attempting to read it). You can then look at the exception and try to re-open the serial connection a few times (put in a sleep and a counter variable) and eventually give up gracefully shutting other things down.

Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

AshPowers
Posts: 76
Joined: Thu Apr 20, 2017 12:10 am
Location: Ormond Beach, FL
Contact: Website

Re: pi3d - Sprites laying over textblock????

Sat May 06, 2017 6:59 pm

Hi Paddy!

Thanks for the feedback! Yes, I did get things sorted out with the bluetooth connection. Silly oversight on my part.

However, I have come across something with pi3d again...

Is there a limit to how many textblock items you can create? It seems that it will only allow 10. I've tried every way, and sideways, to try and get it to produce an 11th textblock and no joy. Program bombs out, code: 1..

-Ash

User avatar
paddyg
Posts: 1918
Joined: Sat Jan 28, 2012 11:57 am

Re: pi3d - Sprites laying over textblock????

Sat May 06, 2017 8:35 pm

Ash, I can't think of a specific limit for the number of TextBlocks you can add to one PointText object. In pi3d_demos.StringMulti.py there are 13 and it seems to work OK when I add several more. However when you create the PointText you have to specify the maximum number of characters in total, as this creates a buffer object to pass to the GPU. This point based text system works fast because it doesn't have to recreate a new buffer each time the text changes or moves, it just runs https://github.com/tipam/pi3d/blob/mast ... er.py#L126 which is much quicker.

Let me know if this doesn't fix the problem.

Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

AshPowers
Posts: 76
Joined: Thu Apr 20, 2017 12:10 am
Location: Ormond Beach, FL
Contact: Website

Re: pi3d - Sprites laying over textblock????

Sat May 06, 2017 9:11 pm

Hi Paddy,

The last two TextBlock entries were for date and time and I removed the "text_format" section as those data types are already formatted. For the new textblock definition I just copied the last entry (for date) and set its attr to a different data object name.. But the boost pressure digital value coming from the ADS1256 needs to be formatted. Adding back the text_format="{2.1f}" corrected the issue. Another ID ten T error. :P

But it is good to know about the maximum number of characters parameter. The 13 character value used in the pi3d example fortunately is large enough to hold each of the data values so it never became an issue.. Lucky me! HA! :)

Thanks again!

Return to “Python”

Who is online

Users browsing this forum: No registered users and 13 guests