Skip to content

build/api-examples/FramebufferPresenter.cpp

Complete program from the FramebufferPresenter API reference. Save it at the path shown above and use the build command in the reference page.

Source files · Download FramebufferPresenter.cpp

#include "framebuffer_window.hpp"
#include <cstring>

int main()
{
    gaspardos::Window  window;
    GO64_WindowOptions options = {};
    options.width              = 320;
    options.height             = 240;
    std::strcpy(options.title, "Framebuffer");
    if (window.create(options) < 0)
        return 1;
    gaspardos::Framebuffer image(320, 240);
    image.clear(0x00201810);
    image.circle(160, 120, 40, 0x00ffffff);
    gaspardos::FramebufferPresenter presenter(window);
    for (unsigned i = 0; i < 10000; ++i)
    {
        GO64_Event event  = {};
        int64_t    result = window.event(event);
        if (result < 0 && result != -11)
            return 1;
        if (result == 0 && (event.type == 15 || event.type == GO64_ERROR))
            break;
        if (window.ready())
        {
            result = presenter.present(image);
            if (result == 0)
                break;
            if (result != -11)
                return 1;
        }
        GO64_yield();
    }
    for (unsigned i = 0; i < 10000; ++i)
    {
        GO64_Event event = {};
        if (window.event(event) == 0 && event.type == 15)
            break;
        GO64_yield();
    }
    return window.close() == 0 ? 0 : 1;
}