From 3e081d1669622bbc276b038ddc38ecf0600683c3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 18 Oct 2021 01:54:59 +0200 Subject: Initial commit with an example --- tests/main.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/main.cpp (limited to 'tests') diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..bddfc3f --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +struct Delegate : public mgl::Window::Delegate { + Delegate() {} + + void draw() override { + mgl::Rectangle rect(window->get_cursor_position().to_vec2f(), { 100.0f, 500.0f }); + rect.set_color({1.0f, 0.0f, 0.0f, 1.0f}); + window->draw(rect); + + mgl::Sprite sprite(*texture, { 100.0f - 10.0f, 0.0f }); + sprite.set_color({1.0f, 1.0f, 1.0f, 0.5f}); + window->draw(sprite); + + mgl::Text text("hello world!\nGood bye world!", { 0.0f, 0.0f }, *font); + window->draw(text); + } + + mgl::Window *window; + mgl::Texture *texture; + mgl::Font *font; +}; + +int main(int argc, char **argv) { + mgl::Init init; + + Delegate delegate; + mgl::Window window(&delegate); + if(!window.create("mglpp", 1920, 1080)) + return 1; + + mgl::Texture texture; + if(!texture.load_from_file("depends/mgl/tests/X11.png")) + return 1; + + mgl::Font font; + if(!font.load_from_file("/usr/share/fonts/noto/NotoSans-Regular.ttf", 32)) + return 1; + + delegate.window = &window; + delegate.texture = &texture; + delegate.font = &font; + + while(true) { + window.poll_events(); + window.draw(); + } + + return 0; +} -- cgit v1.2.3