-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (68 loc) · 1.83 KB
/
main.cpp
File metadata and controls
77 lines (68 loc) · 1.83 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
//
// Created by Jacopo Gasparetto on 19/09/22.
//
#include "ImGuiApp.hpp"
#include "imgui.h"
#include <array>
#include <cmath>
template <size_t size>
using plot_array = std::array<float, size>;
template<size_t Size>
struct PlotData {
plot_array<Size> x;
plot_array<Size> y;
size_t size = Size;
};
template <size_t size>
constexpr plot_array<size> makeBarPlotData() {
plot_array<size> a;
for (size_t i = 0; i < size; i++)
a.at(i) = float(i) * 10.0f;
return a;
}
template <size_t size>
PlotData<size> makeLinePlotData(float a, float b) {
plot_array<size> x;
plot_array<size> y;
for (size_t i = 0; i < size; ++i) {
auto t = float(i) / size * (b - a);
x.at(i) = t;
y.at(i) = std::sin(t / M_PI_2) * 100.0f;
}
return {x, y};
}
class MyApp {
private:
constexpr static size_t n_points = 1000;
constexpr static plot_array<10> m_barPlotData{makeBarPlotData<10>()};
PlotData<n_points> m_linePlotData;
public:
MyApp() : m_linePlotData{makeLinePlotData<n_points>(0.0f, 10.0f)} {}
void Update() {
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
if (ImGui::Button("Button"))
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text(
"Application average %.3f ms/frame (%.1f FPS)",
1000.0f / ImGui::GetIO().Framerate,
ImGui::GetIO().Framerate
);
ImPlot::BeginPlot("A plot");
ImPlot::PlotBars("Bar Plot", m_barPlotData.data(), m_barPlotData.size());
ImPlot::PlotLine("Line Plot", m_linePlotData.x.data(), m_linePlotData.y.data(), m_linePlotData.size);
ImPlot::EndPlot();
ImGui::End();
}
};
int main() {
KCE::AppSettings appSettings{};
appSettings.title = "My Vulkan+ImGui App";
KCE::App<MyApp> app{appSettings};
app.Run();
return 0;
}