Skip to content

arkenidar/cpp_libsdl3_graphics_cairo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cairo + SDL3 Graphics Application

A C++ application that combines Cairo for 2D vector graphics rendering with SDL3 for window management and hardware-accelerated display.

Architecture

┌─────────────────────────────────────────┐
│              Application                │
│               (app.cpp)                 │
├─────────────────────────────────────────┤
│         Cairo Drawing Layer             │
│            (drawing.cpp)                │
│   (Vector graphics, shapes, text)       │
├─────────────────────────────────────────┤
│      SDL3 Surface/Texture Bridge        │
│           (renderer.cpp)                │
│  (Cairo surface → SDL texture transfer) │
├─────────────────────────────────────────┤
│            SDL3 Window/Renderer         │
│   (Window, events, hardware rendering)  │
└─────────────────────────────────────────┘

Project Structure

cpp_libsdl3_graphics_cairo/
├── CMakeLists.txt          # Build configuration
├── .gitignore              # Git ignore rules
├── docs/
│   └── readme.md           # This documentation
├── src/
│   ├── main.cpp            # Entry point
│   ├── app.hpp/cpp         # Application lifecycle & event loop
│   ├── renderer.hpp/cpp    # Cairo-SDL3 bridge
│   └── drawing.hpp/cpp     # Cairo drawing utilities
└── build/                  # Build output (gitignored)

Source Files

File Purpose
main.cpp Entry point, creates and runs the App
app.hpp/cpp Application class managing window, events, and render loop
renderer.hpp/cpp Bridges Cairo surfaces with SDL3 textures
drawing.hpp/cpp Cairo drawing utilities and animated demo

How It Works

  1. SDL3 creates a window and hardware-accelerated renderer
  2. SDL_Surface is created with ARGB8888 format (Cairo-compatible)
  3. Cairo surface wraps the SDL surface's pixel buffer
  4. Cairo context draws vector graphics to the surface
  5. SDL_Texture is updated from the surface and rendered to screen

Features

  • Animated shapes (circles, rounded rectangles)
  • Gradient fills
  • Bezier curves
  • Text rendering
  • Window resizing support
  • ~60 FPS frame rate

Dependencies

  • SDL3 - Window management, input, rendering
  • Cairo - 2D vector graphics library
  • CMake 3.16+ - Build system
  • C++17 compiler

Installing Dependencies (Ubuntu/Debian)

sudo apt install libcairo2-dev cmake build-essential
# SDL3 may need to be built from source

Building

mkdir build && cd build
cmake ..
make

Running

./build/cairo_sdl3_app

Press ESC to exit the application.

Controls

Key Action
ESC Exit application
Window resize Automatically adapts

About

[cairo] plan a C++ app for Cairo graphics within an SDL layer .

Topics

Resources

Stars

Watchers

Forks

Contributors