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[600 * 400 * 3];
25 char tgahead[12] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
26 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
29 float width = 600, height = 400;
30 TGA *tga = (TGA *)malloc(sizeof(TGA));
31 memcpy(tga->head, tgahead, 12);
35 // TODO: flip -- the image is upside down so far
36 glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, tga->pic);
37 FILE *cc = fopen("fbo.tga", "wb");
38 fwrite(tga, 1, (18 + 3 * width * height), cc);
43 void saveImage(char *img, short width, short height, const char *file) {
44 TGA *tga = (TGA *)malloc(sizeof(TGA));
45 memcpy(tga->head, tgahead, 12);
49 memcpy(tga->pic, img, width * height * 3);
50 // TODO: flip -- the image is upside down so far
51 FILE *cc = fopen(file, "wb");
52 fwrite(tga, 1, (18 + 3 * width * height), cc);
57 void saveGrayscale(float *img, short width, short height, const char *file) {
58 char *bytes = (char*)malloc(sizeof(char) * width * height * 3);
59 for (int i = 0; i < width; i++) {
60 for (int j = 0; j < height; j++) {
61 for (int z = 0; z < 3; z++) {
62 bytes[i * 3 + j * width * 3 + z] = (int)(img[i + j * width] * 255.f * 2);
66 saveImage(bytes, width, height, file);