This commit is contained in:
2026-04-03 12:34:06 +02:00
parent cd77088dbf
commit 85dbded287
25 changed files with 2711 additions and 165 deletions

View File

@@ -1,14 +1,11 @@
#include "MainWindow.hpp"
#include "fastmath.hpp"
#include "plane.hpp"
#include "polygon.hpp"
#include "renderer.hpp"
#include "rendertarget.hpp"
#include "testModel.hpp"
#include <QApplication>
#include <QImage>
#include <QLabel>
#include <QObject>
#include <QPixmap>
#include <QTimer>
#include <chrono>
#include <functional>
#include <math.h>
@@ -46,40 +43,11 @@ char *drawToString(unsigned short *img) {
return textImg;
}
void drawImage(unsigned short *img) {
decimal heightPerPix = decimal(1.0) / decimal((float)(HIGHT * FAA_FAC));
decimal widthPerPix = decimal(1.0) / decimal((float)(WIDTH * FAA_FAC));
polygon poly = polygon(vec3(0.9, 0.9, 0.0) * decimal(128.0),
vec3(0.5, 0.1, 0.0) * decimal(128.0),
vec3(0.1, 0.9, 0.0) * decimal(128.0));
// printf("\n hpp: %f, wpp: %f
// \n",TO_FLOAT(heightPerPix),TO_FLOAT(widthPerPix)); calcViewPos(t);
for (decimal y = 0; y < decimal((float)(RHIGHT)); y += decimal(1.0)) {
for (decimal x = 0; x < decimal((float)(RWIDTH)); x += decimal(1.0)) {
vec3 p = vec3(x, y, 0.0);
if (poly.contains(p)) {
img[(y.i >> SHIFT_AMOUNT) * RWIDTH + (x.i >> SHIFT_AMOUNT)] =
(unsigned short)23; // (((-normal[1]+(1 <<
// SHIFT_AMOUNT))*14)>>SHIFT_AMOUNT);
}
}
}
printf("done writing %d \n", *(img + sizeof(unsigned short) * 32 * 32));
}
int main(int argc, char *argv[]) {
Rendertarget target(128, 128);
Renderer renderer;
renderer.target = &target;
polygon poly =
polygon(vec3(0.9, 0.9, 1.0), vec3(0.5, 0.1, 1.0), vec3(0.1, 0.9, 1.0));
std::chrono::steady_clock::time_point begin =
std::chrono::steady_clock::now();
renderer.render(&testModel, mat4::translation(vec3(0.0f, -1.0f, 5.0f)) *
@@ -103,23 +71,48 @@ int main(int argc, char *argv[]) {
arr[c] += target.pixels[start + c];
}
};
vec3 pos;
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);
MainWindow widget;
widget.setWindowTitle("SoftwareRenderer");
// display.setPixmap(QPixmap::fromImage(img).scaled(widget.size()));
auto keyEvent = [&pos](QKeyEvent *e) {
decimal step = decimal(0.5);
switch (e->key()) {
case Qt::Key_W:
pos.z() += step;
break;
case Qt::Key_S:
pos.z() -= step;
break;
case Qt::Key_A:
pos.x() += step;
break;
case Qt::Key_D:
pos.x() -= step;
break;
}
};
widget.keyDownCallBack = keyEvent;
float rot = 0.f;
std::function<void()> renderLoop = [&addTo, &target, &pixel, &renderer,
&display, &widget, &img, &rot]() {
&widget, &rot, &pos]() {
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));
target.clearDepth();
target.clearTarget();
// renderer.render(&testModel, mat4::translation(vec3(0.0f,
// -1.0f, 5.0f)) *
// mat4::rotateOnY(rot));
// renderer.render(&testModel, mat4::translation(vec3(1.0f,
// -1.0f, 7.0f)) *
// mat4::rotateOnY(rot));
renderer.render(&plane, mat4::translation(pos));
std::chrono::steady_clock::time_point end =
std::chrono::steady_clock::now();
@@ -143,7 +136,8 @@ int main(int argc, char *argv[]) {
}
}
// QImage img((unsigned char *)pixel, 64, 64, QImage::Format_RGB888);
display.setPixmap(QPixmap::fromImage(img).scaled(widget.size() * 1));
widget.updateLabel(pixel);
rot += 0.1f;
};
renderLoop();