From fdde5353c259bdab24fc9a7d33b8feff097b128d Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Mon, 22 Jul 2024 20:38:24 -0400 Subject: [PATCH] Working version before opt --- build.sh | 2 +- main.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 51ef5f5..2a51514 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ #!/bin/sh -gcc -O3 -Wall main.c -o texmap +gcc -O2 -Wall main.c -lm -o texmap diff --git a/main.c b/main.c index b76f808..0b7fdf7 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ #include #include #include +#include // You need to generate this with textoc.h #include "texture.h" @@ -54,9 +55,9 @@ void drawTexInto(struct texture tex, struct texture buffer, struct rect texbound // multiplication per pixel float stepx = (float)texwidth / outwidth; float stepy = (float)texheight / outheight; - float texx = texbounds.x1; - float texy = texbounds.y1; - log("%f,%f step %f,%f", texx, texy, stepx, stepy); + float texx = texbounds.x1 * 3; + float texy = texbounds.y1 * 3; + //log("%f,%f step %f,%f", texx, texy, stepx, stepy); // Buffer is R G B for each pixel, then across then down. If you want X, Y, // it's: 3 * (x + y * width) for(int y = bufbounds.y1; y < bufbounds.y2; y++) { @@ -96,8 +97,15 @@ int main() { // We actually stretch a texture here struct rect texrect = { 0, 0, 16, 16 }; - struct rect bufrect = { 100, 100, 502, 192 }; - drawTexInto(tex, fb, texrect, bufrect); + struct rect bufrect = { 10, 13, 502, 509 }; + + clock_t start = clock(); + for(int i = 0; i < 50; i++) { //overdraw factor + drawTexInto(tex, fb, texrect, bufrect); + } + clock_t end = clock(); + double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + log("1000 iterations took: %fs", cpu_time_used); // Dump the image to the ppm dump_ppm(fb);