-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
85 lines (62 loc) · 1.44 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
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "window.h"
#include "bodies.h"
int main(int argc, char *argv[])
{
for (int i = 0; i < argc; ++i)
std::cout << argv[i] << "\n";
// Number of bodies
const int n = 3; // std::strtol(argv[1], NULL, 10);
GLFWwindow *window;
try
{
window = initializeOpenGL();
}
catch (std::runtime_error &e)
{
std::cerr << e.what() << std::endl;
return -1;
}
std::ifstream bodies{"initialConditions.txt"};
double *positions = new double[2 * n];
double *velocities = new double[2 * n];
for (int i = 0; i < 2 * n; i++)
{
if (!(bodies >> positions[i]))
{
return -1;
}
}
for (int i = 0; i < 2 * n; i++)
{
if (!(bodies >> velocities[i]))
{
return -1;
}
}
unsigned int buffer;
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(double), positions, GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_DOUBLE, GL_FALSE, 2 * sizeof(double), 0);
glPointSize(6);
glDrawArrays(GL_POINTS, 0, 3);
updatePositions(positions, velocities);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}