-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestrender.cpp
More file actions
109 lines (85 loc) · 2.88 KB
/
testrender.cpp
File metadata and controls
109 lines (85 loc) · 2.88 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
#include <imgui/imgui.h>
#include "imgui/imgui_softrender.h"
#include <chrono>
#include <string>
#include <opencv2/opencv.hpp>
using namespace cv;
#define SCREENX 1024
#define SCREENY 768
texture_color32_t screen;
texture_alpha8_t fontAtlas;
unsigned long millis()
{
using namespace std::chrono;
static auto start = high_resolution_clock::now();
return duration_cast<milliseconds>(high_resolution_clock::now() - start)
.count();
}
void screen_draw(int frame_index)
{
// export pixels as a PNG using opencv
cv::Mat img(SCREENY, SCREENX, CV_8UC4, screen.pixels);
cv::imwrite("frame_" + std::to_string(frame_index) + ".png", img);
}
int main(int, char **)
{
// Initialize the screen texture
screen.init(SCREENX, SCREENY);
ImGui::CreateContext();
ImGui_ImplSoftrender_Init(&screen);
ImGuiStyle &style = ImGui::GetStyle();
style.AntiAliasedLines = false;
style.AntiAliasedFill = false;
style.WindowRounding = 0.0f;
ImGuiIO &io = ImGui::GetIO();
uint8_t *pixels;
int width, height;
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
fontAtlas.init(width, height, (alpha8_t *)pixels);
io.Fonts->TexID = reinterpret_cast<uintptr_t>(&fontAtlas);
io.MouseDrawCursor = true;
int k = 0;
float f = 0.0f;
unsigned long drawTime = 0;
unsigned long renderTime = 0;
unsigned long rasterTime = 0;
unsigned int t = millis();
while (k < 3)
{
ImGuiIO &io = ImGui::GetIO();
io.DeltaTime = 1.0f / 60.0f;
io.MousePos.x = 100*k;
io.MousePos.y = 200*k;
ImGui_ImplSoftrender_NewFrame();
ImGui::NewFrame();
ImGui::SetWindowPos(ImVec2(0.0, 0.0));
ImGui::SetWindowSize(ImVec2(SCREENX, SCREENY));
f += 0.05;
if (f > 1.0f) f = 0.0f;
unsigned int deltaTime = millis() - t;
t += deltaTime;
deltaTime -= (drawTime + renderTime + rasterTime);
ImGui::Text("Hardware write time %ld ms", drawTime);
ImGui::Text("Render time %ld ms", renderTime);
ImGui::Text("Raster time %ld ms", rasterTime);
ImGui::Text("Remaining time %d ms", deltaTime);
ImGui::Text("abcdefghijklmnopqrstuvwxyz");
ImGui::Text("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
ImGui::Text("0123456789");
ImGui::Text("!@#$%%^&*()_+");
ImGui::Text("~`-=[]\\;',./{}|:\"<>?");
ImGui::Text("Mouse position: (%f, %f)", io.MousePos.x, io.MousePos.y);
ImGui::SliderFloat("SliderFloat", &f, 0.0f, 1.0f);
ImGui::ShowDemoWindow();
renderTime = millis();
ImGui::Render();
renderTime = millis() - renderTime;
rasterTime = millis();
ImGui_ImplSoftrender_RenderDrawData(ImGui::GetDrawData());
rasterTime = millis() - rasterTime;
drawTime = millis();
screen_draw(k);
drawTime = millis() - drawTime;
k++;
}
}