A simple but robust 2D game engine/API aimed to create simple 2D games.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This engine was initially oriented on a simple game that me and my father decided to make: Tank Wars. Frankly, I wanted to create a more of like an engine that simplifies the process of creating various types games, instead of focusing on a single game. That's why I have started the Easy 2D project - in which I improve my C and OpenGL knowledge with creating a useful software that creates things I love. Also note that this Engine (though as of now it really is an API/Wrapper of OpenGL) is only focused on 2D rendering, however after this project I may implement Easy3D which focuses on 3D rendering.
Also, you may find the code obscure/not professional - since I develop the library as I learn (on the fly). If you do, please send me an email (emirhurturk444@gmail.com) and I would be happy to alter the code according to your observation.
A note: Since the engine is currently under development, the codebase lacks quality at some parts, however I aim to refactor this whole engine once I get things up going on and working.
- OpenGL 4.3 - the GLAD loader
- GLFW - Window & Input handler
- stb - Image Parsing
- cglm - Math library
To get this engine locally, there are 2 options for you: 1) build & install from the source (recommended), 2) download the prebuilt binaries for your platform (as of now the engine supports UNIX machines). All the dependencies of the engine are already in the repo, so no need to download any external library locally (although cmake must be installed if you are planning to build from the source). Here are some simple steps to get this engine up and running locally on your system.
- CMake (If you are planning to build from the source)
- Clone the repo
git clone https://github.com/ehurturk/Easy2D.git
- Create the build directory
mkdir -p ./build
- Generate the build files
cd build && cmake ..
- Compile the project
make # if a problem happens, try adding sudo (ex: sudo make)
- Install the library to your system
sudo make install # you can change where to install the library by editing the Makefile
Here is the download link to download the correct binaries without building from the source code.
To be able to successfully install Easy2D to your system, just move the downloaded library file (libEasy2D.dylib
for mac) to /usr/local/lib
, and the whole include
folder to /usr/local/include
.
Although the library is made using the C programming language, it can be used within C++ projects as well. After you have completed the installation process, the necessary dynamic library would be placed under /usr/local/lib
directory, whereas the necessary include files would be placed under /usr/local/include
directory.
-
Using a package manager like
CMake
:I recommend using cmake as the build file generator which simplifies the entire process. For projects using CMake, here is a simple
CMakeLists.txt
file to get you started with Easy2D:# CMakeListst.txt, placed inside the root directory of the project. cmake_minimum_required(VERSION 3.19) project(PROJECT_NAME) set(CMAKE_CXX_STANDARD 17) # for C++17 standard set(CMAKE_C_STANDARD 99) # for C99 standard find_library(Easy2DLIB libEasy2D.1.0.dylib) # locate the dynamic library file inside /usr/local/lib/ message(STATUS ${EASY2D_LIB}) # output the path of the lib to see if cmake found the file or not include_directories(/usr/local/include) # since the Easy2D include files are placed under /usr/local/include, you need to include this inside cmake to be able to access the header files add_executable(PROJECT_NAME main.cpp) target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC ${Easy2DLIB})
-
Using a simple
Makefile
:LIB=-L/usr/local/lib # the lib location INC=-I/usr/local/include # the include direction CC = g++ # the g++ compiler CFLAGS = -Wall # enable all warnings default: main main: $(CC) $(CFLAGS) $(INC) main.cpp -o main clean: rm -r test.o make.out
Here is a boilerplate code that makes use of Easy2D which renders a white rectangle in the middle of the screen:
#include <Easy2D/easy2d.h> /* the public header file (note: use angled brackets (<>) */
#define EZ_DEBUG_ENABLED
void init();
void update();
void destroy();
EZApplication *app; /* the main application */
EZScene *scene; /* the scene containing all gameobjects, camera, etc. */
int main() {
app = ezCreateApplication();
/* After creating the application, you need to register it to Easy2D */
ezRegisterAsApplication(app);
/* Then bind the functions */
ezBindAppInitCallback(init);
ezBindAppUpdateCallback(update);
ezBindAppDestroyCallback(destroy);
ezStart(); /* start Easy2D application */
return 0;
}
void init() {
app->window = ezCreateWindow("Easy2DSandbox", 800, 600);
scene = ezCreateScene();
EZCamera *cam = ezCreateCamera(EZ_ORTHOGRAPHIC);
ezAddToScene(scene, (void *)cam, EZ_CAMERA);
/* Create a sprite with default shader which implements proj and model matrices by default */
EZSprite *sprite = ezSquareSprite();
// Alternatively, you can bind your own shaders / textures the sprite using:
// EZShader *shader = ezDirectShaderPipeline(2,
// (EZShaderInfo){.type = EZ_VERTEX_SHADER, .src = "../res/simple.vs"},
// (EZShaderInfo{.type = EZ_FRAGMENT_SHADER, .src = "../res/simple.fs"}));
// ezSetSpriteShader(sprite, shader);
// EZTexture *tex1 = ezLoadTexture("../res/barack.jpeg");
// ezSetSpriteTexture(sprite, tex1); */
/* Add the sprite to the scene */
ezAddToScene(scene, (void *)sprite, EZ_GAMEOBJECT);
}
void update() {
/* The main loop */
while (!ezIsWindowOpen(app->window)) {
/* Renderer stuff */
ezSetBackgroundColor(0.0f, 0.0f, 0.0f, 1.0f);
ezClearFrame();
/* Render the current scene */
ezRenderScene(scene);
ezUpdateWindow(app->window);
}
}
void destroy() {
/* The cleanup method basically */
ezFreeApp(app); /* deallocate the app */
ezDestroyScene(scene); /* deallocate all the objects the scene includes, and their dependent objects */
}
For more examples, please refer to the Documentation or the Sandbox Repository.
The engine currently supports UNIX machines since it uses dll
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Emir Hurturk - emirhurturk444@gmail.com
Project Link: https://github.com/ehurturk/Easy2D