From a80bf6bb6cb8ab8c5a1430f9f9dbc214f71bdddf Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 22 Oct 2021 07:29:34 +0200 Subject: Use shader --- include/mglpp/graphics/Font.hpp | 4 +--- include/mglpp/graphics/Image.hpp | 3 +-- include/mglpp/graphics/Shader.hpp | 32 ++++++++++++++++++++++++++++++++ include/mglpp/window/Window.hpp | 4 +++- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 include/mglpp/graphics/Shader.hpp (limited to 'include') diff --git a/include/mglpp/graphics/Font.hpp b/include/mglpp/graphics/Font.hpp index af70115..6818277 100644 --- a/include/mglpp/graphics/Font.hpp +++ b/include/mglpp/graphics/Font.hpp @@ -1,8 +1,6 @@ #ifndef MGLPP_FONT_HPP #define MGLPP_FONT_HPP -#include - extern "C" { #include } @@ -13,7 +11,7 @@ namespace mgl { Font(); ~Font(); - bool load_from_file(const std::string &filepath, unsigned int character_size); + bool load_from_file(const char *filepath, unsigned int character_size); unsigned int get_character_size() const; mgl_font* internal_font(); diff --git a/include/mglpp/graphics/Image.hpp b/include/mglpp/graphics/Image.hpp index 2f7aed5..fd82c0c 100644 --- a/include/mglpp/graphics/Image.hpp +++ b/include/mglpp/graphics/Image.hpp @@ -1,7 +1,6 @@ #ifndef MGLPP_IMAGE_HPP #define MGLPP_IMAGE_HPP -#include #include "../system/vec.hpp" extern "C" { @@ -14,7 +13,7 @@ namespace mgl { Image(); ~Image(); - bool load_from_file(const std::string &filepath); + bool load_from_file(const char *filepath); unsigned char* data(); size_t get_byte_size(); vec2i get_size() const; diff --git a/include/mglpp/graphics/Shader.hpp b/include/mglpp/graphics/Shader.hpp new file mode 100644 index 0000000..4e94a7e --- /dev/null +++ b/include/mglpp/graphics/Shader.hpp @@ -0,0 +1,32 @@ +#ifndef MGLPP_SHADER_HPP +#define MGLPP_SHADER_HPP + +#include "../system/vec.hpp" + +extern "C" { +#include +} + +namespace mgl { + class Shader { + public: + enum Type { + Vertex, + Fragment, + Geometry + }; + + Shader(); + ~Shader(); + + bool load_from_file(const char *filepath, Type type); + bool set_uniform(const char *name, vec2f value); + + // If |shader| is nullptr then no shader is used + static void use(Shader *shader); + private: + mgl_shader_program shader_program; + }; +} + +#endif /* MGLPP_SHADER_HPP */ diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index 916e891..d98f5ef 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -13,6 +13,7 @@ namespace mgl { class Event; class Drawable; + class Shader; class Window { public: @@ -28,9 +29,10 @@ namespace mgl { bool create(const char *title, int width, int height); bool poll_event(Event &event); void clear(mgl::Color color = mgl::Color(0, 0, 0, 255)); - void draw(Drawable &drawable); + void draw(Drawable &drawable, Shader *shader = nullptr); void display(); + vec2i get_size() const; vec2i get_cursor_position() const; private: mgl_window window; -- cgit v1.2.3