Initial commit
[clouds.git] / debug.hpp
1 #include <GL/glew.h>
2 #include <cstdio>
3 #include <cstdlib>
4 #include <cstring>
5 #include <glm/glm.hpp>
6
7 inline void dump(glm::mat4 m) {
8   for (int i = 0; i < 4; i++)
9     fprintf(stderr, "%f,%f,%f,%f\n", m[i][0], m[i][1], m[i][2], m[i][3]);
10 }
11
12 inline void dump(glm::vec4 v) {
13   fprintf(stderr, "{%f,%f,%f,%f}\n", v.x, v.y, v.z, v.w);
14 }
15 inline void dump(glm::vec3 v) {
16   fprintf(stderr, "{%f,%f,%f}\n", v.x, v.y, v.z);
17 }
18 inline void dump(glm::vec2 v) { fprintf(stderr, "{%f,%f}\n", v.x, v.y); }
19
20 typedef struct {
21   char head[12];
22   short dx /* Width */, dy /* Height */, head2;
23   char pic[600 * 400][3];
24 } TGA;
25 char tgahead[12] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
26                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
27
28 void saveFBO() {
29   float width = 600, height = 400;
30   TGA *tga = (TGA *)malloc(sizeof(TGA));
31   memcpy(tga->head, tgahead, 12);
32   tga->dx = width;
33   tga->dy = height;
34   tga->head2 = 0x2018;
35   // TODO: flip -- the image is upside down so far
36   glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, tga->pic[0]);
37   FILE *cc = fopen("fbo.tga", "wb");
38   fwrite(tga, 1, (18 + 3 * width * height), cc);
39   fclose(cc);
40   free(tga);
41 }