Skip to content

Latest commit

 

History

History
263 lines (178 loc) · 7.25 KB

README.md

File metadata and controls

263 lines (178 loc) · 7.25 KB

libmx2

planet xeon 3 gl_breakout3 vlcsnap-2025-04-04-16h54m33s924

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.

In Progress

I am working on adding support for Vulkan (its not complete)

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
  • Optional Vulkan: You can compile in support for Vulkan or MoltenVK

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 or Vulkan/MoletnVK

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
  • -DVULKAN=ON optionally compile Vulkan support into the library ON or OFF
  • -DMOLTEN=ON optionally compile with MoltenVK
  • -DMOLTEN_PATH=/usr/local/opt/molten-vk (or path you installed molten-vk)

WebAssembly Demos

https://lostsidedead.biz/acidcam.web

https://lostsidedead.biz/acidcam.webgl

https://lostsidedead.biz/game/3DBreak

https://lostsidedead.biz/Breakout

https://lostsidedead.biz/3DPong

https://lostsidedead.biz/3DPong

https://lostsidedead.biz/Space

https://lostsidedead.biz/game/Space3D

https://lostsidedead.biz/asetroids

https://lostsidedead.biz/Blocks

https://lostsidedead.biz/KnightsTour

https://lostsidedead.biz/point-sprites

https://lostsidedead.biz/point-sprites/stars3d.html

https://lostsidedead.biz/Phong

https://lostsidedead.biz/Torus

https://lostsidedead.biz/Light

https://lostsidedead.biz/Shadow

https://lostsidedead.biz/Skybox

https://lostsidedead.biz/DrawBox

https://lostsidedead.biz/MouseSkybox

https://lostsidedead.biz/BoxOfRain

https://lostsidedead.biz/Rain

https://lostsidedead.biz/3DWalk

https://lostsidedead.biz/Nova

https://lostsidedead.biz/Fire

https://lostsidedead.biz/Winter

https://lostsidedead.biz/SpaceExpanse

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

Vulkan Examples

  • Basic Triangle/Shader
  • 3D Cube
  • 3D texture Mapped Cube

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

af_Console libmx matrix vb_tetris libmx knight 2 vb_pong