-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
115 lines (76 loc) · 2.2 KB
/
Main.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Main.cpp
*
* Created on: 08.04.2018
* Author: andr
*/
#include <iostream>
#include <vector>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
#include <math.h>
#include "Game.h"
using namespace std;
double time_point;
double actual_time;
int flush_fps_count;
int flush_fps_toprint_count;
int fps_count;
int fps_to_print;
int main(int argc, char ** argv)
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(1280, 1024, "GLFW test", NULL, NULL);
glfwMakeContextCurrent(window);
const GLubyte *version = glGetString(GL_VERSION);
const GLubyte *renderer = glGetString(GL_RENDER);
printf("Renderer: %s\n", renderer);
printf("OpenGL version supported %s\n", version);
glfwSwapInterval(0);
glewExperimental = GL_TRUE;
GLenum glew_status = glewInit();
if (glew_status != GLEW_OK) {
cerr << "glew glfw Error "<< to_string(glew_status) << "!" <<endl;
return 1;
}
Game * Zgadywanka = new Game(window);
time_point = actual_time = glfwGetTime();
while (!glfwWindowShouldClose(window))
{
actual_time = glfwGetTime();
bool redraw = true;
if (actual_time - time_point > 1.0)
{
time_point = actual_time;
fps_to_print= fps_count;
fps_count = 0;
flush_fps_toprint_count= flush_fps_count;
flush_fps_count = 0;
}
double delta_time;
delta_time = actual_time - time_point;
if (delta_time*1000 > flush_fps_count)
{
redraw = false;
flush_fps_count++;
Zgadywanka->Tick(actual_time);
glfwPollEvents();
}
if (redraw)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// | GL_STENCIL_BUFFER_BIT);
fps_count++;
Zgadywanka->Display();
glFlush();
glfwSwapBuffers(window);
}
if (Zgadywanka->Terminated) break;
}
glfwTerminate();
return 0;
}