This a simple SDL2 based 2d UI engine. Used for creating windows without borders. Can render jpg, png, gif and simple grafics on screen like python-turtle. Can be used like C/CPP header or python lib. Suppport async work
Project description
Usage and info
At the moment, this is my pet project and it is still in development. He will participate in other projects when he stops being a bit raw. But I don't think anyone is interested in this, so I'll go to the documentation.
Multi-lang readme - Russian
Opportunities
As it says in the description, it can render .gif, .jpg, and .png. The drawing takes place relative to the coordinates set in the function. It supports asynchronous operation and rendering of several images or GIFs at once.
Functions
initEngine- Initializes the engine, creates a window and a renderer. Please add it to your code before using it.
void initEngine(const char* title, int width, int height);
title: Window title (not used for a window without a frame).width: The width of the window.height: The height of the window.
cleanupEngine- Just cleans up the memory and shuts down, at the end of the code there should be
void cleanupEngine();
renderImage- Renders an image on the screen
void renderImage(const char* imagePath, int x, int y);
ImagePath: The path to the image.x: The X coordinate of the upper-left corner.y: The Y coordinate of the upper-left corner.
renderRectangle- Will draw a rectangle on the screen, but why not
void renderRectangle(int x, int y, int width, int height, unsigned int color);
x: The X coordinate of the upper-left corner.y: The Y coordinate of the upper-left corner.width: The width of the rectangle.height: The height of the rectangle is.color: Color in ARGB format (for example, 0xFF0000 for red).
renderGIF- Displays a GIF on the screen, the same as with the image
void renderGIF(const char* gifPath, int x, int y);
gifPath: The path to the GIF animation.x: The X coordinate of the upper-left corner.y: The Y coordinate of the upper-left corner.
startRenderingThread- Starts a stream for asynchronous rendering of images and GIF animations.
void startRenderingThread();
stopRenderingThread- Stops the stream for asynchronous rendering of images and GIF animations.
void stopRenderingThread();
startRecordingThread- Starts the program to record audio and convert it to text.
void startRecordingThread();
stopRecordingThread-Stops the stream to record audio and convert it to text.
void stopRecordingThread();
Usage examples
Synchronous Operation
In this example, we will initialize the engine, render the image and GIF animation, and then shut down the engine.#include <SDL2/SDL.h>
#include "engine.h"
#include <stdio.h>
int main(int argc, char* argv[]) {
initEngine("2D Character Engine", 800, 600);
if (!window) {
printf("Failed to initialize the game engine!\n");
return -1;
}
// Clearing the screen in black
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
// Draw an image in the center of the screen
renderImage("character.jpg", 350, 250);
// Drawing a cloud and GIF animation
renderImage("cloud.png", 300, 200);
renderGIF("speaking.gif", 350, 250);
// Updating the display
SDL_RenderPresent(renderer);
// Waiting for 5 seconds
SDL_Delay(5000);
cleanupEngine();
return 0;
}
Compilation For Lixux
gcc sync_example.c -o sync_example -L. -lengine -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson -Wl,-rpath,.
For windows
gcc sync_example.c -o sync_example.exe -L. -lengine -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson
Variation with Python
import engine
import time
# Initializing the engine
engine.initEngine("2D Character Engine", 800, 600)
# Clearing the screen in black
engine.renderRectangle(0, 0, 800, 600, 0x000000)
# Draw an image in the center of the screen
engine.renderImage("character.jpg", 350, 250)
# Drawing a cloud and GIF animation
engine.renderImage("cloud.png", 300, 200)
engine.renderGIF("speaking.gif", 350, 250)
# Waiting for 5 seconds
of time.sleep(5)
# Clear the screen and shut down the engine
engine.cleanupEngine()
In general, everything is the same.
Asynchronous Operation
In this example, we will initialize the engine, run streams for asynchronous rendering and audio recording, and then shut down the engine.
#include <SDL2/SDL.h>
#include "engine.h"
#include <stdio.h>
int main(int argc, char* argv[]) {
initEngine("2D Character Engine", 800, 600);
if (!window) {
printf("Failed to initialize the game engine!\n");
return -1;
}
SDL_Event event;
int running = 1;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = 0;
}
}
// Clearing the screen in black
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
// Checking for a response
pthread_mutex_lock(&mutex);
if (prompt) {
printf("Prompt: %s\n", prompt);
// Drawing a cloud and GIF animation
renderImage("cloud.png", 300, 200);
renderGIF("speaking.gif", 350, 250);
}
pthread_mutex_unlock(&mutex);
// Draw an image in the center of the screen
renderImage("character.jpg", 350, 250);
// Updating the display
SDL_RenderPresent(renderer);
SDL_Delay(16); // Approximately 60 frames per second
}
cleanupEngine();
return 0;
}
Compilation
It's the same as with the synchronous example.
Variation with Python
import engine
import time
# Initializing the engine
engine.initEngine("2D Character Engine", 800, 600)
# Running streams for rendering and recording audio
engine.startRenderingThread()
engine.startRecordingThread()
try:
while True:
# Clear the screen in black
engine.renderRectangle(0, 0, 800, 600, 0x000000)
# Draw an image in the center of the screen
engine.renderImage("character.jpg", 350, 250)
# Checking for a response
if engine.prompt:
print(f"Prompt: {engine.prompt}")
# Draw a cloud and a GIF animation
engine.renderImage("cloud.png", 300, 200)
engine.renderGIF("speaking.gif", 350, 250)
# Updating the display
time.sleep(0.016) # Approximately 60 frames per second
except KeyboardInterrupt:
pass
finally:
# Stop the threads and shut down the engine
engine.stopRenderingThread()
engine.stopRecordingThread()
engine.cleanupEngine()
Dependencies
Dependencies include both standard headers and some additional ones.
engine.h # is included in the standard delivery
SDL2 - SDL.h, SDL_image.h, SDL2/SDL_gfxPrimitivies
Portaudio
cjson
stdlib
stdbool
string
pthread
Installation for Linux
Debian-based distros
sudo apt-get install libsdl2-dev libsdl2-image-dev libportaudio2 portaudio19-dev libjson-c-dev
Arch-based distros
sudo pacman -S sdl2 sdl2_image portaudio json-c base-devel
Installation for windows
- SDL2: Download the library from SDL2.
- SDL2_image: Download the library from SDL_image.
- PortAudio: Download the library from PortAudio.
- cJSON: Download the library from cJSON.
Cross-platform via vcpkg
vcpkg install sdl2 cjson portaudio
Building into a dynamic library
For Linux
gcc -shared -o libengine.so engine.o -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson
For Windows (using MinGW):
gcc -c engine.c -o engine.o -DENGINE_EXPORTS
gcc -shared -o engine.dll engine.o -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson
Variations of the provision
Python library
Available on PyPI - pip install EasyEngineLib
C/C++ header
Copy the src and add the compiler flag to the directory where engine.h is located. For example -
gcc -I~/include/engine example.c -o example.o
Self-assembly of the Python library
If you're messing up and you don't like PyPI, build the library yourself.
python setup.py sdist bdist_wheel
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file EasyEngine-0.2.1-cp313-cp313-any.whl.
File metadata
- Download URL: EasyEngine-0.2.1-cp313-cp313-any.whl
- Upload date:
- Size: 36.9 kB
- Tags: CPython 3.13
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ef69375e147292742c14c37c4be87703545341a3ee4ab9f98b8b7af3778cdbd
|
|
| MD5 |
9deacbd06b102ad81e8768ff8ee26971
|
|
| BLAKE2b-256 |
7f41bca1eb32078f2aa7987aaaa0d0b7feb09a99008897eb38c8b2be93b6b641
|