Skip to content

Cross-Platform Library for Development with SDL2/OpenGL in C++20

License

Notifications You must be signed in to change notification settings

lostjared/libmx2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libmx2

libmx cube breakout-3d

libmx2 is a cross-platform library that facilitates cross-platform SDL2/OpenGL development using C++20. It provides a collection of utilities and abstractions to streamline the creation of multimedia applications.

Motivation

The motivation for creating this library was to give me an easy way to assemble new SDL2 applications while using an approach I prefer, an Object Oriented Design. I have experimented with AI in some of the example projects for this library.

Features

  • SDL2 Integration: Simplifies the setup and management of SDL2 components.
  • Modern C++20 Design: Utilizes C++20 features for cleaner and more efficient code.
  • Modular Architecture: Offers a flexible structure to accommodate various project needs.
  • Optional OpenGL/GLAD/GLM support: You can compile in support for these libraries with examples

Getting Started

Prerequisites

  • C++20 compatible compiler (e.g., GCC 10+, Clang 10+, MSVC 2019+
  • SDL2/SDL2_ttf/SDL2_mixer, libpng, zlib installed
  • Optional: OpenGL/GLM includes GLAD

Installation

  1. Clone the repository:

    git clone https://github.com/lostjared/libmx2.git
  2. Navigate to the project directory:

    cd libmx2/libmx
  3. Build the library using CMake:

    mkdir build
    cd build
    cmake ..
    make -j4
    sudo make install

Optionally you can build as a static library

mkdir build
cd build
cmake .. -DBUILD_STATIC_LIB=ON
make -j4
sudo make install

Current Options:

  • -DJPEG=OFF - optionally compile in support for JPEG images with jpeglib ON or OFF
  • -DBUILD_STATIC_LIB=OFF - optionally compile library as a static library ON or OFF
  • -DOPENGL=ON optionally compile OpenGL support into the library either ON or OFF
  • -DMIXER=ON optionally compile audio support with SDL2_mixer either ON or OFF

Usage

Include the libmx2 headers in your project and link against the compiled library. Refer to the examples directory for sample usage scenarios. Also various subfolders for example projects

2D Examples Included

  • asteroids
  • blocks
  • breakout
  • frogger
  • knights tour
  • mad
  • matrix
  • piece
  • pong
  • space shooter

OpenGL Examples

How to Run the Examples

The examples require the resources for each instance to be within the same directory as the executable or to pass the path of that directory to the program with the -p or --path argument. If you created the build directory an example to run gl_pong from build/gl_pong would be

./gl_pong -p ../../gl_pong/v4

or to run space:

./space -p ../../space

If you are using Windows and MSYS/MINGW64 its a requirement to copy the libmx.dll file into the same directory as the EXE file. From inside say the build/gl_pong directory

cp ../libmx/libmx.dll .

Then I would recommend running my ldd-deploy project https://github.com/lostjared/ldd-deploy/tree/main/C%2B%2B20 mingw-deploy on the EXE to copy all the required DLL Files

mingw-deploy -i gl_pong.exe -o .

WebAssembly Makefiles

To compile the WebAssembly makefiles is a little more difficult you will first need to create a folder for libpng16 zlib and libmx to be installed to you will need to edit the Makefile and place the path to this folder

LIBS_PATH = /home/jared/emscripten-libs

then install libpng16, zlib by compiling them with emscripten and placing the files in this location you will also need to install GLM on your host system use your package manager to get it something like

sudo pacman -S glm

the paths in the Makefile look like this

ZLIB_INCLUDE = -I$(LIBS_PATH)/zlib/include
PNG_INCLUDE = -I$(LIBS_PATH)/libpng/include
MX_INCLUDE = -I$(LIBS_PATH)/mx2/include -I/usr/include/glm
ZLIB_LIB = $(LIBS_PATH)/zlib/lib/libz.a
PNG_LIB = $(LIBS_PATH)/libpng/lib/libpng.a

then enter the libmx directory edit the Makefile for the path and

make -f Makefile.em
sudo make -f Makefile.em install

then you should be able to build the projects with emscripten after setting the path in each Makefile.em using

make -f Makefile.em

Playing the Example games in WebAssembly

You can point your browser to https://lostsidedead.biz/ and select Free Web Apps and the projects are available to play in your browser

Contributing

Contributions are welcome! Please fork the repository, create a new branch for your feature or bugfix, and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

Special thanks to the SDL2 community for providing a robust multimedia library.

Screenshots of Examples

libmx matrix vb_tetris libmx knight 2 vb_aster vb_pong