7 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
9 inline void dump(glm::mat4 m) {
10 for (int i = 0; i < 4; i++)
11 fprintf(stderr, "%f,%f,%f,%f\n", m[i][0], m[i][1], m[i][2], m[i][3]);
14 inline void dump(glm::vec4 v) {
15 fprintf(stderr, "{%f,%f,%f,%f}\n", v.x, v.y, v.z, v.w);
17 inline void dump(glm::vec3 v) {
18 fprintf(stderr, "{%f,%f,%f}\n", v.x, v.y, v.z);
20 inline void dump(glm::vec2 v) { fprintf(stderr, "{%f,%f}\n", v.x, v.y); }
24 short dx /* Width */, dy /* Height */, head2;
25 char pic[1000 * 1000 * 3];
27 char tgahead[12] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
32 glGetIntegerv(GL_VIEWPORT, ps);
33 GLint width = ps[2], height = ps[3];
34 TGA *tga = (TGA *)malloc(sizeof(TGA));
35 memcpy(tga->head, tgahead, 12);
39 // TODO: flip -- the image is upside down so far
40 glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, tga->pic);
41 FILE *cc = fopen("fbo.tga", "wb");
42 fwrite(tga, 1, (18 + 3 * width * height), cc);
47 void saveImage(char *img, short width, short height, const char *file) {
48 TGA *tga = (TGA *)malloc(sizeof(TGA));
49 memcpy(tga->head, tgahead, 12);
53 memcpy(tga->pic, img, width * height * 3);
54 // TODO: flip -- the image is upside down so far
55 FILE *cc = fopen(file, "wb");
56 fwrite(tga, 1, (18 + 3 * width * height), cc);
61 void saveGrayscale(float *img, short width, short height, const char *file) {
62 char *bytes = (char*)malloc(sizeof(char) * width * height * 3);
63 for (int i = 0; i < width; i++) {
64 for (int j = 0; j < height; j++) {
65 for (int z = 0; z < 3; z++) {
66 bytes[i * 3 + j * width * 3 + z] = (int)(img[i + j * width] * 255.f * 2);
70 saveImage(bytes, width, height, file);