aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-22 07:05:55 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-22 07:05:55 +0200
commitc9ee5e1c1feccb073863ba17cbfdcf094f235886 (patch)
treef6b9f3fdc21cecbaca1fd58425c0f93c3372a9d4 /include
parentfe1588ef18163c7557d3d0a62c085f42f2abfab2 (diff)
Add vertex buffer
Diffstat (limited to 'include')
-rw-r--r--include/mglpp/graphics/Font.hpp4
-rw-r--r--include/mglpp/graphics/Image.hpp7
-rw-r--r--include/mglpp/graphics/Rectangle.hpp2
-rw-r--r--include/mglpp/graphics/Sprite.hpp2
-rw-r--r--include/mglpp/graphics/Text.hpp5
-rw-r--r--include/mglpp/graphics/Texture.hpp3
-rw-r--r--include/mglpp/graphics/VertexBuffer.hpp61
-rw-r--r--include/mglpp/system/vec.hpp35
-rw-r--r--include/mglpp/window/Event.hpp116
-rw-r--r--include/mglpp/window/Keyboard.hpp113
-rw-r--r--include/mglpp/window/Mouse.hpp22
11 files changed, 352 insertions, 18 deletions
diff --git a/include/mglpp/graphics/Font.hpp b/include/mglpp/graphics/Font.hpp
index 6818277..af70115 100644
--- a/include/mglpp/graphics/Font.hpp
+++ b/include/mglpp/graphics/Font.hpp
@@ -1,6 +1,8 @@
#ifndef MGLPP_FONT_HPP
#define MGLPP_FONT_HPP
+#include <string>
+
extern "C" {
#include <mgl/graphics/font.h>
}
@@ -11,7 +13,7 @@ namespace mgl {
Font();
~Font();
- bool load_from_file(const char *filepath, unsigned int character_size);
+ bool load_from_file(const std::string &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 d8df2c3..2f7aed5 100644
--- a/include/mglpp/graphics/Image.hpp
+++ b/include/mglpp/graphics/Image.hpp
@@ -1,6 +1,7 @@
#ifndef MGLPP_IMAGE_HPP
#define MGLPP_IMAGE_HPP
+#include <string>
#include "../system/vec.hpp"
extern "C" {
@@ -13,10 +14,10 @@ namespace mgl {
Image();
~Image();
- bool load_from_file(const char *filepath);
+ bool load_from_file(const std::string &filepath);
unsigned char* data();
- size_t byte_size();
- vec2i size() const;
+ size_t get_byte_size();
+ vec2i get_size() const;
mgl_image* internal_image();
private:
diff --git a/include/mglpp/graphics/Rectangle.hpp b/include/mglpp/graphics/Rectangle.hpp
index 44a5f36..b1ed1ce 100644
--- a/include/mglpp/graphics/Rectangle.hpp
+++ b/include/mglpp/graphics/Rectangle.hpp
@@ -10,12 +10,14 @@ extern "C" {
namespace mgl {
class Rectangle : public Drawable {
public:
+ Rectangle();
Rectangle(vec2f position, vec2f size);
void set_position(vec2f position) override;
void set_color(Color color) override;
vec2f get_position() const override;
void set_size(vec2f size);
+ vec2f get_size() const;
protected:
void draw(Window &window) override;
private:
diff --git a/include/mglpp/graphics/Sprite.hpp b/include/mglpp/graphics/Sprite.hpp
index d3b8885..3cfe92b 100644
--- a/include/mglpp/graphics/Sprite.hpp
+++ b/include/mglpp/graphics/Sprite.hpp
@@ -22,7 +22,7 @@ namespace mgl {
vec2f get_scale() const;
- const Texture& get_texture() const;
+ const Texture* get_texture() const;
protected:
void draw(Window &window) override;
private:
diff --git a/include/mglpp/graphics/Text.hpp b/include/mglpp/graphics/Text.hpp
index fc02244..c169075 100644
--- a/include/mglpp/graphics/Text.hpp
+++ b/include/mglpp/graphics/Text.hpp
@@ -1,6 +1,7 @@
#ifndef MGLPP_TEXT_HPP
#define MGLPP_TEXT_HPP
+#include <string>
#include "Drawable.hpp"
extern "C" {
@@ -11,7 +12,8 @@ namespace mgl {
class Font;
class Text : public Drawable {
public:
- Text(const char *str, vec2f position, Font &font);
+ Text(std::string str, Font &font);
+ Text(std::string str, vec2f position, Font &font);
~Text();
void set_position(vec2f position) override;
@@ -22,6 +24,7 @@ namespace mgl {
private:
mgl_text text;
Font &font;
+ std::string str;
};
}
diff --git a/include/mglpp/graphics/Texture.hpp b/include/mglpp/graphics/Texture.hpp
index 0bd1740..c584a7b 100644
--- a/include/mglpp/graphics/Texture.hpp
+++ b/include/mglpp/graphics/Texture.hpp
@@ -14,7 +14,8 @@ namespace mgl {
~Texture();
bool load_from_file(const char *filepath);
- vec2i size() const;
+ vec2i get_size() const;
+ bool is_valid() const;
mgl_texture* internal_texture();
private:
diff --git a/include/mglpp/graphics/VertexBuffer.hpp b/include/mglpp/graphics/VertexBuffer.hpp
new file mode 100644
index 0000000..ca3defd
--- /dev/null
+++ b/include/mglpp/graphics/VertexBuffer.hpp
@@ -0,0 +1,61 @@
+#ifndef MGLPP_VERTEX_BUFFER_HPP
+#define MGLPP_VERTEX_BUFFER_HPP
+
+#include "Drawable.hpp"
+#include "Color.hpp"
+#include "../system/vec.hpp"
+
+extern "C" {
+#include <mgl/graphics/vertex_buffer.h>
+}
+
+namespace mgl {
+ struct Vertex {
+ vec2f position;
+ Color color;
+ vec2f texcoords;
+ };
+
+ class Texture;
+ class VertexBuffer : public Drawable {
+ public:
+ enum PrimitiveType {
+ Points,
+ Lines,
+ LineStrip,
+ Triangles,
+ TriangleStrip,
+ TriangleFan,
+ Quads,
+ QuadStrip,
+ Polygon
+ };
+
+ enum Usage {
+ Stream,
+ Dynamic,
+ Static
+ };
+
+ VertexBuffer(PrimitiveType primitive_type, Usage usage);
+ ~VertexBuffer();
+
+ void set_position(vec2f position) override;
+ void set_color(Color color) override;
+ vec2f get_position() const override;
+
+ void set_texture(Texture *texture);
+ const Texture* get_texture() const;
+
+ bool update(const Vertex *vertices, size_t vertex_count);
+ protected:
+ void draw(Window &window) override;
+ private:
+ mgl_vertex_buffer vertex_buffer;
+ Texture *texture;
+ PrimitiveType primitive_type;
+ Usage usage;
+ };
+}
+
+#endif /* MGLPP_VERTEX_BUFFER_HPP */
diff --git a/include/mglpp/system/vec.hpp b/include/mglpp/system/vec.hpp
index ac06a52..a9de662 100644
--- a/include/mglpp/system/vec.hpp
+++ b/include/mglpp/system/vec.hpp
@@ -2,23 +2,38 @@
#define MGLPP_VEC_HPP
namespace mgl {
- struct vec2f {
- vec2f(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}
+ template <typename T>
+ struct vec2 {
+ vec2(T x = 0, T y = 0) : x(x), y(y) {}
- float x;
- float y;
- };
+ vec2<T> operator + (vec2<T> other) const {
+ return { x + other.x, y + other.y };
+ }
+
+ vec2<T> operator - (vec2<T> other) const {
+ return { x - other.x, y - other.y };
+ }
- struct vec2i {
- vec2i(int x = 0, int y = 0) : x(x), y(y) {}
+ vec2<T> operator * (vec2<T> other) const {
+ return { x * other.x, y * other.y };
+ }
+
+ vec2<T> operator * (T v) const {
+ return { x * v, y * v };
+ }
- vec2f to_vec2f() const {
+ vec2<float> to_vec2f() const {
return { (float)x, (float)y };
}
- int x;
- int y;
+ T x;
+ T y;
};
+
+ using vec2f = vec2<float>;
+ using vec2d = vec2<double>;
+ using vec2i = vec2<int>;
+ using vec2u = vec2<unsigned int>;
}
#endif /* MGLPP_VEC_HPP */
diff --git a/include/mglpp/window/Event.hpp b/include/mglpp/window/Event.hpp
index ecfb380..47718ff 100644
--- a/include/mglpp/window/Event.hpp
+++ b/include/mglpp/window/Event.hpp
@@ -1,10 +1,124 @@
#ifndef MGLPP_EVENT_HPP
#define MGLPP_EVENT_HPP
+#include "Keyboard.hpp"
+#include "Mouse.hpp"
+#include <stdint.h>
+
namespace mgl {
class Event {
public:
-
+ struct SizeEvent {
+ unsigned int width;
+ unsigned int height;
+ };
+
+ struct KeyEvent {
+ Keyboard::Key code;
+ bool alt;
+ bool control;
+ bool shift;
+ bool system;
+ };
+
+ struct TextEvent {
+ uint32_t unicode;
+ };
+
+ struct MouseMoveEvent {
+ int x;
+ int y;
+ };
+
+ struct MouseButtonEvent {
+ Mouse::Button button;
+ int x;
+ int y;
+ };
+
+ struct MouseWheelEvent {
+ int delta;
+ int x;
+ int y;
+ };
+
+ struct MouseWheelScrollEvent {
+ Mouse::Wheel wheel;
+ float delta;
+ int x;
+ int y;
+ };
+
+ struct JoystickConnectEvent {
+ unsigned int joystick_id;
+ };
+
+ struct JoystickMoveEvent {
+ unsigned int joystick_id;
+ /*Joystick::Axis axis;*/
+ float position;
+ };
+
+ struct JoystickButtonEvent {
+ unsigned int joystick_id;
+ unsigned int button;
+ };
+
+ struct TouchEvent {
+ unsigned int finger;
+ int x;
+ int y;
+ };
+
+ struct SensorEvent {
+ /*Sensor::Type type;*/
+ float x;
+ float y;
+ float z;
+ };
+
+ enum EventType {
+ Closed,
+ Resized,
+ LostFocus,
+ GainedFocus,
+ TextEntered,
+ KeyPressed,
+ KeyReleased,
+ MouseWheelMoved,
+ MouseWheelScrolled,
+ MouseButtonPressed,
+ MouseButtonReleased,
+ MouseMoved,
+ MouseEntered,
+ MouseLeft,
+ JoystickButtonPressed,
+ JoystickButtonReleased,
+ JoystickMoved,
+ JoystickConnected,
+ JoystickDisconnected,
+ TouchBegan,
+ TouchMoved,
+ TouchEnded,
+ SensorChanged
+ };
+
+ EventType type;
+
+ union {
+ SizeEvent size;
+ KeyEvent key;
+ TextEvent text;
+ MouseMoveEvent mouse_move;
+ MouseButtonEvent mouse_button;
+ MouseWheelEvent mouse_wheel;
+ MouseWheelScrollEvent mouse_wheel_scroll;
+ JoystickMoveEvent joystick_move;
+ JoystickButtonEvent joystick_button;
+ JoystickConnectEvent joystick_connect;
+ TouchEvent touch;
+ SensorEvent sensor;
+ };
};
}
diff --git a/include/mglpp/window/Keyboard.hpp b/include/mglpp/window/Keyboard.hpp
new file mode 100644
index 0000000..2757871
--- /dev/null
+++ b/include/mglpp/window/Keyboard.hpp
@@ -0,0 +1,113 @@
+#ifndef MGLPP_KEYBOARD_HPP
+#define MGLPP_KEYBOARD_HPP
+
+namespace mgl {
+ class Keyboard {
+ public:
+ enum Key {
+ A,
+ B,
+ C,
+ D,
+ E,
+ F,
+ G,
+ H,
+ I,
+ J,
+ K,
+ L,
+ M,
+ N,
+ O,
+ P,
+ Q,
+ R,
+ S,
+ T,
+ U,
+ V,
+ W,
+ X,
+ Y,
+ Z,
+ Num0,
+ Num1,
+ Num2,
+ Num3,
+ Num4,
+ Num5,
+ Num6,
+ Num7,
+ Num8,
+ Num9,
+ Escape,
+ LControl,
+ LShift,
+ LAlt,
+ LSystem,
+ RControl,
+ RShift,
+ RAlt,
+ RSystem,
+ Menu,
+ LBracket,
+ RBracket,
+ Semicolon,
+ Comma,
+ Period,
+ Quote,
+ Slash,
+ Backslash,
+ Tilde,
+ Equal,
+ Hyphen,
+ Space,
+ Enter,
+ Backspace,
+ Tab,
+ PageUp,
+ PageDown,
+ End,
+ Home,
+ Insert,
+ Delete,
+ Add,
+ Subtract,
+ Multiply,
+ Divide,
+ Left,
+ Right,
+ Up,
+ Down,
+ Numpad0,
+ Numpad1,
+ Numpad2,
+ Numpad3,
+ Numpad4,
+ Numpad5,
+ Numpad6,
+ Numpad7,
+ Numpad8,
+ Numpad9,
+ F1,
+ F2,
+ F3,
+ F4,
+ F5,
+ F6,
+ F7,
+ F8,
+ F9,
+ F10,
+ F11,
+ F12,
+ F13,
+ F14,
+ F15,
+ Pause
+ };
+ };
+}
+
+#endif /* MGLPP_KEYBOARD_HPP */
diff --git a/include/mglpp/window/Mouse.hpp b/include/mglpp/window/Mouse.hpp
new file mode 100644
index 0000000..d77659a
--- /dev/null
+++ b/include/mglpp/window/Mouse.hpp
@@ -0,0 +1,22 @@
+#ifndef MGLPP_MOUSE_HPP
+#define MGLPP_MOUSE_HPP
+
+namespace mgl {
+ class Mouse {
+ public:
+ enum Button {
+ Left,
+ Right,
+ Middle,
+ XButton1,
+ XButton2
+ };
+
+ enum Wheel {
+ VerticalWheel,
+ HorizontalWheel
+ };
+ };
+}
+
+#endif /* MGLPP_MOUSE_HPP */