Skip to content

Framebuffer

Index · Français

Description

Owned RGBX8888 software pixel buffer. Use it to draw in memory before presenting pixels in a window.

gaspardos::Framebuffer — bindings/cpp/framebuffer.hpp, C++98.

Simple program example

#include "framebuffer.hpp"

int main()
{
    gaspardos::Framebuffer image(320, 240);
    image.clear(0x00201810);
    image.circle(160, 120, 40, 0x00ffffff);
    return image.pixel(200, 120) == 0x00ffffff ? 0 : 1;
}

Building from Windows

From the repository root, save the program as build/api-examples/Framebuffer.cpp.

New-Item -ItemType Directory -Force build/api-examples | Out-Null
& .\build-x64-install\bin\x86_64-gaspardos-g++.exe -std=c++98 -O2 -Ibindings/cpp build/api-examples/Framebuffer.cpp -o build/api-examples/Framebuffer.elf
if ($LASTEXITCODE -ne 0) { throw "C++ build failed" }

Executable for GaspardOS. Presentation requires WINDOW_BLIT=146 in the kernel; -38 means the extension is absent. Source files.

Methods and public data

Framebuffer(unsigned width, unsigned height)

Each dimension must be 1..1024; rejected dimensions leave a 0 × 0 buffer. Allocation failure throws bad_alloc.

bool resize(unsigned width, unsigned height)

Validate and replace storage; false preserves the old buffer. Invalidates pointers to previous pixels.

unsigned width() const / unsigned height() const

Current dimensions.

uint32_t* pixels() / const uint32_t* pixels() const

Contiguous width × height pixels; null for an invalid buffer. Stride equals width.

void clear(uint32_t color)

Fill every pixel. Color is 0x00BBGGRR.

void pixel(int x, int y, uint32_t color)

Write when coordinates are inside the buffer; otherwise do nothing.

uint32_t pixel(int x, int y) const

Read a pixel; zero outside bounds.

void circle(int x, int y, unsigned radius, uint32_t color)

Draw a hollow circle without filling its center; maximum radius 1024 and center within [-2048,2048].