aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------depends/mgl0
-rw-r--r--include/mglpp/graphics/Texture.hpp10
-rw-r--r--include/mglpp/system/MemoryMappedFile.hpp4
-rw-r--r--src/graphics/Sprite.cpp6
-rw-r--r--src/graphics/Texture.cpp25
-rw-r--r--tests/main.cpp2
6 files changed, 32 insertions, 15 deletions
diff --git a/depends/mgl b/depends/mgl
-Subproject f3e5b69d33f47dece7e3bc8c133f65ad7169cc1
+Subproject 470dac0e891c1ec59dfe52e77861cf068837976
diff --git a/include/mglpp/graphics/Texture.hpp b/include/mglpp/graphics/Texture.hpp
index 906818c..8bd2df6 100644
--- a/include/mglpp/graphics/Texture.hpp
+++ b/include/mglpp/graphics/Texture.hpp
@@ -12,8 +12,9 @@ namespace mgl {
class Texture {
public:
struct LoadOptions {
- bool compressed;
- bool pixel_coordinates;
+ bool compressed = false;
+ bool pixel_coordinates = false;
+ bool mipmap = false; /* available since opengl 3.0 */
};
Texture();
@@ -23,8 +24,9 @@ namespace mgl {
static Texture reference(mgl_texture ref);
- bool load_from_file(const char *filepath, const LoadOptions load_options = {false, false});
- bool load_from_image(Image &image, const LoadOptions load_options = {false, false});
+ bool load_from_file(const char *filepath, const LoadOptions load_options = {false, false, false});
+ bool load_from_image(Image &image, const LoadOptions load_options = {false, false, false});
+ bool load_from_memory(const unsigned char *data, int width, int height, mgl_image_format format, LoadOptions load_options = {false, false, false});
void clear();
vec2i get_size() const;
bool is_valid() const;
diff --git a/include/mglpp/system/MemoryMappedFile.hpp b/include/mglpp/system/MemoryMappedFile.hpp
index 1be23d4..57f3c67 100644
--- a/include/mglpp/system/MemoryMappedFile.hpp
+++ b/include/mglpp/system/MemoryMappedFile.hpp
@@ -9,8 +9,8 @@ namespace mgl {
class MemoryMappedFile {
public:
struct LoadOptions {
- bool readable;
- bool writable;
+ bool readable = true;
+ bool writable = true;
};
MemoryMappedFile();
diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp
index f2ba460..de9e96c 100644
--- a/src/graphics/Sprite.cpp
+++ b/src/graphics/Sprite.cpp
@@ -35,10 +35,8 @@ namespace mgl {
}
vec2f Sprite::get_size() const {
- if(texture)
- return get_scale() * mgl::vec2f(texture->get_size().x, texture->get_size().y);
- else
- return { 0.0f, 0.0f };
+ const mgl_vec2f v = mgl_sprite_get_size(&sprite);
+ return { v.x, v.y };
}
void Sprite::set_scale(vec2f scale) {
diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp
index 86c4ac0..1bcf3af 100644
--- a/src/graphics/Texture.cpp
+++ b/src/graphics/Texture.cpp
@@ -47,9 +47,10 @@ namespace mgl {
if(mgl_texture_init(&texture) != 0)
return false;
- mgl_texture_load_options texture_load_options = {
+ const mgl_texture_load_options texture_load_options = {
load_options.compressed,
- load_options.pixel_coordinates
+ load_options.pixel_coordinates,
+ load_options.mipmap
};
return mgl_texture_load_from_file(&texture, filepath, &texture_load_options) == 0;
}
@@ -61,13 +62,29 @@ namespace mgl {
if(mgl_texture_init(&texture) != 0)
return false;
- mgl_texture_load_options texture_load_options = {
+ const mgl_texture_load_options texture_load_options = {
load_options.compressed,
- load_options.pixel_coordinates
+ load_options.pixel_coordinates,
+ load_options.mipmap
};
return mgl_texture_load_from_image(&texture, image.internal_image(), &texture_load_options) == 0;
}
+ bool Texture::load_from_memory(const unsigned char *data, int width, int height, mgl_image_format format, LoadOptions load_options) {
+ if(texture.id)
+ clear();
+
+ if(mgl_texture_init(&texture) != 0)
+ return false;
+
+ const mgl_texture_load_options texture_load_options = {
+ load_options.compressed,
+ load_options.pixel_coordinates,
+ load_options.mipmap
+ };
+ return mgl_texture_load_from_memory(&texture, data, width, height, format, &texture_load_options) == 0;
+ }
+
void Texture::clear() {
if(owned)
mgl_texture_unload(&texture);
diff --git a/tests/main.cpp b/tests/main.cpp
index eb134ac..72737b5 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -106,7 +106,7 @@ int main(int argc, char **argv) {
mgl::Event event;
while(window.is_open()) {
- if(window.poll_event(event)) {
+ while(window.poll_event(event)) {
}