#include <cstring>
#include <glm/glm.hpp>
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
inline void dump(glm::mat4 m) {
for (int i = 0; i < 4; i++)
fprintf(stderr, "%f,%f,%f,%f\n", m[i][0], m[i][1], m[i][2], m[i][3]);
typedef struct {
char head[12];
short dx /* Width */, dy /* Height */, head2;
- char pic[600 * 400][3];
+ char pic[1000 * 1000 * 3];
} TGA;
char tgahead[12] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
void saveFBO() {
- float width = 600, height = 400;
+ GLint ps[4];
+ glGetIntegerv(GL_VIEWPORT, ps);
+ GLint width = ps[2], height = ps[3];
TGA *tga = (TGA *)malloc(sizeof(TGA));
memcpy(tga->head, tgahead, 12);
tga->dx = width;
tga->dy = height;
tga->head2 = 0x2018;
// TODO: flip -- the image is upside down so far
- glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, tga->pic[0]);
+ glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, tga->pic);
FILE *cc = fopen("fbo.tga", "wb");
fwrite(tga, 1, (18 + 3 * width * height), cc);
fclose(cc);
free(tga);
}
+
+void saveImage(char *img, short width, short height, const char *file) {
+ TGA *tga = (TGA *)malloc(sizeof(TGA));
+ memcpy(tga->head, tgahead, 12);
+ tga->dx = width;
+ tga->dy = height;
+ tga->head2 = 0x2018;
+ memcpy(tga->pic, img, width * height * 3);
+ // TODO: flip -- the image is upside down so far
+ FILE *cc = fopen(file, "wb");
+ fwrite(tga, 1, (18 + 3 * width * height), cc);
+ fclose(cc);
+ free(tga);
+}
+
+void saveGrayscale(float *img, short width, short height, const char *file) {
+ char *bytes = (char*)malloc(sizeof(char) * width * height * 3);
+ for (int i = 0; i < width; i++) {
+ for (int j = 0; j < height; j++) {
+ for (int z = 0; z < 3; z++) {
+ bytes[i * 3 + j * width * 3 + z] = (int)(img[i + j * width] * 255.f * 2);
+ }
+ }
+ }
+ saveImage(bytes, width, height, file);
+ free(bytes);
+}