Skip to content

Dyikot/Sgl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sgl - Simple game library

A lightweight 2D game development library built on top of SDL2

About

Sgl is a minimalistic C++ library designed to simplify 2D game development using SDL2.

Key Features

  • Application Framework:
    • Simple Application class for game lifecycle management
    • Window management with Window class
    • Built-in game loop with frame rate control
  • Rendering:
    • 2D rendering with RenderContext
    • Texture loading and management
  • Event System:
    • C#-style events with delegates and observers
    • Input event handling (keyboard/mouse)
  • Scene Management:
    • Stack-based SceneManager for scene transitions
  • Styling System:
    • Declarative UI element styling with StyleProperties
    • Scene-level style configuration
  • Time Utilities:
    • Timer with duration/interval callbacks
    • Stopwatch for precise time measurements
  • Audio System:
    • SoundChunk for short sound effects
    • Music for streaming audio
    • Playlist for managing background music

Perfect for beginners learning game development and experienced developers who want to avoid boilerplate SDL2 setup.

Example

This example shows how to create an application, set up a window, and style the scene.

#include "../Sgl/Application.h"
#include "../Sgl/UI/UIElement/UIElement.h"

class MyScene: public Scene
{
public:
	MyScene()
	{
		auto layout = Canvas::New();
		layout->Classes = { "layout", "elementSize"};

		BackgroundColor = Colors::Whitesmoke;
		SetLayout(layout);
	}

	void OnRender(RenderContext context) const override
	{
		Scene::OnRender(context);
	}

	void Process(TimeSpan elapsed) override
	{
		Scene::Process(elapsed);		
	}
};

static StyleMap CreateAppStyles()
{
	StyleMap styles;
	styles.Add<Canvas>("layout")
		.AddSetter(&Canvas::BackgroundColor, Colors::White)
		.AddSetter(&Canvas::Cursor, Cursors::Hand);
	styles.Add<UIElement>("elementSize")
		.AddSetter(&UIElement::Width, 200)
		.AddSetter(&UIElement::Height, 400);

	return styles;
}

int main()
{	
	Application app;
	app.SetMaxFPS(60);
	app.Window.SetTitle("Test");
	app.SceneManager.Push<MyScene>();
	app.Styles = CreateAppStyles();
	app.Run();
}

Dependencies

About

Sgl is a simple 2D game library based on SDL 2.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages