Rendering
Rendering gets pixels onto a window. ASGE keeps this layer thin: an abstract renderer, a window and a texture, with SDL3 as the only backend today.
The concept
A 2D renderer exposes a small drawing vocabulary (clear, shapes, textures, text) and a way to present the finished frame. Hiding it behind an interface keeps game code independent of the graphics API, so a different backend could be added later without touching gameplay. Cameras convert world space (where things are in the level) into screen space (pixels in the window).
Immediate versus retained
An immediate-mode renderer draws what you tell it to, right now, every frame; nothing is remembered between frames. A retained scene graph keeps objects and draws them for you. Immediate mode is simple and fits 2D games where the scene is already stored elsewhere (here, in the ECS); the cost is that you submit every draw call yourself each frame.
Textures and the GPU
An image decoded in RAM must be uploaded to the GPU before it can be drawn quickly. Uploading is slow, so it should happen once and the resulting texture be reused, which is the reason textures are cached by the asset layer. Draw order also matters in 2D: later draws cover earlier ones, so sprites are sorted by layer (and often by their Y position for a top-down look) before submission.
Cameras
A camera is a position and a zoom. Subtracting its position and scaling by the zoom maps a world coordinate onto the window, and the inverse maps a mouse click back into the world. The same transform lets the renderer skip anything outside the visible area (culling), which saves draw calls in large levels.
How ASGE does it
Video system and backends
asge::video::VideoSystem brings up a window and a renderer for a chosen GraphicsBackend
through a factory and hands them out as IWindow& and IRenderer&. Only
GraphicsBackend::SDL exists; OpenGL, Vulkan and DirectX are future possibilities, which is why
everything above this layer talks to the interfaces.
IRenderer
The drawing calls are all const methods on IRenderer:
Clear,DrawRect,DrawLine,DrawCirclefor primitives, thenPresent()to show the frame.DrawTexturein several forms: scaled into a rect, at native size, a source sub-rect, plusDrawTexture9Grid(nine-slice scaling),DrawTextureTiledandDrawTextureAffinefor arbitrary transforms.DrawStringrenders text from a bakedmedia::Fontatlas (a fixed ASCII range).CreateTexture(media::Image const&)uploads pixels and returns astd::unique_ptr<ITexture>.
An ITexture reports its Size() and supports a colour modulation (SetColorMod).
Camera
video::Camera is a 2D world position plus a uniform m_Zoom. IRenderer::SetCamera
makes every following draw call go through it, and helpers such as TransformRect and
VisibleWorldRect convert between world and screen space. The ECS-side rendering (sprites, layers, Y-sort)
is the render pipeline that Game::Render runs each frame.
// image: an asge::media::Image decoded earlier; color: an asge::graphics::RGBA_Color
auto texture = inRenderer.CreateTexture( image ); // std::unique_ptr<ITexture>
inRenderer.Clear( color );
inRenderer.DrawTexture( *texture, asge::math::Float2{ 32.0f, 32.0f } ); // native size at (32, 32)
inRenderer.Present();
See also
Source: Video/VideoSystem.hpp, Video/Graphics/Renderer.hpp, Video/Graphics/Camera.hpp.
Shapes demo · Texture demo ·
Camera demo · Math