added shaders, but ran into performance issues. will need refactor

This commit is contained in:
2026-07-07 17:57:25 -07:00
parent ad2e84c279
commit 85cfdaab49
12 changed files with 139 additions and 78 deletions
+27 -12
View File
@@ -19,8 +19,12 @@
// #include "draw.cpp"
#include "shaders/shader.cpp"
#include "shaders/colorshader.cpp"
#include "shaders/gradientshader.cpp"
#include "mapper.cpp"
// #include "shaders/gradientshader.cpp"
#include "shaders/hgradientshader.cpp"
#include "shaders/vgradientshader.cpp"
// #include "mapper.cpp"
#include <time.h>
static void onKey(void *user, uint32_t keycode, uint32_t state) {
if (keycode == 1) {
@@ -34,26 +38,36 @@ static void onKey(void *user, uint32_t keycode, uint32_t state) {
int main(void) {
uint16_t w = 800, h = 480;
UwU::GradientShader fuchsia = UwU::GradientShader(UwU::Color(0xb00b69ff), UwU::Color(0xb00b6940));
// UwU::GradientShader fuchsia = UwU::GradientShader(UwU::Color(0xb00b69ff), UwU::Color(0xb00b6940));
// UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff));
UwU::VGradientShader fuchsia = UwU::VGradientShader(69, UwU::Color(0xb00b69ff), 420, UwU::Color(0x00000000));
int32_t rectScale = (255 * 65536) / 351;
UwU::Mapper rectMapper = UwU::Mapper(UwU::Vec2(-69, 0), UwU::Vec2(69, 0), UwU::Matrix4(rectScale, 0, 0, 1));
// rectScale = 41233; //-23806
// UwU::Mapper rectMapper = UwU::Mapper(UwU::Vec2(0, 0), UwU::Vec2(0, 0), UwU::Matrix4(0, 0, 0, 0));
UwU::Color red = UwU::Color(0xff000080);
UwU::Color green = UwU::Color(0x00ff00ff);
UwU::Color blue = UwU::Color(0x0000ff80);
// UwU::Color alpha = UwU::Color(0x00000000);
UwU::Surface surface = UwU::Surface(w, h, onKey);
// draw.rainbow();
// UwU::Buffer buffer = UwU::Buffer(surface.getWidth(), surface.getHeight());
UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420);
rectangle.draw(surface.buffer, rectMapper, fuchsia);
// draw.rainbow();
// draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red);
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
rectangle.draw(surface.buffer, fuchsia);
clock_gettime(CLOCK_MONOTONIC, &end);
long elapsed_ns = (end.tv_sec - start.tv_sec) * 1000000000L +
(end.tv_nsec - start.tv_nsec);
printf("Elapsed: %ld ns\n", elapsed_ns);
UwU::Trapezoid trapezoid = UwU::Trapezoid(300, 400, 360, 380, 600, 480);
trapezoid.draw(surface.buffer, red);
UwU::Triangle triangle = UwU::Triangle(280, 100, 240, 290, 320, 300);
triangle.draw(surface.buffer, blue);
@@ -75,6 +89,7 @@ int main(void) {
lines[i].draw(surface.buffer, green);
}
surface.present();
while (!surface.shouldClose()) {}