/* illum.c */

#include "illum.h"

#include <stdlib.h>
#include <stdio.h>
#include "lodepng/lodepng.h"

texture texture_alloc(const char* filename) {
	texture ret;
	int i = LodePNG_decode32_file(
		(unsigned char**) &ret.pixels, &ret.width, &ret.height, filename
	);
	if (i) {
		fprintf(
			stderr, "FATAL: Error #%d loading texture \"%s\"\n",
			i, filename
		);
	} else {
		fprintf(
			stderr, "INFO: Loaded texture \"%s\" (%dx%d)\n",
			filename, ret.width, ret.height
		);
	}
	return ret;
}

void texture_free(texture* tex) {
	free(tex->pixels);
}
