0

I'm using Buildroot 2018.02 to create a custom Linux to run my raspberry pi 3.

I'm trying to display a pygame window on the external hdmi screen from command line.

So far, I've been able to boot the pi3 with the default configuration running make raspberrypi3_defconfig, I've just changed the toolchain to use glibc instead of uClibc-ng.

Flashing the first default configuration

make raspberrypi3_defconfig
make menuconfig
make
dd if=output/images/sdcard.img of=/dev/sdb bs=4M

The rpi boot well, I can log as root using a FTDI cable.

Adding pygame ans ssh support

I run make menuconfig to select both open-ssh and python3 packages and I select the external python3 package python-pygame

After reflashing, the rpi boots well and I can connect through ssh.

At this moment nothing is printed on the hdmi screen. If I open a pygame window running a python3 shell nothing happens.

# python3
Python 3.6.3 (default, Jun 17 2018, 20:05:31) 
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> screen = pygame.display.set_mode((300, 200))
>>> pygame.display.flip()
>>> quit()
# 

Adding X.org support

I have then enabled X.org X Window System with the following configuration.

BR2_PACKAGE_XAPP_TWM=y
BR2_PACKAGE_XAPP_XCALC=y
BR2_PACKAGE_XAPP_XCLOCK=y
BR2_PACKAGE_XAPP_XEYES=y
BR2_PACKAGE_XAPP_XINIT=y
BR2_PACKAGE_XDRIVER_XF86_INPUT_KEYBOARD=y
BR2_PACKAGE_XDRIVER_XF86_INPUT_MOUSE=y
BR2_PACKAGE_XDRIVER_XF86_VIDEO_CIRRUS=y
BR2_PACKAGE_XDRIVER_XF86_VIDEO_FBDEV=y
BR2_PACKAGE_XDRIVER_XF86_VIDEO_VESA=y
BR2_PACKAGE_XORG7=y
BR2_PACKAGE_XSERVER_XORG_SERVER=y
BR2_PACKAGE_XTERM=y

At this moment, when the rpi3 boot, I can see kernel logs on the hdmi screen. If I run startx from command line, several windows appear as follow enter image description here

However if I run again the python instructions above, the screen become totally black.
If I quit the python shell, the screen returns to the picture state.

I have also tried after exporting display with export DISPLAY=:0.0 but with the same result.

If I don't run startx the result is the same except that console log replace the windows on the picture.

What else could I do to be able to display a pygame window from command line ?

0

Pygame is not a framework where button, frame and windows are already defined. It is a more low level access to the framebuffer.

To use pygame with the framebuffer you should write something into it. Basically, your program only declares the screen (which is initially black) and... do nothing else.

You should use blit to write/place texts and images to the framebuffer. Then call flip to actually show/render your screen.

A basic example is as follow :

import pygame
from pygame.locals import *

pygame.display.init() ;

(width,height) = (800,480)
screen = pygame.display.set_mode((width, height))

pygame.font.init()
font = pygame.font.SysFont("cantarell", 24)

text = font.render('Text to show',True,(200,0,0))
image = pygame.image.load ('image.jpg')

while True:
    # clear the screen
    screen.fill((0, 0, 0))
    # place the image
    screen.blit(image, (0, 0))
    # the the image
    screen.blit(text,(10,450))
    # render/update the display
    pygame.display.flip()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.