commit 73b7d46e73021d17208c5bc169937ef346ce8a80
parent c2a5d78b6c3fc6319a1e6d761564d2482e98084b
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 24 Sep 2016 10:43:41 -0600
src: remove window class
Diffstat:
M | src/gl_main.cc | | | 164 | ++++++++++++++++++++++++++++++------------------------------------------------- |
1 file changed, 63 insertions(+), 101 deletions(-)
diff --git a/src/gl_main.cc b/src/gl_main.cc
@@ -19,124 +19,50 @@
#define FONT_PATH "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf"
#endif
-class window {
-public:
- window(int argc, char *argv[]);
- void start();
-
- static void idle_step();
- static void print_fps(int);
- static void next_frame(View *);
-
- static FT_Library ft_library;
- static FT_Face ft_face;
-
- static demo_font_t *font;
- static demo_buffer_t *buffer;
-
- static View *static_vu;
- static ProcessDir m_pdir;
- static std::vector<ProcessFile> drawables;
-private:
- static void add_new_process(std::string const &);
- static void display();
- static void reshape_func(int, int);
- static void keyboard_func(unsigned char, int, int);
- static void special_func(int, int, int);
- static void mouse_func(int, int, int, int);
- static void motion_func(int, int);
-
- demo_glstate_t *st;
-};
-
-std::vector<ProcessFile> window::drawables;
-ProcessDir window::m_pdir;
-View *window::static_vu;
-
-FT_Library window::ft_library;
-FT_Face window::ft_face;
-
-demo_font_t *window::font;
-demo_buffer_t *window::buffer;
-
-window::window(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(1600, 1200);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutCreateWindow("C It Run");
- glutReshapeFunc(reshape_func);
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard_func);
- glutSpecialFunc(special_func);
- glutMouseFunc(mouse_func);
- glutMotionFunc(motion_func);
-
- GLenum glew_status = glewInit();
- if (GLEW_OK != glew_status)
- errx(1, "%s", glewGetErrorString(glew_status));
- if (!glewIsSupported("GL_VERSION_2_0"))
- errx(1, "No support for OpenGL 2.0 found");
-
- st = demo_glstate_create();
- buffer = demo_buffer_create();
+demo_glstate_t *st;
- static_vu = new View(st, buffer);
-
- FT_Init_FreeType(&ft_library);
-
- ft_face = NULL;
- FT_New_Face(ft_library, FONT_PATH, /* face_index */ 0, &ft_face);
-
- font = demo_font_create(ft_face, demo_glstate_get_atlas(st));
-
- static_vu->setup();
+std::vector<ProcessFile> drawables;
+ProcessDir m_pdir;
+View *static_vu;
- static_vu->toggle_animation();
+FT_Library ft_library;
+FT_Face ft_face;
- glyphy_point_t top_left = { 0, 0 };
- demo_buffer_move_to(buffer, &top_left);
- demo_buffer_add_text(buffer, "waiting...", font, 1);
-}
+demo_font_t *font;
+demo_buffer_t *buffer;
void
-window::reshape_func(int width, int height)
+reshape_func(int width, int height)
{
static_vu->reshape_func(width, height);
}
void
-window::keyboard_func(unsigned char key, int x, int y)
+keyboard_func(unsigned char key, int x, int y)
{
static_vu->keyboard_func(key, x, y);
}
void
-window::special_func(int key, int x, int y)
+special_func(int key, int x, int y)
{
static_vu->special_func(key, x, y);
}
void
-window::mouse_func(int button, int state, int x, int y)
+mouse_func(int button, int state, int x, int y)
{
static_vu->mouse_func(button, state, x, y);
}
void
-window::motion_func(int x, int y)
+motion_func(int x, int y)
{
static_vu->motion_func(x, y);
}
void
-window::start()
-{
- glutMainLoop();
-}
-
-void
-window::display(void)
+display(void)
{
static_vu->display();
}
@@ -150,10 +76,10 @@ current_time(void)
}
void
-window::add_new_process(std::string const &file_name)
+add_new_process(std::string const &file_name)
{
- window::drawables.push_back(ProcessFile(file_name));
- ProcessFile *pfile = &window::drawables.back();
+ drawables.push_back(ProcessFile(file_name));
+ ProcessFile *pfile = &drawables.back();
demo_buffer_clear(buffer);
@@ -178,7 +104,7 @@ window::add_new_process(std::string const &file_name)
}
void
-window::next_frame(View *vu)
+next_frame(View *vu)
{
std::vector<std::string> *new_files = m_pdir.scan();
for (std::string &file_name : *new_files)
@@ -186,14 +112,14 @@ window::next_frame(View *vu)
delete new_files;
- for (auto &rp : window::drawables) {
+ for (auto &rp : drawables) {
rp.read_executions();
//glyphy_point_t tmp;
for (auto &t : rp.m_tus) {
//size_t bytes_total = t.num_lines * sizeof(uint64_t);
- for (int i = 0; i < t.num_lines; i++) {
+ for (unsigned int i = 0; i < t.num_lines; i++) {
if (t.exec_counts[i] == 0)
continue;
@@ -207,7 +133,7 @@ window::next_frame(View *vu)
}
void
-window::idle_step(void)
+idle_step(void)
{
View *vu = static_vu;
if (vu->animate) {
@@ -218,7 +144,7 @@ window::idle_step(void)
}
void
-window::print_fps(int ms)
+print_fps(int ms)
{
View *vu = static_vu;
if (vu->animate) {
@@ -234,21 +160,57 @@ window::print_fps(int ms)
void
start_animation()
{
- View *vu = window::static_vu;
+ View *vu = static_vu;
vu->num_frames = 0;
vu->last_frame_time = vu->fps_start_time = current_time();
- glutIdleFunc(window::idle_step);
+ glutIdleFunc(idle_step);
if (!vu->has_fps_timer) {
vu->has_fps_timer = true;
- glutTimerFunc (5000, window::print_fps, 5000);
+ glutTimerFunc (5000, print_fps, 5000);
}
}
int
main(int argc, char *argv[])
{
- window glut_window(argc, argv);
- glut_window.start();
+ glutInit(&argc, argv);
+ glutInitWindowSize(1600, 1200);
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
+ glutCreateWindow("C It Run");
+ glutReshapeFunc(reshape_func);
+ glutDisplayFunc(display);
+ glutKeyboardFunc(keyboard_func);
+ glutSpecialFunc(special_func);
+ glutMouseFunc(mouse_func);
+ glutMotionFunc(motion_func);
+
+ GLenum glew_status = glewInit();
+ if (GLEW_OK != glew_status)
+ errx(1, "%s", glewGetErrorString(glew_status));
+ if (!glewIsSupported("GL_VERSION_2_0"))
+ errx(1, "No support for OpenGL 2.0 found");
+
+ st = demo_glstate_create();
+ buffer = demo_buffer_create();
+
+ static_vu = new View(st, buffer);
+
+ FT_Init_FreeType(&ft_library);
+
+ ft_face = NULL;
+ FT_New_Face(ft_library, FONT_PATH, /* face_index */ 0, &ft_face);
+
+ font = demo_font_create(ft_face, demo_glstate_get_atlas(st));
+
+ static_vu->setup();
+
+ static_vu->toggle_animation();
+
+ glyphy_point_t top_left = { 0, 0 };
+ demo_buffer_move_to(buffer, &top_left);
+ demo_buffer_add_text(buffer, "waiting...", font, 1);
+
+ glutMainLoop();
return 0;
}