This project is a 3D software renderer implemented in C89 for the Playdate handheld gaming system. It provides a modular and efficient 3D graphics engine tailored for the Playdate's hardware capabilities.
- 2D and 3D vector operations
- Point projection and linear transformations
- Triangle and vertex handling
- Dynamic arrays for memory management
- Line drawing algorithms
- OBJ file parsing and rendering
- Triangle rasterization with depth sorting
- Matrix operations and 3D transformations
- Lighting and shading effects
- Texture mapping with perspective correction
- PNG file decoding for textures
- Z-buffer implementation
- Camera system and clipping
- Support for multiple meshes
- Optimized for Playdate hardware
Playdate-3D-Renderer/
│
├── CMakeLists.txt
├── README.md
├── .gitignore
├── docs/
└── Source/
├── include/
│ └── display.h
├── src/
│ ├── main.c
│ └── display.c
├── lib/
└── assets/
├── images/
├── sounds/
├── music/
└── levels/
- Visual Studio 2022
- CMake (version 3.10 or higher)
- Git
- Playdate SDK (version 2.5.0 or higher)
To build this project, you'll need the Playdate SDK and CMake installed on your system. Playdate Building on Windows
-
Set up the Playdate SDK:
- Download and install the Playdate SDK.
- Set the
PLAYDATE_SDK_PATH
andSDK
environment variables to point to your SDK installation.
-
Set up GNU ARM Embedded Toolchain
- Download and install the GNU Arm Embedded Toolchain.
- Set the
PLAYDATE_ARM_GCC
environment variable to point to C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10
-
Clone this repository:
git clone https://github.com/yourusername/3d-software-renderer-playdate.git cd 3d-software-renderer-playdate
-
Create a build directory and run CMake:
mkdir build cd build cmake ..
-
Build the project:
- For Visual Studio: Open the generated
.sln
file and build the project. - For Make: Run
make
in the build directory.
- For Visual Studio: Open the generated
-
To build for the Playdate device:
- Open a Visual Studio Developer Command Prompt from the Start Menu or from within Visual Studio
cmake .. -G "NMake Makefiles" --toolchain=C:/Users/Ramo/Documents/PlaydateSDK/C_API/buildsupport/arm.cmake -DCMAKE_BUILD_TYPE=Release nmake
-
The output will be a
.pdx
file, which can be run on the Playdate simulator or transferred to a Playdate device.
Comprehensive documentation can be found in the docs
directory. This includes:
- API documentation
- Implementation details
- Usage instructions and examples
- Performance considerations
This project follows a specific coding style to maintain consistency and readability:
-
C Standard: We use C89 (ANSI C) to ensure maximum compatibility with the Playdate SDK.
-
Naming Conventions:
- Use descriptive names for functions, variables, and types.
- Functions use camelCase:
updateGameState()
,drawPaddle()
. - Variables use camelCase:
playerScore
,ballSpeed
. - Constants and macros use UPPER_SNAKE_CASE:
MAX_PLAYERS
,INITIAL_BALL_SPEED
. - Typedef structs use PascalCase:
typedef struct { ... } GameState;
-
Braces: We use Allman style braces:
if (condition) { // code } else { // code }
-
Indentation: Use 4 spaces for indentation, not tabs.
-
Comments:
- Use C-style comments for multi-line explanations:
/* ... */
- Use C++-style comments for single-line comments:
// ...
- Each function should have a brief comment explaining its purpose.
- Use C-style comments for multi-line explanations:
-
File Structure:
- Each
.c
file should have a corresponding.h
file. - Use include guards in header files:
#ifndef GAME_H #define GAME_H // content #endif /* GAME_H */
- Each
-
Modularity: Keep functions small and focused on a single task. If a function grows too large, consider breaking it into smaller functions.
-
Error Handling: Use appropriate error handling mechanisms. Return error codes or use the Playdate SDK's error handling functions where appropriate.
-
Documentation: Use C-style documentation comments for functions in header files:
/** * @brief Updates the game state for one frame * @param game_state Pointer to the current game state * @param delta_time Time elapsed since last frame in seconds * @return 0 on success, non-zero error code on failure */ int update_game_state(GameState* game_state, float delta_time);
Please adhere to these guidelines when contributing to the project. Consistent style helps maintain code readability and makes collaboration easier.
Contributions are welcome! Please read the CONTRIBUTING.md file for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Playdate SDK developers
- Contributors to the Minunit.h testing library
For any questions or concerns, please open an issue on the GitHub repository.