-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
126 lines (74 loc) · 3.28 KB
/
Copy pathmain.cpp
File metadata and controls
126 lines (74 loc) · 3.28 KB
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
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <vector>
#include <iterator>
#include "ShaderProgram.hpp"
#include "Window.hpp"
#include "VertexBuffer.hpp"
#include "VertexArray.hpp"
#include "GeometryGenerator.cpp"
#include "ParticleSystem.cpp"
#include "MouseInteractionHandler.cpp"
int main() {
int segments = 128;
std::vector<GLfloat> vertices = GeometryGenerator::circleGeometry(segments,1.0f);
Window window(1600, 1200, "Particle Simulation");
MouseInteractionHandler interactionHandler(window);
VertexArray vao{};
//Dumbass c++ always wants to declare a function, I miss you Java :c
VertexBuffer billboard_vbo{};
VertexBuffer positions_vbo{};
VertexBuffer color_vbo{};
//STATIC DRAW because the vertices of the billboard do not change
billboard_vbo.setData(vertices,GL_STATIC_DRAW);
//STREAM DRAW because positions change really often
positions_vbo.setData(ParticleSystem::maxParticles * 4 * sizeof(GLfloat),GL_STREAM_DRAW);
// STREAM DRAW , idk maybe we will change the color frquently
color_vbo.setData(ParticleSystem::maxParticles * 4 * sizeof(GLubyte),GL_STREAM_DRAW);
// The last 0 on the call Tells the gpu the size of the steps as it reads the vbos,
// we want to read an element at a time for the changing attibs and not move for the base geometry
//1st channel for streaming
vao.addAtributte(billboard_vbo,0,3,GL_FLOAT,GL_FALSE,0);
// 2nd channel for streaming , size 4 due to attrib x y z size
vao.addAtributte(positions_vbo,1,4,GL_FLOAT,GL_FALSE,1);
// 3rd channel for streaming, size 4 due to r g b a, GL_TRUE because chars gor form 0 to 255 and gpus expect a number between 0 and 1
vao.addAtributte(color_vbo,2,4,GL_UNSIGNED_BYTE,GL_TRUE,1);
//Shaders
ShaderProgram shader("../particle.vsh", "../particle.fsh");
GridLayout grid(1,1, ParticleSystem::maxParticles);
ThreadPool pool(ParticleSystem::threadCount);
ParticleSystem particleSystem(interactionHandler, grid, pool);
window.initializeUI();
while (!window.shouldClose()) {
window.processInput();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
glClearColor(0.1f, 0.1f, 0.12f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
shader.use();
particleSystem.update(glfwGetTime());
positions_vbo.updateSubData( 0, particleSystem.positions());
color_vbo.updateSubData(0, particleSystem.colors());
glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, segments, ParticleSystem::maxParticles);
ImGui::Begin("Engine Metrics");
ImGui::Text("Active Particles: %d", particleSystem.maxParticles);
ImGui::Text("Application average %.1f FPS (%.3f ms/frame)",
ImGui::GetIO().Framerate,
1000.0f / ImGui::GetIO().Framerate);
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
window.swapBuffers();
window.pollEvents();
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
return 0;
}