115 lines
3.2 KiB
C++
115 lines
3.2 KiB
C++
// #pragma once
|
|
|
|
#include "waymini/waymini.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
// #include "datatypes.cpp"
|
|
// #include "helpers.cpp"
|
|
// #include "buffer.cpp"
|
|
// #include "surface.cpp"
|
|
// #include "primatives/line.cpp"
|
|
// #include "primatives/point.cpp"
|
|
// #include "primatives/rectangle.cpp"
|
|
// #include "primatives/trapezoid.cpp"
|
|
// #include "primatives/triangle.cpp"
|
|
// #include "shader.cpp"
|
|
|
|
#include "uwugl.h"
|
|
#include <time.h>
|
|
#include "font.cpp"
|
|
|
|
|
|
static void onKey(void *user, uint32_t keycode, uint32_t state) {
|
|
if (keycode == 1) {
|
|
exit(1);
|
|
}
|
|
(void)user;
|
|
const char *label = state ? "down" : "up ";
|
|
printf("key %s: %u\n", label, keycode);
|
|
fflush(stdout);
|
|
}
|
|
|
|
int main(void) {
|
|
uint16_t w = 800, h = 480;
|
|
|
|
UwU::Surface surface = UwU::Surface(w, h, onKey);
|
|
|
|
// UwU::Color fuchsia = UwU::Color(0xb00b69ff);
|
|
UwU::Color red = UwU::Color(0xff0000ff);
|
|
UwU::Color green = UwU::Color(0x00ff00ff);
|
|
UwU::Color blue = UwU::Color(0x0000ffff);
|
|
|
|
// UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff));
|
|
UwU::VGradientShader bisexual = UwU::VGradientShader(0, 351, red, blue);
|
|
UwU::OffsetMapper offsetMapper = UwU::OffsetMapper();
|
|
UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420);
|
|
rectangle.draw(surface.buffer, offsetMapper, bisexual);
|
|
|
|
UwU::ColorShader greenShader = UwU::ColorShader(green);
|
|
UwU::NullMapper nullMapper = UwU::NullMapper();
|
|
UwU::Point point = UwU::Point(187, 37);
|
|
point.draw(surface.buffer, nullMapper, greenShader);
|
|
|
|
UwU::ColorShader blueShader = UwU::ColorShader(blue);
|
|
UwU::Trapezoid trapezoid = UwU::Trapezoid(100, 300, 690, 320, 720, 780);
|
|
trapezoid.draw(surface.buffer, nullMapper, blueShader);
|
|
|
|
UwU::ColorShader redShader = UwU::ColorShader(red);
|
|
UwU::Triangle triangle = UwU::Triangle(140, 140, 60, 400, 240, 240);
|
|
triangle.draw(surface.buffer, nullMapper, redShader);
|
|
|
|
// // Benchmarking
|
|
// struct timespec start, end;
|
|
// const int WARMUP = 100;
|
|
// const int BATCH = 1000;
|
|
// const int SAMPLES = 10;
|
|
|
|
// for (int i = 0; i < WARMUP; i++) {
|
|
// rectangle.draw(surface.buffer, gradientBuffer);
|
|
// }
|
|
// long times[SAMPLES];
|
|
// for (int s = 0; s < SAMPLES; s++) {
|
|
// clock_gettime(CLOCK_MONOTONIC, &start);
|
|
// for (int i = 0; i < BATCH; i++) {
|
|
// rectangle.draw(surface.buffer, gradientBuffer);
|
|
// }
|
|
// clock_gettime(CLOCK_MONOTONIC, &end);
|
|
// times[s] = (end.tv_sec - start.tv_sec) * 1000000000L + (end.tv_nsec - start.tv_nsec);
|
|
// }
|
|
// long timeAvg = 0;
|
|
// for (int i = 0; i < SAMPLES; i++) {
|
|
// timeAvg += times[i];
|
|
// }
|
|
// timeAvg /= SAMPLES;
|
|
// timeAvg /= BATCH;
|
|
// printf("Elapsed: %ld ns\n", timeAvg);
|
|
|
|
|
|
UwU::Line lines[8] {
|
|
UwU::Line(300, 100, 250, 469),
|
|
UwU::Line(250, 100, 300, 469),
|
|
UwU::Line(300, 100, 469, 250),
|
|
UwU::Line(469, 100, 300, 250),
|
|
UwU::Line(100, 300, 250, 469),
|
|
UwU::Line(250, 300, 100, 469),
|
|
UwU::Line(100, 300, 469, 250),
|
|
UwU::Line(469, 300, 100, 250)
|
|
};
|
|
|
|
for (uint16_t i = 0; i < 8; i++) {
|
|
lines[i].draw(surface.buffer, nullMapper, blueShader);
|
|
}
|
|
|
|
|
|
surface.present();
|
|
|
|
while (!surface.shouldClose()) {}
|
|
|
|
surface.destroy();
|
|
return 0;
|
|
}
|