1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#include "../../include/mglpp/window/Window.hpp"
#include "../../include/mglpp/window/Event.hpp"
#include "../../include/mglpp/graphics/Drawable.hpp"
#include "../../include/mglpp/graphics/Shader.hpp"
extern "C" {
#include <mgl/graphics/vertex.h>
#include <mgl/window/event.h>
#include <mgl/mgl.h>
}
namespace mgl {
Window::Window() {
window.window = 0;
}
Window::~Window() {
mgl_window_deinit(&window);
}
bool Window::create(const char *title, int width, int height) {
if(window.window)
return false;
return mgl_window_create_with_params(&window, title, width, height, 0) == 0;
}
bool Window::create(WindowHandle existing_window) {
if(window.window)
return false;
return mgl_window_init_from_existing_window(&window, existing_window) == 0;
}
bool Window::poll_event(Event &event) {
if(!window.window)
return false;
return mgl_window_poll_event(&window, (mgl_event*)&event);
}
void Window::clear(Color color) {
if(!window.window)
return;
mgl_window_clear(&window, mgl_color{color.r, color.g, color.b, color.a});
}
void Window::draw(Drawable &drawable, Shader *shader) {
// TODO: Make the opengl context active for this thread and window, if it already isn't
if(shader)
Shader::use(shader);
drawable.draw(*this);
if(shader)
Shader::use(nullptr);
}
void Window::draw(const Vertex *vertices, size_t vertex_count, PrimitiveType primitive_type, Shader *shader) {
// TODO: Make the opengl context active for this thread and window, if it already isn't
if(shader)
Shader::use(shader);
mgl_context *context = mgl_get_context();
mgl_vertices_draw(context, (const mgl_vertex*)vertices, vertex_count, (mgl_primitive_type)primitive_type);
if(shader)
Shader::use(nullptr);
}
void Window::display() {
if(!window.window)
return;
mgl_window_display(&window);
}
// TODO: Implement
bool Window::is_open() const {
return true;
}
// TODO: Implement
bool Window::has_focus() const {
return true;
}
// TODO: Implement
void Window::close() {
}
// TODO: Implement
void Window::set_title(const char *title) {
}
// TODO: Implement
void Window::set_framerate_limit(unsigned int fps) {
}
// TODO: Implement
void Window::set_key_repeat_enabled(bool enabled) {
}
// TODO: Implement
void Window::set_cursor_visible(bool visible) {
}
vec2i Window::get_size() const {
return { window.size.x, window.size.y };
}
vec2i Window::get_cursor_position() const {
return { window.cursor_position.x, window.cursor_position.y };
}
void Window::set_view(const View &new_view) {
if(!window.window)
return;
mgl_window_set_view(&window, (mgl_view*)&new_view);
}
View Window::get_view() {
View view;
if(!window.window)
return view;
mgl_window_get_view(&window, (mgl_view*)&view);
return view;
}
WindowHandle Window::get_system_handle() const {
return window.window;
}
}
|