feat: animation in main

This commit is contained in:
2025-12-27 23:51:55 +01:00
parent 51989119ba
commit a13a9c5489

View File

@@ -6,7 +6,9 @@
#include <QApplication>
#include <QImage>
#include <QLabel>
#include <QObject>
#include <QPixmap>
#include <QTimer>
#include <chrono>
#include <functional>
#include <math.h>
@@ -102,6 +104,31 @@ int main(int argc, char *argv[]) {
}
};
QApplication a(argc, argv);
QWidget widget;
widget.setAutoFillBackground(true);
widget.setGeometry(0, 0, 500, 500);
QLabel display(&widget);
QImage img((unsigned char *)pixel, 64, 64, QImage::Format_RGB888);
// display.setPixmap(QPixmap::fromImage(img).scaled(widget.size()));
float rot = 0.f;
std::function<void()> renderLoop = [&addTo, &target, &pixel, &renderer,
&display, &widget, &img, &rot]() {
std::chrono::steady_clock::time_point begin =
std::chrono::steady_clock::now();
renderer.render(&testModel, mat4::translation(vec3(0.0f, -1.0f, 5.0f)) *
mat4::rotateOnY(rot));
std::chrono::steady_clock::time_point end =
std::chrono::steady_clock::now();
std::cout << "Time difference = "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
end - begin)
.count()
<< "[ms]" << std::endl;
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
uint32_t result[3] = {};
@@ -115,13 +142,15 @@ int main(int argc, char *argv[]) {
}
}
}
QApplication a(argc, argv);
QWidget widget;
widget.setAutoFillBackground(true);
widget.setGeometry(0, 0, 500, 500);
QLabel display(&widget);
QImage img((unsigned char *)pixel, 64, 64, QImage::Format_RGB888);
display.setPixmap(QPixmap::fromImage(img).scaled(widget.size()));
// QImage img((unsigned char *)pixel, 64, 64, QImage::Format_RGB888);
display.setPixmap(QPixmap::fromImage(img).scaled(widget.size() * 1));
rot += 0.1f;
};
renderLoop();
widget.show();
QTimer timer;
timer.setInterval(20);
timer.start();
QObject::connect(&timer, &QTimer::timeout, &widget, renderLoop);
return a.exec();
}