Skip to content

A lightweight, flexible 2D graphics framework built on SDL3, designed to make game and application development fast and intuitive with modern C++20 features.

License

Notifications You must be signed in to change notification settings

CatIsNotFound/MyEngine

Repository files navigation

MyEngine

简体中文

C++20 SDL3 License

cover

MyEngine is a lightweight yet powerful 2D graphics framework built on top of SDL3 and its extensions. Designed for simplicity and flexibility, it provides an intuitive object-oriented API that makes game and application development fast and enjoyable. Leveraging modern C++20 features, MyEngine offers a modular architecture that allows developers to easily create interactive graphics applications with minimal boilerplate code.

Environment Dependencies

To use this third-party library, you need to install the following dependencies:

Quick Start

Getting Binary Version

Currently, no official version has been released yet. It is expected to be released early next year.

Precompiled versions can be obtained through Github Release or Gitee Release pages.

Source Repository Installation

  1. Clone the project using Git

    git clone https://github.com/CatIsNotFound/MyEngine

    Or clone the project using the following URL:

    git clone https://gitee.com/CatIsNotFound/MyEngine
  2. Configure the project using CMake

    cd MyEngine
    mkdir build ; cd build
    cmake .. -DCMAKE_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX="/path/to/MyEngine" -DSDL3_LIB=/path/to/SDL3 -DSDL3_IMAGE_LIB=/path/to/SDL3_image -DSDL3_MIXER_LIB=/path/to/SDL3_mixer -DSDL3_TTF_LIB=/path/to/SDL3_ttf

    ❗ Note:

    You need to replace the static library paths for CMAKE_INSTALL_PREFIX, SDL3_LIB, SDL3_IMAGE_LIB, SDL3_TTF_LIB, and SDL3_MIXER_LIB.

  3. Compile and install the project

    cmake --build . --config install

Minimal Example Test

  1. Create a new CMakeLists.txt file and write the following content:

     cmake_minimum_required(VERSION 3.24)
     # Need to modify your project name.
     project(Demo)
     
     set(CMAKE_CXX_STANDARD 20)
     
     # Need to set these paths before cmake configuration.
     set(SDL3_DIR       "/path/to/SDL3")
     set(SDL3_IMAGE_DIR "/path/to/SDL3_image")
     set(SDL3_TTF_DIR   "/path/to/SDL3_ttf")
     set(SDL3_MIXER_DIR "/path/to/SDL3_mixer")
     set(MYENGINE_DIR      "/path/to/MyEngine")
     set(CMAKE_INCLUDE_CURRENT_DIR ON)
     
     list(APPEND CMAKE_PREFIX_PATH ${SDL3_DIR})
     list(APPEND CMAKE_PREFIX_PATH ${SDL3_IMAGE_DIR})
     list(APPEND CMAKE_PREFIX_PATH ${SDL3_TTF_DIR})
     list(APPEND CMAKE_PREFIX_PATH ${SDL3_MIXER_DIR})
     list(APPEND CMAKE_PREFIX_PATH ${MYENGINE_DIR})
     
     find_package(SDL3 REQUIRED)
     find_package(SDL3_image REQUIRED)
     find_package(SDL3_ttf REQUIRED)
     find_package(SDL3_mixer REQUIRED)
     find_package(MyEngine REQUIRED)
     
     add_executable(${PROJECT_NAME}
             main.cpp
     )
     
     target_link_libraries(${PROJECT_NAME} PRIVATE
             SDL3::SDL3
             SDL3_image::SDL3_image
             SDL3_ttf::SDL3_ttf
             SDL3_mixer::SDL3_mixer
             MyEngine::MyEngine
     )
    
     if (WIN32)
     set(POST_BUILD_COMMANDS
             COMMAND ${CMAKE_COMMAND} -E copy_directory ${SDL3_LIB}/bin ${CMAKE_BINARY_DIR}/bin
             COMMAND ${CMAKE_COMMAND} -E copy_directory ${SDL3_MIXER_LIB}/bin ${CMAKE_BINARY_DIR}/bin
     )
     if (MINGW)
         list(APPEND POST_BUILD_COMMANDS
                 COMMAND ${CMAKE_COMMAND} -E copy_directory ${SDL3_IMAGE_LIB}/x86_64-w64-mingw32/bin ${CMAKE_BINARY_DIR}/bin
                 COMMAND ${CMAKE_COMMAND} -E copy_directory ${SDL3_TTF_LIB}/x86_64-w64-mingw32/bin ${CMAKE_BINARY_DIR}/bin
         )
     else ()
         list(APPEND POST_BUILD_COMMANDS
                 COMMAND ${CMAKE_COMMAND} -E copy_directory ${SDL3_IMAGE_LIB}/bin ${CMAKE_BINARY_DIR}/bin
                 COMMAND ${CMAKE_COMMAND} -E copy_directory ${SDL3_TTF_LIB}/bin ${CMAKE_BINARY_DIR}/bin
         )
     endif()
    
     add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
             ${POST_BUILD_COMMANDS}
     )
     endif()
  2. Edit the main.cpp file:

    #include <MyEngine/MyEngine>
    
    using namespace MyEngine;
    
    int main() {
        Engine engine;
        auto win = new Window(&engine, "Hello world!");
        win->installPaintEvent([](Renderer* r) {
            r->fillBackground(StdColor::DarkBlue);
            r->drawPixelText("Hello world!", {20, 20});		    
        });
        return engine.exec();
    }
  3. Test and run the entire project, for example using the command line:

    cd /path/to/YourProject
    mkdir build ; cd build
    cmake ..
    cmake --build .
    ./YourProject
  4. This will open the window shown in the figure below. If it displays successfully, it means that the operation has been successful! screenshot.png

License

This project is licensed under the MIT open source license. See the LICENSE file for details.

Getting Help

  1. Check the documentation for related API documentation. (Content not updated)
  2. Submit issues through Github Issue or Gitee Issues.

About

A lightweight, flexible 2D graphics framework built on SDL3, designed to make game and application development fast and intuitive with modern C++20 features.

Resources

License

Stars

Watchers

Forks

Packages

No packages published