Pi3C is a fast, C++ graphics engine and toolkit tailored for all models of the Raspberry Pi and works on other platforms such as Windows. It's small size and innovative techniques make it fast enough to run highly detailed 3D games; even on the Pi Zero ...
Or, how about a Minecraft style game? ...
Pi3C is designed to be simple to use and encourage youngsters (or anyone) new to programming by exploring the basic tutorials, games and apps provided.
These range from a few lines of simple, self explained code to more complex, real-world and heavy-weight examples.
Pi3C tries to avoid the complexities of C++ by providing a top-level class called Pi3C. This class has simple commands to help you start your journey into the exciting world of C++ programming. Pi3C's utilizes the 'Simple DirectMedia Layer' (SDL 2.0) cross-platform development library (https://www.libsdl.org/).
Pi3C provides functions to render Open GLES 2.0 graphics using shaders. It also provides a high speed, Immediate Mode Graphics User Interface (IMGUI) with various buttons, text and common widgets. Using these functions, complex Apps and games can be made with relative ease.
Pi3C will also includes tools for 3D modelling and scene arrangemet with 1st person capabilites for testing scenes such as free flight, point and jump, and full screen renderng. Other tools planned will include an IMGUI interface designer and C++ code generator that will jump-start your project.
Pi3C is currently under heavy development and functions may/will change over time as new Apps, Games and Demos are developed. These developments will continue to greatly improve, enhance and simplify the Pi3C graphics engine and speed up your coding.
I hope that you will enjoy your experience with Pi3C as it develops!
- The main program
- Including stuff
- Compile & Run
With Pi3C you can write high speed 2D or 3D games. Or, you can write fast applications.
The following games can be explored in this repo ...
The following apps can be explored in this repo ...
- 3D Modeller
- Castle Creator
- Blocks (Minecraft experiment)
- MD viewer
C++ is one of the most popular, industry standard programming languages.
What you need and Setting up
You will need the following parts
- Raspberry Pi (preferably 3/4 for faster compiling)
- 5 volt, 2.5 amp power supply with Micro-USB connector
- Keyboard and Mouse
- Monitor or TV with HMDI
- HDMI cable
- 16GB or 32GB Micro-SD card
The easiest ways to download and modify Pi3C for your own use it use Git
Git is usually installed with the Raspberry Pi OS, but if not, download Git with;
sudo apt install git
Make sure you're in the 'home/pi' directory (indicated by the ~ (tilde character) with nothing after it) and enter;
git clone https://github.com/timskillman/Pi3C.git
Pi3C will be cloned onto your Pi and a Pi3C directory, with all the necessary code and resources, will be downloaded.
This will install all the SDL 2.0 libraries, configure your GPU memory and enable the video drivers for your particular Raspberry Pi.
Automatic Install (preferably a fresh RPi OS install)
Open a terminal window, navigate to the Pi3C folder and enter:
sudo sh Installer.sh
The installer does the following;
- Install the latest SDL2.0 libraries including Mixer, TTF, Image and Net (lines 9-12)
- Checks for Pi version (pione, pitwo, pizero, pifour) - (lines 14-37)
- Sets the OpenGL driver (lines 39-66)
- Sets the OpenGL memory GPU memory split to 64Mb (lines 69-78)
When prompted, type "Reboot" to restart your Raspberry Pi.
If you would like to install manually, then;
- Enter the following in a terminal;
apt-get update apt-get upgrade -y apt-get install libsdl2-dev libsdl2-mixer-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-net-dev -y
- Select the OpenGL renderer;
$ sudo raspi-config Pi 4 - Fake KMS driver PiZero to Pi3 - Buster and older: Full KMS driver Bullseye: Enable Glamor
- Ensure you have at least a 64MB for the graphics
Now you should be setup and ready to play with Pi3C ... Congratulations!
Trying the examples
Pi3C folders are laid out in the following way;
Examples (Example games, apps and demos in here) SharedCode (Pi3C core and helper code) Resources (Models, textures and sounds stored here) ThirdParty (Windows only - not needed on the Pi, but keep if developing on a Windows machine as well) MyProjects A place to put your projects and reference the Pi3C SharedCode
The Examples folder contains all the examples to try out.
So lets try out some examples!
Opening the Examples folder you will see several examples such as 'Castle Creator' and others. Let's try out Castle Creator first and see how it works ...
Open a terminal window (if already closed) and navigate to;
Run the Castlre Creator by entering ...
Note: If it doesn't work, you need to change CastleCreator's permissions and do the following ...
- In the desktop folder, navigate to 'CastleCreator' and click the right button and select 'Permissions'
- Under the Permissions tab, All three dropdowns should be set to 'Anyone' and then select OK.
- Try ./CastleCreator again and it should run
You will notice the 'options.txt' file and other txt files in the CastleCreator folder. If you feel adventurous, open these files and try changing the screen resolution or set fullscreen to 'true'. The 'options.txt' file is an easy way of customising a game or an app without having to recompile your code.
Try the other examples such as Blocks, Invaders, Snow, 3D modeller and others using the same info for CastleCreator.
Of course, we're trying out precompiled examples - so let's get coding your own stuff!
Build, Run and Clean
If setup correctly, Pi3C examples and tools should be ready to build and run.
To build a project do the following;
1. Enter the Project folder you want to build
Note: you don't need to type the whole word 'Invaders' ... type the first few characters such as 'Inv' and then press the TAB key ... this will auto-complete the word. You can do this shortcut for any part of a long pathname for example.
2. Build with 'make'
Make will build the whole project and all of its dependent code.
Dependent code in this case is 'SharedCode' containing Pi3C. If not built previously, Pi3C code will also build and it can take some time. However, this only happens once since the compiler is clever enough to only compile code that has changed after that.
Once built, you will notice a "_build" folder appearing next to the Pi3C folder. This folder contains all the object files created from the source. These files are then 'linked' together to create the final program.
You will also notice the built, executable file in your project folder.
To run the executable on the Raspberry Pi (Invaders for example), type;
Sometimes your project won't compile as expected - and that's not due to any bad coding! ... For example, when you update Pi3C the object files in the build folder need cleaning out. To clean the project entirely, type;
This basically deletes all the object files in the build folder (note: don't worrry, it won't delete anything important) Cleaning will ensure that all your built code is fresh and using the latest changes.
You should clean after updating Pi3C or making significant changes. However, it is not necessary if Pi3C SharedCode has not changed.
Keeping up-to-date with the latest code is simple. In a terminal window navigate to the Pi3C folder, and type;
git pull origin master
This command will import (pull) all the latest Pi3C changes from the GIT repository.