summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuane Bailey <nayryeliab@gmail.com>2005-09-23 22:15:35 +0000
committerDuane Bailey <nayryeliab@gmail.com>2005-09-23 22:15:35 +0000
commitc3d7827d18b725d2dff94e08a17474d607bb43dd (patch)
treebcf47aee4c5425ac9bf3b76e82cadee2514b0c8c
parent5860a7322aa193f33d98bdfc0de983af85ef9229 (diff)
downloadmana-c3d7827d18b725d2dff94e08a17474d607bb43dd.tar.gz
mana-c3d7827d18b725d2dff94e08a17474d607bb43dd.tar.bz2
mana-c3d7827d18b725d2dff94e08a17474d607bb43dd.tar.xz
mana-c3d7827d18b725d2dff94e08a17474d607bb43dd.zip
fixed opengl screenshot, made opengl smoother on macosx
-rw-r--r--ChangeLog6
-rw-r--r--src/openglgraphics.cpp70
2 files changed, 29 insertions, 47 deletions
diff --git a/ChangeLog b/ChangeLog
index 4f0136ab..be49258e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-09-23 Duane Bailey <nayryeliab@gmail.com>
+
+ * src/openglgraphics.cpp: totally redid the opengl screenshot method
+ needs to be tested on lil endian systems. Also made it smoother on
+ OpenGL macosx.
+
2005-09-23 Eugenio Favalli <elvenprogrammer@gmail.com>
* src/resources/imagewriter.cpp: Reverted the latst change that broke
the screenshots facility.
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 56ef5b3f..072999d8 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -28,6 +28,10 @@
#include <iostream>
#include <SDL.h>
+#ifdef __APPLE__
+#include <OpenGL/OpenGL.h>
+#endif
+
#include <guichan/image.hpp>
#include "log.h"
@@ -62,6 +66,11 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
return false;
}
+#ifdef __APPLE__
+ long VBL = 1;
+ CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
+#endif
+
// Setup OpenGL
glViewport(0, 0, w, h);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
@@ -137,57 +146,24 @@ void OpenGLGraphics::_endDraw()
SDL_Surface* OpenGLGraphics::getScreenshot()
{
- // TODO I expect this to be unneeded for OpenGL, someone with a PPC or
- // sth. else that is big endian should check this.
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- int rmask = 0xff000000;
- int gmask = 0x00ff0000;
- int bmask = 0x0000ff00;
-#else
- int rmask = 0x000000ff;
- int gmask = 0x0000ff00;
- int bmask = 0x00ff0000;
-#endif
- int amask = 0x00000000;
+ 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);
- SDL_Surface *screenshot = SDL_CreateRGBSurface(SDL_SWSURFACE, mScreen->w,
- mScreen->h, 24, rmask, gmask, bmask, amask);
+ void *data = malloc(w * h * 3);
- if (SDL_MUSTLOCK(screenshot)) {
- SDL_LockSurface(screenshot);
- }
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(0, 0, mScreen->w, mScreen->h, GL_RGB, GL_UNSIGNED_BYTE,
- screenshot->pixels);
-
- unsigned char *data = (unsigned char*)screenshot->pixels;
- for (int x = 0; x < mScreen->w; x++) {
- for (int y=0; y < mScreen->h / 2; y++) {
- int i1 = (y * mScreen->w + x) * 3;
- int i2 = ((mScreen->h - y - 1) * mScreen->w + x) * 3;
-
- unsigned char temp = data[i1];
- data[i1] = data[i2];
- data[i2] = temp;
-
- i1++; i2++;
- temp = data[i1];
- data[i1] = data[i2];
- data[i2] = temp;
-
- i1++; i2++;
- temp = data[i1];
- data[i1] = data[i2];
- data[i2] = temp;
-
- }
- }
-
- if (SDL_MUSTLOCK(screenshot)) {
- SDL_UnlockSurface(screenshot);
+ for (int i = 0; i < h; i++)
+ {
+ memcpy(data + 3 * w * i, surface->pixels + 3 * w * (h - i), 3 * w);
}
+ surface->pixels = data;
+
+ //SDL_FreeSurface(surface);
+ //free(data);
- return screenshot;
+ return surface;
}
bool OpenGLGraphics::pushClipArea(gcn::Rectangle area)