From 5826739e2caa98774da97c67eccb38a07b7be472 Mon Sep 17 00:00:00 2001 From: Robin Linden Date: Sat, 21 Oct 2023 14:41:45 +0200 Subject: [PATCH] img: Use our own gfx-abstractions to render images in the example --- img/BUILD | 1 + img/img_example.cpp | 19 ++++++------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/img/BUILD b/img/BUILD index e6a6b0b9..761cb495 100644 --- a/img/BUILD +++ b/img/BUILD @@ -74,6 +74,7 @@ cc_binary( ":gif", ":png", ":qoi", + "//gfx:sfml", "@sfml//:graphics", "@sfml//:window", ], diff --git a/img/img_example.cpp b/img/img_example.cpp index 8a02e6ee..5597d209 100644 --- a/img/img_example.cpp +++ b/img/img_example.cpp @@ -6,10 +6,9 @@ #include "img/png.h" #include "img/qoi.h" -#include +#include "gfx/sfml_canvas.h" + #include -#include -#include #include #include @@ -110,12 +109,7 @@ int main(int argc, char **argv) { window.setVerticalSyncEnabled(true); window.setActive(true); - sf::Image sf_image{}; - sf_image.create(width, height, bytes.data()); - sf::Texture texture{}; - texture.loadFromImage(sf_image); - sf::Sprite sprite{}; - sprite.setTexture(texture); + gfx::SfmlCanvas canvas{window}; bool running = true; while (running) { @@ -126,16 +120,15 @@ int main(int argc, char **argv) { running = false; break; case sf::Event::Resized: - window.setView(sf::View{sf::FloatRect{ - 0, 0, static_cast(event.size.width), static_cast(event.size.height)}}); + canvas.set_viewport_size(event.size.width, event.size.height); break; default: break; } } - window.clear(); - window.draw(sprite); + canvas.clear(gfx::Color{}); + canvas.draw_pixels({0, 0, static_cast(width), static_cast(height)}, bytes); window.display(); } }