-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.cpp
More file actions
46 lines (35 loc) · 1010 Bytes
/
UI.cpp
File metadata and controls
46 lines (35 loc) · 1010 Bytes
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
#include "UI.h"
#include <atomic>
#include <cassert>
#include <chrono>
#include <thread>
namespace xyz {
UI::UI(TripleBuffer *triple_buffer, Scene scene)
: triple_buffer_(triple_buffer), scene_(std::move(scene)) {}
UI::~UI() {
if (window_) {
glfwDestroyWindow(window_);
glfwTerminate();
}
}
void UI::init() {
assert(!window_);
glfwInit();
window_ = glfwCreateWindow(height, width, "3dsurface", nullptr, nullptr);
glfwSetInputMode(window_, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwMakeContextCurrent(window_);
gl3wInit();
scene_.init(window_);
}
void UI::display() {
while (!glfwWindowShouldClose(window_)) {
auto buffer = reinterpret_cast<float *>(triple_buffer_->consumer_buffer());
scene_.display(window_, buffer);
glfwSwapBuffers(window_);
glfwPollEvents();
triple_buffer_->switch_consumer_buffer();
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
stopped_.store(true, std::memory_order_release);
}
} // namespace xyz