[Scummvm-cvs-logs] CVS: residual driver_gl.cpp,1.59,1.60 driver_gl.h,1.29,1.30
Erich Edgar Hoover
compholio at users.sourceforge.net
Sat Dec 24 21:58:00 CET 2005
- Previous message: [Scummvm-cvs-logs] CVS: residual objectstate.h,1.11,1.12 font.h,1.6,1.7 textsplit.h,1.6,1.7
- Next message: [Scummvm-cvs-logs] CVS: residual lua.cpp,1.160,1.161 textsplit.cpp,1.11,1.12 smush.cpp,1.67,1.68
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv405
Modified Files:
driver_gl.cpp driver_gl.h
Log Message:
Added support for screen/region dimming and screenshots to the OpenGL driver
Index: driver_gl.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.cpp,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- driver_gl.cpp 28 Aug 2005 23:25:14 -0000 1.59
+++ driver_gl.cpp 25 Dec 2005 05:57:08 -0000 1.60
@@ -46,9 +46,15 @@
// Load emergency built-in font
loadEmergFont();
+ _storedDisplay = new byte[_screenWidth * _screenHeight * 4];
+ memset(_storedDisplay, 0, _screenWidth * _screenHeight * 4);
_smushNumTex = 0;
}
+DriverGL::~DriverGL() {
+ delete []_storedDisplay;
+}
+
void DriverGL::toggleFullscreenMode() {
warning("Switching on fly to Fullscreen mode is not allowed");
// switching to fullscreen mode it cause lost of texture
@@ -653,7 +659,7 @@
void DriverGL::drawTextBitmap(int x, int y, TextObjectHandle *handle) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0, 640, 480, 0, 0, 1);
+ glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_TEXTURE);
@@ -699,20 +705,105 @@
delete[] (GLuint *)handle->texIds;
}
-Bitmap *DriverGL::getScreenshot(int /*w*/, int /*h*/) {
- return NULL;
+Bitmap *DriverGL::getScreenshot(int w, int h) {
+ uint16 *buffer = new uint16[w * h];
+ uint32 *src = (uint32 *)_storedDisplay;
+ float step_x = _screenWidth * 1.0f / w;
+ float step_y = _screenHeight * 1.0f / h;
+
+ int step = 0;
+ for (float y = 0; y < 479; y += step_y) {
+ for (float x = 0; x < 639; x += step_x) {
+ uint32 pixel = *(src + (int)y * _screenWidth + (int)x);
+
+ uint8 r = (pixel & 0xFF0000) >> 16;
+ uint8 g = (pixel & 0x00FF00) >> 8;
+ uint8 b = (pixel & 0x0000FF);
+ uint32 color = (r + g + b) / 3;
+ int pos = step/w;
+ int wpos = step-pos*w;
+ // source is upside down, flip appropriately while storing
+ buffer[h*w - (pos*w+w-wpos)] = ((color & 0xF8) << 8) | ((color & 0xFC) << 3) | (color >> 3);
+ step++;
+ }
+ }
+
+ Bitmap *screenshot = new Bitmap((char *) buffer, w, h, "screenshot");
+ delete []buffer;
+ return screenshot;
}
void DriverGL::storeDisplay() {
+ glReadPixels(0, 0, _screenWidth, _screenHeight, GL_RGBA, GL_UNSIGNED_BYTE, _storedDisplay);
}
void DriverGL::copyStoredToDisplay() {
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glDisable(GL_LIGHTING);
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE);
+
+ glRasterPos2i(0, _screenHeight);
+ glDrawPixels(_screenWidth, _screenHeight, GL_RGBA, GL_UNSIGNED_BYTE, _storedDisplay);
+
+ glDepthMask(GL_TRUE);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
}
void DriverGL::dimScreen() {
+ uint32 *data = (uint32 *)_storedDisplay;
+ for (int l = 0; l < _screenWidth * _screenHeight; l++) {
+ uint32 pixel = data[l];
+ uint8 r = (pixel & 0xFF0000) >> 16;
+ uint8 g = (pixel & 0x00FF00) >> 8;
+ uint8 b = (pixel & 0x0000FF);
+ uint32 color = (r + g + b) / 6;
+ data[l] = ((color & 0xFF) << 16) | ((color & 0xFF) << 8) | (color & 0xFF);
+ }
}
-void DriverGL::dimRegion(int x, int y, int w, int h, float level) {
+void DriverGL::dimRegion(int x, int yReal, int w, int h, float level) {
+ uint32 *data = new uint32[w*h];
+ int y = _screenHeight - yReal;
+
+ // collect the requested area and generate the dimmed version
+ glReadPixels(x, y-h, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ for (int ly = 0; ly < h; ly++) {
+ for (int lx = 0; lx < w; lx++) {
+ uint32 pixel = data[ly * w + lx];
+ uint8 r = (pixel & 0xFF0000) >> 16;
+ uint8 g = (pixel & 0x00FF00) >> 8;
+ uint8 b = (pixel & 0x0000FF);
+ uint32 color = (uint32)(((r + g + b) / 3) * level);
+ data[ly * w + lx] = ((color & 0xFF) << 16) | ((color & 0xFF) << 8) | (color & 0xFF);
+ }
+ }
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glDisable(GL_LIGHTING);
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE);
+
+ // Set the raster position and draw the bitmap
+ glRasterPos2i(x, yReal+h);
+ glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, data);
+
+ glDepthMask(GL_TRUE);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
+
+ delete[] data;
}
void DriverGL::drawRectangle(PrimitiveObject *primitive) {
@@ -725,7 +816,7 @@
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0, 640, 480, 0, 0, 1);
+ glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -764,7 +855,7 @@
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0, 640, 480, 0, 0, 1);
+ glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Index: driver_gl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- driver_gl.h 28 Aug 2005 23:25:14 -0000 1.29
+++ driver_gl.h 25 Dec 2005 05:57:08 -0000 1.30
@@ -32,6 +32,7 @@
class DriverGL : public Driver {
public:
DriverGL(int screenW, int screenH, int screenBPP, bool fullscreen = false);
+ virtual ~DriverGL();
void setupCamera(float fov, float nclip, float fclip, float roll);
void positionCamera(Vector3d pos, Vector3d interest);
@@ -91,6 +92,7 @@
GLuint *_smushTexIds;
int _smushWidth;
int _smushHeight;
+ byte *_storedDisplay;
};
#endif
- Previous message: [Scummvm-cvs-logs] CVS: residual objectstate.h,1.11,1.12 font.h,1.6,1.7 textsplit.h,1.6,1.7
- Next message: [Scummvm-cvs-logs] CVS: residual lua.cpp,1.160,1.161 textsplit.cpp,1.11,1.12 smush.cpp,1.67,1.68
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list