-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cxx
113 lines (92 loc) · 2.13 KB
/
main.cxx
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
#include "glfw3.h"
#include "CRender.hxx"
#include "CPicture.hxx"
#include "CGraph.hxx"
#include "CModificators.hxx"
#include "TimFunction.hxx"
#include <iostream>
#include <fstream>
using namespace std;
bool _Running = true;
GLFWwindow* window;
CRender* render;
CPicture* picture;
CGraph* graph;
IFunction* graphicFunction;
IModificator* modificator1;
IModificator* modificator2;
void KeyboardCallback(GLFWwindow *window, int key, int scan, int action, int mods)
{
if ((key == GLFW_KEY_ESCAPE) && (action == GLFW_PRESS))
_Running = false;
}
void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
render->DrawPicture(picture);
glfwPollEvents();
glfwSwapBuffers(window);
}
void Update()
{
const float delta = 1;
for (int i = 0; i < 1; i++)
{
picture->Update();
modificator1->ChangeParam(delta);
modificator2->ChangeParam(-delta);
}
cout << glfwGetTime() << endl;
}
void InitProjection()
{
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 1, 0, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char const *argv[])
{
glfwInit();
render = new CRender();
picture = new CPicture();
graph = new CGraph();
graphicFunction = new JorFunction();
modificator1 = new CMoveRightModificator();
modificator2 = new CMoveRightModificator();
{
fstream input;
input.open("input.txt", std::fstream::in);
if (input.is_open())
{
graph->ReadFromFile(input);
graphicFunction->ReadFromStream(input);
picture->ReadBackgroundFunctions(input);
};
input.close();
};
picture->SetFunction(graphicFunction);
picture->SetGraph(graph);
picture->AddModificator(modificator1);
picture->AddModificator(modificator2);
picture->Init();
window = glfwCreateWindow(600, 600, "GL window", NULL, NULL);
glfwMakeContextCurrent(window);
InitProjection();
glfwSetKeyCallback(window, KeyboardCallback);
while ((_Running) && !glfwWindowShouldClose(window))
{
Render();
Update();
}
glfwTerminate();
delete picture;
delete graph;
delete render;
delete modificator1;
delete modificator2;
return 0;
}