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]);
12 inline void dump(glm::vec4 v) {
13 fprintf(stderr, "{%f,%f,%f,%f}\n", v.x, v.y, v.z, v.w);
15 inline void dump(glm::vec3 v) {
16 fprintf(stderr, "{%f,%f,%f}\n", v.x, v.y, v.z);
18 inline void dump(glm::vec2 v) { fprintf(stderr, "{%f,%f}\n", v.x, v.y); }
22 short dx /* Width */, dy /* Height */, head2;
23 char pic[1000 * 1000 * 3];
25 char tgahead[12] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
26 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
30 glGetIntegerv(GL_VIEWPORT, ps);
31 GLint width = ps[2], height = ps[3];
32 TGA *tga = (TGA *)malloc(sizeof(TGA));
33 memcpy(tga->head, tgahead, 12);
37 // TODO: flip -- the image is upside down so far
38 glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, tga->pic);
39 FILE *cc = fopen("fbo.tga", "wb");
40 fwrite(tga, 1, (18 + 3 * width * height), cc);
45 void saveImage(char *img, short width, short height, const char *file) {
46 TGA *tga = (TGA *)malloc(sizeof(TGA));
47 memcpy(tga->head, tgahead, 12);
51 memcpy(tga->pic, img, width * height * 3);
52 // TODO: flip -- the image is upside down so far
53 FILE *cc = fopen(file, "wb");
54 fwrite(tga, 1, (18 + 3 * width * height), cc);
59 void saveGrayscale(float *img, short width, short height, const char *file) {
60 char *bytes = (char*)malloc(sizeof(char) * width * height * 3);
61 for (int i = 0; i < width; i++) {
62 for (int j = 0; j < height; j++) {
63 for (int z = 0; z < 3; z++) {
64 bytes[i * 3 + j * width * 3 + z] = (int)(img[i + j * width] * 255.f * 2);
68 saveImage(bytes, width, height, file);