-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimesTables.cpp
150 lines (120 loc) · 2.62 KB
/
timesTables.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include<GL/glew.h>
#include<GLFW/glfw3.h>
#include<iostream>
#include"Renderer.h"
#include"VertexBuffer.h"
#include"IndexBuffer.h"
#include"VertexArray.h"
#include"VertexBufferLayout.h"
#include"Shader.h"
#include <math.h>
#define PI 3.14159265
#define TEN 100
void timesTables(std::vector<float> & arr, std::vector<unsigned int> & indx, int nop, float table,bool firstTime)
{
nop = nop * TEN;
if (firstTime)
{
float angle = 0;
float angleDelta = (2 * PI) / nop;
float r = 1;
float x;
float y;
for (int i = 0; i < nop; i++)
{
x = r * cos(i * angleDelta);
y = r * sin(i * angleDelta);
arr.push_back(x);
arr.push_back(y);
angle += angleDelta;
}
}
int inc = 0;
for (int i = 0; i < nop; i++)
{
indx.push_back(inc % nop);
indx.push_back((inc + 1) % nop);
inc += 1;
}
int tab = table * TEN;
for (int i = 0; i < nop / TEN; i += 1)
{
indx.push_back(i * TEN);
indx.push_back((i * tab) % nop);
}
}
int main()
{
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
if (!glfwInit())
exit(EXIT_FAILURE);
GLFWwindow* window = glfwCreateWindow(600, 600, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewInit();
//glfwSwapInterval(4);
float buff[12] =
{
0.5,0.5,
-0.5,0.5,
-0.5,-0.5,
0.5,-0.5
};
unsigned int ind[6] =
{
0,1,2,2,3,0
};
Shader sh("b.shader");
sh.Bind();
sh.SetUnifrom4f("u_color", 1.0, 1.0, 1.0, 0.0);
Renderer ren;
float w = 0.01;
float h = 0;
float breathe = 1.0f;
float tab = 0;
bool first = true;
std::vector<float>arr;
while (!glfwWindowShouldClose(window))
{
std::vector<unsigned int>indx;
timesTables(arr, indx, 200, tab,first);
VertexBuffer vbo(arr.data(), arr.size() * sizeof(float));
vbo.Bind();
IndexBuffer ibo(indx.data(), indx.size());
ibo.Bind();
VertexBufferLayout layout;
layout.Push<float>(2);
VertexArray va;
va.AddBuffer(vbo, layout);
va.Bind();
ren.Clear();
ren.Draw(va, ibo, sh, GL_LINES);
first = false;
tab += 0.01;
sh.SetUnifrom4f("u_color", 1.0 - h, 0.0 + h, 1.0f - breathe * h * 100,1);
h += 0.001;
if ((1.0f - breathe * h*100) < 0.0)
{
breathe = -1.0f;
}
else if ((1.0f - breathe * h*100) > 1)
{
breathe = 1.0f;
}
glfwSwapBuffers(window);
glfwPollEvents();
}
}
glfwTerminate();
return 0;
}