|
SDLPainter 1.2.0
SDL3 + OpenGL/Vulkan 2B çizim kütüphanesi
|
Türkçe sürüm | English
This guide is for people using SDLPainter for the first time. The goal is to provide a working window with a few shapes on it in five minutes. For the reasoning behind the design, see the Architecture Overview please.
| Tool | Minimum version | Notes |
|---|---|---|
| C++ compiler | GCC 11+, Clang 14+ or MSVC 2022 with C++17 | |
| CMake | 3.21 | PROJECT_IS_TOP_LEVEL, $<TARGET_RUNTIME_DLLS>, presets v3 |
| Conan | 2.x | pip install conan |
| Git | — | to clone the repository |
| OpenGL driver | 3.3 Core | present on most systems |
| Vulkan loader | 1.1+ runtime (optional) | target API is 1.1; the Conan package is vulkan-loader/1.3.290 (backward compatible) |
The preset name must match
--output-folder:CMakePresets.jsonlooks for each preset's toolchain underbuild/<preset>/generators/....On Windows/MSVC the presets are
windows-debugandwindows-release(--output-folder=build/windows-debug/generators). For cross-compilation use thewindows-crossstage in the Dockerfile together with thewindows-mingw-debug/windows-mingw-releasepresets.
Run every script from the project root. Full flag list: Script Reference.
| Preset | Platform | Build type | Notes |
|---|---|---|---|
linux-debug | Linux | Debug | used also in CI |
linux-release | Linux | Release | used also in CI |
linux-debug-asan | Linux | Debug | ASan + UBSan enabled |
windows-debug | Windows | Debug | MSVC, Visual Studio 17 2022 |
windows-release | Windows | Release | MSVC, Visual Studio 17 2022 |
windows-mingw-debug | Windows (cross) | Debug | MinGW-w64 from a Linux host, no Vulkan |
windows-mingw-release | Windows (cross) | Release | MinGW-w64 from a Linux host, no Vulkan |
| Option | Default | Effect |
|---|---|---|
SDLPAINTER_WITH_VULKAN | OFF | Vulkan backend |
SDLPAINTER_BUILD_EXAMPLES | ON | Example applications |
SDLPAINTER_BUILD_TESTS | ON | GTest unit tests |
ENABLE_SANITIZERS | OFF | ASan + UBSan (GCC/Clang) |
Building with everything, Vulkan included:
To develop a minimal application, please save the following as main.cpp:
| Line | Why | If you skip it |
|---|---|---|
SDL_GL_SetAttribute(...CORE) | OpenGL 3.3 Core profile is required | may work on a compatibility profile, but it is undefined |
Painter inside a scope | the GL context belongs to the window | glDelete* fails with error 1282 |
painter.IsValid() | the constructor can fail silently | later calls crash |
painter.Begin() / painter.End() | frame boundary | nothing reaches the screen |
Pen::NoPen() and Brush::NoBrush() are the invisible variants; the affected draws are skipped entirely, so they cost no GPU work.
| Stroke | Fill |
|---|---|
DrawLine(x1, y1, x2, y2) | — |
DrawRect(x, y, w, h) | FillRect(x, y, w, h) |
DrawCircle(cx, cy, r) | FillCircle(cx, cy, r) |
DrawEllipse(cx, cy, rx, ry) | FillEllipse(cx, cy, rx, ry) |
DrawPolygon(points) | FillPolygon(points) |
DrawPolyline(points) | — |
Save and Restore must be balanced.
The image is uploaded to the GPU on first draw; later draws reuse the cache.
Scissor-based, axis-aligned rectangles.
The library must have been built with Vulkan support:
conan install . -o "&:with_vulkan=True".
Nothing else in your code changes. The same painter.FillRect, painter.DrawText and painter.Save calls keep working. This is what the IRenderer abstraction buys you, in concrete terms.
examples/ contains one self-contained demo per feature. A good reading order for newcomers:
| Demo | Topic | Relevant API |
|---|---|---|
primitives.cpp | every basic primitive | DrawRect, FillCircle, DrawPolyline |
transforms.cpp | transform stack | Save/Restore, Translate/Rotate/Scale |
clipping.cpp | clipping | SetClipRect / ClearClip |
images.cpp | images and textures | Image, DrawImage |
text.cpp | text | Font, DrawText, Alignment |
vulkan_clear.cpp | Vulkan: clear the window | RendererBackend::kVulkan |
vulkan_triangles.cpp | Vulkan: first triangles | — |
vulkan_textured.cpp | Vulkan: images | — |
vulkan_demo.cpp | Vulkan: every primitive | — |
vulkan_text.cpp | Vulkan: text | — |
Descriptions of every demo: examples/README.md.
SDL_WINDOW_OPENGL flag?SDL_WINDOW_VULKAN, and was the library built with with_vulkan=True?painter.Begin() and painter.End()?Pen or Brush transparent (alpha = 0)?Save/Restore?Painter instance must be destroyed before SDL_DestroyWindow. The simplest fix is to put the Painter in its own scope.SetPen/SetBrush before every draw call — a colour change does not force a flush, but an opacity change does.Font::GetGlyph is expensive on the first call for a glyph and free afterwards, once it is cached.