-
Notifications
You must be signed in to change notification settings - Fork 2
/
transformer.cpp
95 lines (81 loc) · 2.76 KB
/
transformer.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
89
90
91
92
93
94
#include "gl_framework.hpp"
#include <stdlib.h>
#include <sstream>
unsigned int texture[8];
body* b;
bool recording = false;
int fps = 60;
void renderGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//if(b->transformed)
b->move(b->dist, b->turn);
b->render();
}
int main(int argc, char** argv)
{
if(argc == 2) {
std::stringstream(argv[1]) >> fps;
}
double step = 1.0 / (double) fps;
//! The pointer to the GLFW window
GLFWwindow* window;
int height = 750;
int width = 1000;
//! Setting up the GLFW Error callback
glfwSetErrorCallback(transpace::error_callback);
//! Initialize GLFW
if (!glfwInit())
return -1;
//! Create a windowed mode window and its OpenGL context
window = glfwCreateWindow(width, height, "Transformer!", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
//! Make the window's context current
glfwMakeContextCurrent(window);
//Initialize GLEW
GLenum err = glewInit();
if (GLEW_OK != err)
{
//Problem: glewInit failed, something is seriously wrong.
std::cerr<<"GLEW Init Failed : %s"<<std::endl;
}
glViewport(0, 0, width, height);
std::cout << "\n";
std::cout << "▀▀█▀▀ ▒█▀▀█ ░█▀▀█ ▒█▄░▒█ ▒█▀▀▀█ ▒█▀▀▀ ▒█▀▀▀█ ▒█▀▀█ ▒█▀▄▀█ ▒█▀▀▀ ▒█▀▀█\n";
std::cout << "░▒█░░ ▒█▄▄▀ ▒█▄▄█ ▒█▒█▒█ ░▀▀▀▄▄ ▒█▀▀▀ ▒█░░▒█ ▒█▄▄▀ ▒█▒█▒█ ▒█▀▀▀ ▒█▄▄▀\n";
std::cout << "░▒█░░ ▒█░▒█ ▒█░▒█ ▒█░░▀█ ▒█▄▄▄█ ▒█░░░ ▒█▄▄▄█ ▒█░▒█ ▒█░░▒█ ▒█▄▄▄ ▒█░▒█\n";
std::cout << "\n";
//Keyboard Callback
glfwSetKeyCallback(window, transpace::key_callback);
//Framebuffer resize callback
glfwSetFramebufferSizeCallback(window, transpace::framebuffer_size_callback);
// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
//Initialize GL state
transpace::initGL();
// Loop until the user closes the window
b = new body();
double time;
while (glfwWindowShouldClose(window) == 0)
{
time = glfwGetTime();
// Render here
renderGL();
// Swap front and back buffers
glfwSwapBuffers(window);
// Poll for and process events
glfwPollEvents();
if(b->terminate)
glfwSetWindowShouldClose(window, GL_TRUE);
while(glfwGetTime() < time + step);
std::cout << "FPS: " << 1.0 / (glfwGetTime() - time) << " \r";
std::cout.flush();
}
glfwTerminate();
return 0;
}