summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-09-24 22:34:06 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-09-24 22:34:06 +0000
commit1a7f56901301fb8fe08f26526f3314b0974626ca (patch)
treef8c2189c5b502b5b3f610d60310db78a2043f4cd
parent0fc148affc222dd1108b6f1fc8ad2757f1fdc4f1 (diff)
downloadmana-client-1a7f56901301fb8fe08f26526f3314b0974626ca.tar.gz
mana-client-1a7f56901301fb8fe08f26526f3314b0974626ca.tar.bz2
mana-client-1a7f56901301fb8fe08f26526f3314b0974626ca.tar.xz
mana-client-1a7f56901301fb8fe08f26526f3314b0974626ca.zip
Fix crash on exit after taking screenshot in OpenGL and fix compiler warning.
-rw-r--r--ChangeLog25
-rw-r--r--src/openglgraphics.cpp42
2 files changed, 46 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 5047779e..3cb5ec1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,14 +1,21 @@
+2005-09-25 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * src/openglgraphics.cpp: Fixed taking OpenGL screenshots and in
+ addition made it flip the image using just a line buffer instead of a
+ buffer for the complete image. Still needs testing on MacOS X.
+
2005-09-24 Bjørn Lindeijer <bjorn@lindeijer.nl>
- * src/being.cpp, src/engine.cpp, src/game.cpp, src/main.cpp, src/map.cpp,
- src/sound.cpp, src/gui/char_select.cpp, src/gui/char_select.h,
- src/gui/char_server.cpp, src/gui/char_server.h, src/gui/chargedialog.cpp,
- src/gui/chargedialog.h, src/gui/chat.cpp, src/gui/equipmentwindow.cpp,
- src/gui/login.h, src/gui/setup.cpp, src/gui/setup.h, src/gui/status.cpp,
- src/gui/updatewindow.cpp, src/gui/updatewindow.h,
- src/resources/iteminfo.cpp, src/resources/iteminfo.h,
- src/resources/itemmanager.cpp, src/resources/itemmanager.h: Merged most
- of the changes in biggeruniverse's second memory cleanup patch.
+ * src/being.cpp, src/engine.cpp, src/game.cpp, src/main.cpp,
+ src/map.cpp, src/sound.cpp, src/gui/char_select.cpp,
+ src/gui/char_select.h, src/gui/char_server.cpp, src/gui/char_server.h,
+ src/gui/chargedialog.cpp, src/gui/chargedialog.h, src/gui/chat.cpp,
+ src/gui/equipmentwindow.cpp, src/gui/login.h, src/gui/setup.cpp,
+ src/gui/setup.h, src/gui/status.cpp, src/gui/updatewindow.cpp,
+ src/gui/updatewindow.h, src/resources/iteminfo.cpp,
+ src/resources/iteminfo.h, src/resources/itemmanager.cpp,
+ src/resources/itemmanager.h: Merged most of the changes in
+ biggeruniverse's second memory cleanup patch.
2005-09-23 Duane Bailey <nayryeliab@gmail.com>
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 27eefc6e..d7915256 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -148,23 +148,41 @@ SDL_Surface* OpenGLGraphics::getScreenshot()
{
int h = mScreen->h;
int w = mScreen->w;
- SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, mScreen->w,
- mScreen->h, 24, 0xff0000, 0x00ff00, 0x0000ff, NULL);
- glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
- void *data = malloc(w * h * 3);
+ SDL_Surface *screenshot = SDL_CreateRGBSurface(
+ SDL_SWSURFACE,
+ w, h, 24,
+ 0xff0000, 0x00ff00, 0x0000ff, 0x000000);
- for (int i = 0; i < h; i++)
+ if (SDL_MUSTLOCK(screenshot)) {
+ SDL_LockSurface(screenshot);
+ }
+
+ // Grap the pixel buffer and write it to the SDL surface
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
+
+ // Flip the screenshot, as OpenGL has 0,0 in bottom left
+ unsigned int lineSize = 3 * w;
+ GLubyte* buf = (GLubyte*)malloc(lineSize);
+
+ for (int i = 0; i < (h / 2); i++)
{
- memcpy((GLubyte*)data + 3 * w * i,
- (GLubyte*)surface->pixels + 3 * w * (h - i),
- 3 * w);
+ GLubyte *top = (GLubyte*)screenshot->pixels + lineSize * i;
+ GLubyte *bot = (GLubyte*)screenshot->pixels + lineSize * (h - 1 - i);
+
+ memcpy(buf, top, lineSize);
+ memcpy(top, bot, lineSize);
+ memcpy(bot, buf, lineSize);
+ }
+
+ free(buf);
+
+ if (SDL_MUSTLOCK(screenshot)) {
+ SDL_UnlockSurface(screenshot);
}
- memcpy(surface->pixels, data, w * h * 3);
- free(data);
-
- return surface;
+ return screenshot;
}
bool OpenGLGraphics::pushClipArea(gcn::Rectangle area)