Textures are fun

This commit is contained in:
Carlos Sanchez 2024-07-22 19:40:13 -04:00
parent ecab593313
commit 43b9598a16
4 changed files with 55 additions and 1 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
texmap texmap
*.png
*.ppm
wget-log

37
main.c
View File

@ -1,6 +1,41 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h>
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() { 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");
} }

6
run.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
./build.sh
./texmap > image.ppm
convert image.ppm image.png

10
textoc.sh Normal file
View File

@ -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