feat: switched to qt and refactored
This commit is contained in:
64
main.cpp
64
main.cpp
@@ -1,12 +1,18 @@
|
||||
#include "fastmath.hpp"
|
||||
#include "polygon.hpp"
|
||||
#include "renderer.hpp"
|
||||
#include "rendertarget.hpp"
|
||||
#include <QApplication>
|
||||
#include <QImage>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <functional>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define HIGHT 64
|
||||
#define WIDTH 64
|
||||
|
||||
@@ -56,24 +62,54 @@ void drawImage(unsigned short *img) {
|
||||
img[(y.i >> SHIFT_AMOUNT) * RWIDTH + (x.i >> SHIFT_AMOUNT)] =
|
||||
(unsigned short)23; // (((-normal[1]+(1 <<
|
||||
// SHIFT_AMOUNT))*14)>>SHIFT_AMOUNT);
|
||||
} else {
|
||||
img[(y.i >> SHIFT_AMOUNT) * RWIDTH + (x.i >> SHIFT_AMOUNT)] =
|
||||
(unsigned short)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("done writing %d \n", *(img + sizeof(unsigned short) * 32 * 32));
|
||||
}
|
||||
|
||||
int main() {
|
||||
unsigned short *img =
|
||||
(unsigned short *)malloc(128 * 128 * sizeof(unsigned short));
|
||||
while (true) {
|
||||
drawImage(img);
|
||||
printf("%s", drawToString(img));
|
||||
return 0;
|
||||
// sleep(0.001);
|
||||
int main(int argc, char *argv[]) {
|
||||
Rendertarget target(128, 128);
|
||||
Renderer renderer;
|
||||
renderer.target = ⌖
|
||||
|
||||
polygon poly =
|
||||
polygon(vec3(0.9, 0.9, 0.0), vec3(0.5, 0.1, 0.0), vec3(0.1, 0.9, 0.0));
|
||||
|
||||
renderer.render(&poly);
|
||||
QApplication a(argc, argv);
|
||||
|
||||
uint8_t *pixel = new uint8_t[64 * 64 * 3];
|
||||
/*for (int i = 0; i < 64 * 64 * 3; i++) {
|
||||
pixel[i] = target.pixels[i].i >> SHIFT_AMOUNT;
|
||||
}*/
|
||||
std::function<void(int, uint32_t *)> addTo = [&target](int start,
|
||||
uint32_t *arr) {
|
||||
for (int c = 0; c < 3; c++) {
|
||||
arr[c] += target.pixels[start + c].i >> SHIFT_AMOUNT;
|
||||
}
|
||||
};
|
||||
|
||||
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 * y + x) * 3 + c] = result[c] >> 2; /*
|
||||
target.pixels[(target.width * y * 2 + x * 2) * 3 + c].i >>
|
||||
SHIFT_AMOUNT;*/
|
||||
}
|
||||
}
|
||||
}
|
||||
// printf("%s", test);
|
||||
return 0;
|
||||
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()));
|
||||
widget.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user