diff --git a/.gitignore b/.gitignore index 9c0f052..ac7f75e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ texmap +*.png +*.ppm +wget-log diff --git a/main.c b/main.c index 2c76de7..74dfe66 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,41 @@ #include #include +#include +#include + +typedef uint8_t u8; + +#define CDEPTH 255 + +#define log(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__) +#define panic(fmt, ...) { fprintf(stderr, "PANIC: " fmt "\n", ##__VA_ARGS__); exit(EXIT_FAILURE); } + +// fb is framebuffer. Thsi dumps a color version (rgb) of a framebuffer +// to stdout, which you can pipe to a file or some shit idk +void dump_ppm(u8 * fb, int width, int height) { + log("Dumping framebuffer %dx%d", width, height); + printf("P3\n%d %d\n%d\n# Image start\n", width, height, CDEPTH); + for(int i = 0; i < width * height * 3; i+=3) + printf("%d %d %d\n", fb[i], fb[i+1], fb[i+2]); + printf("\n"); +} int main() { - printf("Hello world!\n"); + log("Program start"); + + const int width = 512; + const int height = 512; + const int fbsize = width * height * 3 * sizeof(u8); + + u8 * fb = malloc(fbsize); + if(!fb) { + panic("Can't allocate framebuffer"); + } + memset(fb, 0, fbsize); + + // We actually stretch a texture + + dump_ppm(fb, width, height); + + log("Program end"); } diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..799ca48 --- /dev/null +++ b/run.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +./build.sh +./texmap > image.ppm +convert image.ppm image.png + diff --git a/textoc.sh b/textoc.sh new file mode 100644 index 0000000..8a14a12 --- /dev/null +++ b/textoc.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if [ $# -lt 1 ] +then + echo "You must pass in the texture!" + exit 1 +fi + +convert $1 -compress none $1.ppm +