Working version before opt

This commit is contained in:
Carlos Sanchez 2024-07-22 20:38:24 -04:00
parent e56131c3f9
commit fdde5353c2
2 changed files with 14 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
gcc -O3 -Wall main.c -o texmap gcc -O2 -Wall main.c -lm -o texmap

16
main.c
View File

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <time.h>
// You need to generate this with textoc.h // You need to generate this with textoc.h
#include "texture.h" #include "texture.h"
@ -54,9 +55,9 @@ void drawTexInto(struct texture tex, struct texture buffer, struct rect texbound
// multiplication per pixel // multiplication per pixel
float stepx = (float)texwidth / outwidth; float stepx = (float)texwidth / outwidth;
float stepy = (float)texheight / outheight; float stepy = (float)texheight / outheight;
float texx = texbounds.x1; float texx = texbounds.x1 * 3;
float texy = texbounds.y1; float texy = texbounds.y1 * 3;
log("%f,%f step %f,%f", texx, texy, stepx, stepy); //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, // Buffer is R G B for each pixel, then across then down. If you want X, Y,
// it's: 3 * (x + y * width) // it's: 3 * (x + y * width)
for(int y = bufbounds.y1; y < bufbounds.y2; y++) { for(int y = bufbounds.y1; y < bufbounds.y2; y++) {
@ -96,8 +97,15 @@ int main() {
// We actually stretch a texture here // We actually stretch a texture here
struct rect texrect = { 0, 0, 16, 16 }; struct rect texrect = { 0, 0, 16, 16 };
struct rect bufrect = { 100, 100, 502, 192 }; 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); 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 the image to the ppm
dump_ppm(fb); dump_ppm(fb);