diff --git a/main.cpp b/main.cpp index b3e1465..bf83600 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -102,26 +104,53 @@ int main(int argc, char *argv[]) { } }; - for (int x = 0; x < 64; x++) { - for (int y = 0; y < 64; y++) { - uint32_t result[3] = {}; - addTo((target.width * y * 2 + x * 2) * 3, result); - addTo((target.width * (y * 2 + 1) + x * 2) * 3, result); - addTo((target.width * y * 2 + (x * 2 + 1)) * 3, result); - addTo((target.width * (y * 2 + 1) + (x * 2 + 1)) * 3, result); - for (int c = 0; c < 3; c++) { - pixel[(WIDTH * (WIDTH - y - 1) + WIDTH - x - 1) * 3 + c] = - result[c] >> 2; - } - } - } 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())); + + // display.setPixmap(QPixmap::fromImage(img).scaled(widget.size())); + + float rot = 0.f; + std::function 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( + end - begin) + .count() + << "[ms]" << std::endl; + + for (int x = 0; x < 64; x++) { + for (int y = 0; y < 64; y++) { + uint32_t result[3] = {}; + addTo((target.width * y * 2 + x * 2) * 3, result); + addTo((target.width * (y * 2 + 1) + x * 2) * 3, result); + addTo((target.width * y * 2 + (x * 2 + 1)) * 3, result); + addTo((target.width * (y * 2 + 1) + (x * 2 + 1)) * 3, result); + for (int c = 0; c < 3; c++) { + pixel[(WIDTH * (WIDTH - y - 1) + WIDTH - x - 1) * 3 + c] = + result[c] >> 2; + } + } + } + // 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(); }