Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-26 23:24:26 +0000
committerStijn Buys <ingar@osirion.org>2008-03-26 23:24:26 +0000
commit3d993058e5078fbdfd92d479281ad93bb40a4bc6 (patch)
treefd578d5a44246a90fc08cdf6b9a18f02313ce431 /src/client/video.cc
parent2b9f068e7ee4c0d249c715f9eb5a3c2c8a11e6f8 (diff)
improved TGA handling
Diffstat (limited to 'src/client/video.cc')
-rw-r--r--src/client/video.cc56
1 files changed, 5 insertions, 51 deletions
diff --git a/src/client/video.cc b/src/client/video.cc
index e41f774..cd25d19 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -10,6 +10,7 @@
#include "client/video.h"
#include "client/view.h"
#include "render/render.h"
+#include "render/tga.h"
#include "core/core.h"
#include "filesystem/filesystem.h"
#include "sys/sys.h"
@@ -181,59 +182,12 @@ void screenshot()
}
} while (!available);
- std::ofstream ofs(filename.c_str());
+ render::Image image((unsigned int)video::width, (unsigned int)video::height, 3);
- if (!ofs.is_open()) {
- con_warn << "Could not write " << shortname << std::endl;
- return;
- }
+ glReadPixels(0, 0, (GLsizei) video::width, (GLsizei) video::height,
+ GL_RGB, GL_UNSIGNED_BYTE, (void *) image.data());
- // TGA header
- // TODO: RL-encoding, image ID
-
- // note: see http://www.fileformat.info/format/tga/egff.htm
- unsigned char header[18];
- memset(header, 0, sizeof(header));
-
- // byte 0 - image ID field lenght = 0 (no image ID field present)
- // byte 1 - color map type = 0 (no palette present)
- // byte 2 - image type = 2 (truecolor without RLE)
- header[2] = 2;
- // byte 3-11 - palette data (not used)
- // byte 12+13 - image width
- header[12] = (video::width & 0xff);
- header[13] = ((video::width >> 8) & 0xff);
- // byte 14+15 - image height
- header[14] = (video::height & 0xff);
- header[15] = ((video::height >> 8) & 0xff);
- // byte 16 - image color depth = 24 (RGB)
- header[16] = 24;
- // byte 17 - image descriptor byte
- header[17] = 0;
-
- // allocate buffer to hold the RGB data
- unsigned char *rgb_data = (unsigned char *) malloc(video::width * video::height * 3);
-
- // read OpenGL pixels into the buffer
- //glReadBuffer(GL_BACK);
- glReadPixels(0, 0, (GLsizei) video::width, (GLsizei) video::height, GL_RGB, GL_UNSIGNED_BYTE, (void *) rgb_data);
-
- // either OpenGL actually returns BGR, or TGA wants BGR
- for (size_t i = 0; i < (size_t) (video::width * video::height); i++) {
- unsigned char tmp = rgb_data[i*3];
- rgb_data[i*3] = rgb_data[i*3+2];
- rgb_data[i*3+2] = tmp;
- }
-
- ofs.write((char *)header, sizeof(header));
- ofs.write((char *)rgb_data, video::width * video::height * 3 );
-
- // free the buffer
- free(rgb_data);
-
- // close file
- ofs.close();
- con_print << "Wrote " << shortname << std::endl;
+ render::TGA::save(filename.c_str(), image);
}