-
Notifications
You must be signed in to change notification settings - Fork 1
/
imageview.cpp
88 lines (80 loc) · 2.53 KB
/
imageview.cpp
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
#include "incgraphics.h"
#include "Transformation.hpp"
#include "Logger.hpp"
#include "Debug.hpp"
#include "Timer.hpp"
#include "Button.hpp"
class ImageViewer {
C_STRING(font_name, "assets/Verdana.ttf");
C_STRING(tex_name, "assets/button.png");
ui::Button<tex_name, font_name> button;
void setup() {
button.setx(-1, 1);
button.sety(-1, 1);
button.init();
}
protected:
const GLFWvidmode *vidmode = nullptr;
size_t width_, height_;
void init_glfw() {
int rc = glfwInit();
ASSERT(rc == 1);
vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
ASSERT(vidmode != nullptr);
width_ = vidmode->width;
height_ = vidmode->height;
width_ = 800, height_ = 600;
/* glfwWindowHint(GLFW_SAMPLES, 4); */
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
window = glfwCreateWindow(width(), height(), "imageview", nullptr, nullptr);
ASSERT(window != nullptr);
glfwMakeContextCurrent(window); GLERROR
}
void init_controls() {
// ensure we can capture the escape key
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); GLERROR
/* glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); GLERROR */
}
public:
GLFWwindow *window = nullptr;
ImageViewer(const std::string &dir):
button(dir),
width_(0), height_(0)
{}
size_t width() const { return width_; }
size_t height() const { return height_; }
void run() {
init_glfw();
init_controls();
ui::Font::setup();
setup();
Timer::time_t current_time = .0;
glfwSwapInterval(2); GLERROR
while(!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLERROR
button.label.set_text("text");
button.display();
glfwPollEvents(); GLERROR
glfwSwapBuffers(window); GLERROR
}
// display image
ui::Font::cleanup();
glfwDestroyWindow(window); GLERROR
glfwTerminate(); GLERROR
}
void resize(float new_width, float new_height) {
width_ = new_width, height_ = new_height;
}
};
int main(int argc, char *argv[]) {
std::string execdir = sys::get_executable_directory(argc, argv);
Logger::Setup();
Logger::SetLogOutput(sys::Path(execdir) / sys::Path("imageview.log"));
Logger::MirrorLog(stderr);
ImageViewer imview(execdir);
imview.run();
Logger::Close();
}