Textures are fun
This commit is contained in:
parent
ecab593313
commit
43b9598a16
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,4 @@
|
||||
texmap
|
||||
*.png
|
||||
*.ppm
|
||||
wget-log
|
||||
|
37
main.c
37
main.c
@ -1,6 +1,41 @@
|
||||
#include <stdio.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() {
|
||||
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
6
run.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
./build.sh
|
||||
./texmap > image.ppm
|
||||
convert image.ppm image.png
|
||||
|
Loading…
Reference in New Issue
Block a user