aboutsummaryrefslogtreecommitdiff
path: root/src/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/Font.cpp4
-rw-r--r--src/graphics/Image.cpp4
-rw-r--r--src/graphics/Shader.cpp40
3 files changed, 44 insertions, 4 deletions
diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp
index 52698d3..7b5dd68 100644
--- a/src/graphics/Font.cpp
+++ b/src/graphics/Font.cpp
@@ -9,10 +9,10 @@ namespace mgl {
mgl_font_unload(&font);
}
- bool Font::load_from_file(const std::string &filepath, unsigned int character_size) {
+ bool Font::load_from_file(const char *filepath, unsigned int character_size) {
if(font.texture.id)
return false;
- return mgl_font_load_from_file(&font, filepath.c_str(), character_size) == 0;
+ return mgl_font_load_from_file(&font, filepath, character_size) == 0;
}
unsigned int Font::get_character_size() const {
diff --git a/src/graphics/Image.cpp b/src/graphics/Image.cpp
index c45da15..493fad7 100644
--- a/src/graphics/Image.cpp
+++ b/src/graphics/Image.cpp
@@ -10,10 +10,10 @@ namespace mgl {
mgl_image_unload(&image);
}
- bool Image::load_from_file(const std::string &filepath) {
+ bool Image::load_from_file(const char *filepath) {
if(image.data)
return false;
- return mgl_image_load_from_file(&image, filepath.c_str()) == 0;
+ return mgl_image_load_from_file(&image, filepath) == 0;
}
unsigned char* Image::data() {
diff --git a/src/graphics/Shader.cpp b/src/graphics/Shader.cpp
new file mode 100644
index 0000000..96fe8ba
--- /dev/null
+++ b/src/graphics/Shader.cpp
@@ -0,0 +1,40 @@
+#include "../../include/mglpp/graphics/Shader.hpp"
+
+namespace mgl {
+ Shader::Shader() {
+ shader_program.id = 0;
+ }
+
+ Shader::~Shader() {
+ mgl_shader_program_deinit(&shader_program);
+ }
+
+ bool Shader::load_from_file(const char *filepath, Type type) {
+ if(shader_program.id)
+ return false;
+
+ int res = mgl_shader_program_init(&shader_program);
+ if(res != 0)
+ return false;
+
+ res = mgl_shader_program_add_shader_from_file(&shader_program, filepath, (mgl_shader_type)type);
+ if(res != 0)
+ return false;
+
+ return mgl_shader_program_finalize(&shader_program) == 0;
+ }
+
+ bool Shader::set_uniform(const char *name, vec2f value) {
+ if(!shader_program.id)
+ return false;
+ return mgl_shader_program_set_uniform_vec2f(&shader_program, name, { value.x, value.y }) == 0;
+ }
+
+ // static
+ void Shader::use(Shader *shader) {
+ if(shader)
+ mgl_shader_program_use(&shader->shader_program);
+ else
+ mgl_shader_program_use(nullptr);
+ }
+} \ No newline at end of file