Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
paddywwoof committed Jan 18, 2019
2 parents b463fb4 + 843d5aa commit 5dce5c2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 19 deletions.
14 changes: 9 additions & 5 deletions ReadMe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Setup on the Raspberry Pi
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo pip3 install pi3d
$ sudo raspi-config # set gpu_mem=128
$ sudo raspi-config # set gpu_mem=128 - keep the 'legacy' graphics driver

(or ``sudo pip install`` if you want to use python 2 for some reason).

Expand All @@ -178,7 +178,7 @@ Setup on the Raspberry Pi
$ sudo apt-get install python3-pip
$ sudo pip3 install pi3d
$ sudo pip3 install Pillow
$ sudo raspi-config # set gpu_mem=128
$ sudo raspi-config # set gpu_mem=128 - keep the 'legacy' graphics driver
####### download demos in their latest form, quicker #######
$ wget https://github.com/pi3d/pi3d_demos/archive/master.zip
Expand All @@ -190,6 +190,10 @@ Setup on the Raspberry Pi
$ cd ~/pi3d_demos
$ python3 Earth.py

**NB pi3d uses the original broadcom OpenGLES2 drivers** (as that's what the GPU hardware
actually runs) so if you use ``raspi-config`` to swap to the emulated
OpenGL driver it will give errors.

#. **Download, Extract and install**

Expand Down Expand Up @@ -245,9 +249,9 @@ Setup on the Raspberry Pi
doesn't run on python_3. The better equivalent replacement is Pillow.

As of raspbian jessie Pillow is the default imaging library. It's already
installed on the ``fully featured`` SD image, but if it's left off the
jessie lite image (rumoured to be in the pipeline) it can be installed
using the debian package manager::
installed on the ``fully featured`` SD image, but it's left off the
lite image it can be installed using the debian package manager
(for lite image you also need numpy)::

$ sudo apt-get install python3-pil

Expand Down
10 changes: 9 additions & 1 deletion pi3d/Display.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ def resize(self, x=0, y=0, w=0, h=0):
self.top = y
self.right = x + w
self.bottom = y + h
self.opengl.resize(x, y, w, h)
self.opengl.resize(x, y, w, h, self.layer)

def change_layer(self, layer=0):
self.layer = layer
self.opengl.change_layer(layer)

def add_sprites(self, *sprites):
"""Add one or more sprites to this Display."""
Expand Down Expand Up @@ -450,6 +454,9 @@ def create(x=None, y=None, w=None, h=None, near=None, far=None,
To use pygame for display surface, mouse and keyboard - as per windows
This almost certainly would conflict if attempting to use in combination
with tk=True. Default False
*layer*
display layer height - used by dispmanx on Raspberry Pi only. -128 will move the
pi3d window behind the X11 desktop
*display_config*
Configuration of display - See pi3d.constants for DISPLAY_CONFIG options
"""
Expand Down Expand Up @@ -546,6 +553,7 @@ def update(self):
display.top = y
display.right = x + w
display.bottom = y + h
display.layer = layer

display.opengl.create_display(x, y, w, h, depth=depth, samples=samples, layer=layer, display_config=display_config)
if PLATFORM == PLATFORM_ANDROID:
Expand Down
11 changes: 9 additions & 2 deletions pi3d/util/DisplayOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def create_surface(self, x=0, y=0, w=0, h=0, layer=0):
#Create viewport
opengles.glViewport(0, 0, w, h)

def resize(self, x=0, y=0, w=0, h=0):
def resize(self, x=0, y=0, w=0, h=0, layer=0):
# Destroy current surface and native window
openegl.eglSwapBuffers(self.display, self.surface)
if PLATFORM == PLATFORM_PI:
Expand All @@ -207,10 +207,17 @@ def resize(self, x=0, y=0, w=0, h=0):
bcm.vc_dispmanx_display_close(self.dispman_display)

#Now recreate the native window and surface
self.create_surface(x, y, w, h)
self.create_surface(x, y, w, h, layer)
elif PLATFORM == PLATFORM_ANDROID:
pass #TODO something here

def change_layer(self, layer=0):
if PLATFORM == PLATFORM_PI:
self.dispman_update = bcm.vc_dispmanx_update_start(0)
bcm.vc_dispmanx_element_change_layer(self.dispman_update,
self.dispman_element, layer)
bcm.vc_dispmanx_update_submit_sync(self.dispman_update)


def destroy(self, display=None):
if self.active:
Expand Down
33 changes: 23 additions & 10 deletions pi3d/util/Font.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

MAX_SIZE = 1920

def _strengthen(x):
# used if shadow required to slightly harden edges
F = 0.5
return int(x * (1 + F - F * x / 256))

class Font(Texture):
"""
A Font contains a TrueType font ready to be rendered in OpenGL.
Expand All @@ -27,10 +32,10 @@ class Font(Texture):
then creates a table mapping codepoints to subrectangles of that Texture."""

def __init__(self, font, color=(255,255,255,255), codepoints=None,
add_codepoints=None, font_size=42, image_size=512,
add_codepoints=None, font_size=None, image_size=1024,
italic_adjustment=1.1, background_color=None,
shadow=(0,0,0,255), shadow_radius=0, spacing=None,
mipmap=True, filter=None):
mipmap=True, filter=None, grid_size=16):
"""Arguments:
*font*:
File path/name to a TrueType font file.
Expand Down Expand Up @@ -96,9 +101,15 @@ def __init__(self, font, color=(255,255,255,255), codepoints=None,
*filter*:
Resulting texture filter option, default None
*grid_size*
number rows and cols to divide 1024 pixels. For high res fonts this can be
changed 4 -> 16chars, 8 -> 64chars, 10 -> 100chars etc.
"""
super(Font, self).__init__(font, mipmap=mipmap, filter=filter)
self.font = font
if font_size is None:
font_size = int(672 / grid_size) # i.e. 16x16 has font size 42
try:
imgfont = ImageFont.truetype(font, font_size)
except IOError:
Expand All @@ -113,18 +124,19 @@ def __init__(self, font, color=(255,255,255,255), codepoints=None,
if spacing is None:
spacing = shadow_radius
self.height = ascent + descent + spacing # allow extra pixels if shadow or for certain fonts
self.spacing = 64

image_size = self.spacing * 16 # or 1024 TODO this may go wrong if self.height != 64
self.grid_size = grid_size
num_char = self.grid_size ** 2
image_size = 1024 # fixed value despite having as argument! TODO allow variable size now grid_size variable
self.spacing = image_size / self.grid_size

if codepoints is not None:
codepoints = list(codepoints)
codepoints = list(codepoints)[:num_char]
else:
codepoints = list(range(256))
codepoints = list(range(num_char))
if add_codepoints is not None:
add_codepoints = list(add_codepoints)
if (len(codepoints) + len(add_codepoints)) > 256: # make room at end
codepoints = codepoints[:(256 - len(add_codepoints))]
if (len(codepoints) + len(add_codepoints)) > num_char: # make room at end
codepoints = codepoints[:(num_char - len(add_codepoints))]
codepoints += add_codepoints

is_draw_shadows = shadow_radius > 0
Expand Down Expand Up @@ -183,7 +195,7 @@ def __init__(self, font, color=(255,255,255,255), codepoints=None,
self.glyph_table[ch] = table_entry

xindex += 1
if xindex >= 16:
if xindex >= self.grid_size:
xindex = 0
yindex += 1

Expand All @@ -196,6 +208,7 @@ def __init__(self, font, color=(255,255,255,255), codepoints=None,
shadow_img = self._force_color(shadow_img, shadow)

shadow_img = shadow_img.filter(ImageFilter.GaussianBlur(radius=shadow_radius))
shadow_img = Image.eval(shadow_img, _strengthen) # slightly sharpen edge of blur - see func def at top

self.im = Image.alpha_composite(shadow_img, self.im)

Expand Down
2 changes: 1 addition & 1 deletion pi3d/util/PointText.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, font, camera, max_chars=100, point_size=48):
self.text = Points(camera=camera, vertices=self.locations, normals=self.normals,
tex_coords=self.uv, point_size=self.point_size)
self.text.set_draw_details(self.shader, [self.font])
self.text.unif[48] = 0.058 # used to hold "patch size" passed to shader
self.text.unif[48] = 0.928 / self.font.grid_size # used to hold "patch size" passed to shader - margin to allow rotating
#Reset all characters to space so there are no false character shadows
try:
glyph = self.font.glyph_table[' '] #u' ' doesn't work on python3.2!!
Expand Down

0 comments on commit 5dce5c2

Please sign in to comment.