The prototype of Zen Zoom. Made on ubuntu, I guess.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

88 lines
2.1 KiB

#include <iostream>
#include <stdexcept>
#include <chrono>
#include <thread>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include "App.h"
#include "globals.h"
App* app_ptr = 0;
unsigned int const frames_per_second = 60.0;
typedef std::chrono::high_resolution_clock clock_type;
size_t frame_count = 0;
clock_type::time_point begin_time;
void begin() {
app_ptr = new App(kWindowWidth, kWindowHeight);
begin_time = clock_type::now();
}
void end() {
auto end = clock_type::now();
auto difference = end-begin_time;
auto time_elapsed = difference.count()*clock_type::duration::period::num/(double)clock_type::duration::period::den;
std::cout << "Did " << frame_count << " frames in " << time_elapsed << " seconds." << std::endl;
std::cout << "That's " << frame_count/time_elapsed << " frames per second." << std::endl;
delete app_ptr;
}
int main(int argc, char** argv) {
// let glut create a window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_ALPHA);
glutInitWindowSize(kWindowWidth, kWindowHeight);
glutCreateWindow("OpenGL");
// we need glew for shaders
auto err = glewInit();
if(err != GLEW_OK) {
throw std::runtime_error("A glew error");
}
// all callbacks (c++0x lambdas woei)
glutDisplayFunc([] {
auto const time_step = std::chrono::milliseconds(1000/frames_per_second);
static auto previous_timepoint = clock_type::now();
auto const current_timepoint = clock_type::now();
auto const difference = current_timepoint - previous_timepoint;
if(difference > time_step) {
app_ptr->update();
app_ptr->draw();
glutSwapBuffers();
//glFlush();
++frame_count;
if(frame_count == 7400) exit(0);
previous_timepoint = current_timepoint-(difference%time_step);
} else {
usleep((time_step-difference).count()*1000000*clock_type::duration::period::num/(double)clock_type::duration::period::den/2);
//std::sleep_for((time_step-difference)/2);
}
glutPostRedisplay();
});
glutReshapeFunc([](int w, int h) {app_ptr->resize(w, h);});
glutCloseFunc(end); // freeglut extension
// my app-object
begin();
// GO!
glutMainLoop();
return 0;
}