Refactor code to use Graphics::Surface, and remove a few more Grim leftovers

This commit is contained in:
Scott Thomas 2010-01-22 14:40:49 +10:30
parent 090fbd8813
commit 016aa846ca
7 changed files with 17 additions and 75 deletions

52
gfx.h
View file

@ -1,52 +0,0 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* $URL$
* $Id$
*
*/
#ifndef STARK_GFX_H
#define STARK_GFX_H
#include "common/sys.h"
namespace Stark {
struct Surface {
Surface(uint32 width, uint32 height) {
_pixels = (byte *)malloc(width * (height & 1 ? height + 1 : height)* 3);
assert(_pixels);
_width = width;
_height = height;
}
~Surface() {
free(_pixels);
}
byte *_pixels; // Must be in 24-bit RGB format!
uint32 _width, _height;
};
} // end of namespace Stark
#endif

View file

@ -27,8 +27,8 @@
#define STARK_GFX_BASE_H
#include "engines/stark/color.h"
#include "graphics/surface.h"
#include "graphics/vector3d.h"
#include "engines/stark/gfx.h"
namespace Stark {
@ -63,7 +63,7 @@ public:
virtual void translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll) = 0;
virtual void translateViewpointFinish() = 0;
virtual void drawBitmap(Surface* bmp) = 0;
virtual void drawSurface(Graphics::Surface* surface) = 0;
/*
virtual void disableLights() = 0;

View file

@ -35,13 +35,10 @@ namespace Stark {
GfxOpenGL::GfxOpenGL() {
_storedDisplay = NULL;
_emergFont = 0;
}
GfxOpenGL::~GfxOpenGL() {
delete[] _storedDisplay;
if (_emergFont && glIsList(_emergFont))
glDeleteLists(_emergFont, 128);
}
byte *GfxOpenGL::setupScreen(int screenW, int screenH, bool fullscreen) {
@ -172,11 +169,11 @@ void GfxOpenGL::translateViewpointFinish() {
glPopMatrix();
}
void GfxOpenGL::drawBitmap(Surface* bmp) {
void GfxOpenGL::drawSurface(Graphics::Surface* surface) {
glPixelZoom(1.0f, -1.0f);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glRasterPos2f(-1.0f, 0.75f);
glDrawPixels(bmp->_width, bmp->_height, GL_RGB, GL_UNSIGNED_BYTE, bmp->_pixels);
glDrawPixels(surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
}
} // end of namespace Stark

View file

@ -61,16 +61,11 @@ byte *setupScreen(int screenW, int screenH, bool fullscreen);
void translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll);
void translateViewpointFinish();
void drawBitmap(Surface* bmp);
void drawSurface(Graphics::Surface* bmp);
protected:
private:
GLuint _emergFont;
int _smushNumTex;
GLuint *_smushTexIds;
int _smushWidth;
int _smushHeight;
byte *_storedDisplay;
};

View file

@ -120,11 +120,11 @@ void StarkEngine::updateDisplayScene(){
Common::File _f;
_f.open("house_layercenter.xmg");
Common::SeekableReadStream *dat = _f.readStream(_f.size());
Surface *bmp;
bmp = xmg->decodeImage(dat);
g_driver->drawBitmap(bmp);
Graphics::Surface *surf;
surf = xmg->decodeImage(dat);
g_driver->drawSurface(surf);
delete xmg;
delete bmp;
delete surf;
delete dat;
_f.close();

10
xmg.cpp
View file

@ -29,7 +29,7 @@
namespace Stark {
Surface *XMGDecoder::decodeImage(Common::SeekableReadStream *stream) {
Graphics::Surface *XMGDecoder::decodeImage(Common::SeekableReadStream *stream) {
_stream = stream;
@ -43,10 +43,12 @@ Surface *XMGDecoder::decodeImage(Common::SeekableReadStream *stream) {
header.unknown2 = stream->readUint32LE();
header.unknown3 = stream->readUint32LE();
Surface *surface = new Surface(header.width, header.height);
Graphics::Surface *surface = new Graphics::Surface();
surface->create(header.width, header.height, 3);
_width = header.width;
_pixels = surface->_pixels;
_pixels = (byte *)surface->pixels;
_currX = 0;
_currY = 0;
@ -55,7 +57,7 @@ Surface *XMGDecoder::decodeImage(Common::SeekableReadStream *stream) {
if (_currX >= header.width) {
_currX -= 640;
_currY += 2;
_pixels = surface->_pixels + (3 * (_width * _currY + _currX));
_pixels = (byte *)surface->getBasePtr(_currX, _currY);
if (_currY >= header.height)
break;
}

4
xmg.h
View file

@ -29,7 +29,7 @@
#include "common/sys.h"
#include "common/stream.h"
#include "engines/stark/gfx.h"
#include "graphics/surface.h"
namespace Stark {
@ -55,7 +55,7 @@ public:
XMGDecoder() {}
~XMGDecoder() {}
Surface *decodeImage(Common::SeekableReadStream *stream);
Graphics::Surface *decodeImage(Common::SeekableReadStream *stream);
private:
void processYCrCb(uint16 count);