diff --git a/engines/grim/bitmap.cpp b/engines/grim/bitmap.cpp index 7ae131ae87a..acd198dfb5d 100644 --- a/engines/grim/bitmap.cpp +++ b/engines/grim/bitmap.cpp @@ -409,6 +409,14 @@ void Bitmap::draw(int x, int y) { g_driver->drawBitmap(this, x, y); } +void Bitmap::drawForeground() { + _data->load(); + if (_currImage == 0) + return; + + g_driver->drawBitmap(this, _data->_x, _data->_y, false); +} + void Bitmap::setActiveImage(int n) { assert(n >= 0); _data->load(); diff --git a/engines/grim/bitmap.h b/engines/grim/bitmap.h index dcfaa8bd8a1..2a18acc7153 100644 --- a/engines/grim/bitmap.h +++ b/engines/grim/bitmap.h @@ -146,6 +146,8 @@ public: void draw(); void draw(int x, int y); + void drawForeground(); + /** * Set which image in an animated bitmap to use * diff --git a/engines/grim/gfx_base.h b/engines/grim/gfx_base.h index 3c095fb5101..313994b1558 100644 --- a/engines/grim/gfx_base.h +++ b/engines/grim/gfx_base.h @@ -169,7 +169,7 @@ public: * @see createBitmap * @see destroyBitmap */ - virtual void drawBitmap(const Bitmap *bitmap, int x, int y) = 0; + virtual void drawBitmap(const Bitmap *bitmap, int x, int y, bool initialDraw = true) = 0; /** * Deletes any internal references and representations of a bitmap diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp index 7d737d74d5f..bd92b9e3943 100644 --- a/engines/grim/gfx_opengl.cpp +++ b/engines/grim/gfx_opengl.cpp @@ -805,10 +805,14 @@ void GfxOpenGL::createBitmap(BitmapData *bitmap) { } } -void GfxOpenGL::drawBitmap(const Bitmap *bitmap, int dx, int dy) { +void GfxOpenGL::drawBitmap(const Bitmap *bitmap, int dx, int dy, bool initialDraw) { if (g_grim->getGameType() == GType_MONKEY4) { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); glMatrixMode(GL_PROJECTION); + glPushMatrix(); glLoadIdentity(); glOrtho(-1, 1, -1, 1, 0, 1); @@ -823,17 +827,28 @@ void GfxOpenGL::drawBitmap(const Bitmap *bitmap, int dx, int dy) { BitmapData *data = bitmap->_data; GLuint *textures = (GLuint *)bitmap->getTexIds(); float *texc = data->_texc; - uint32 offset = data->_offsets[data->_curOffset]._offset; - for (uint32 i = offset; i < offset + data->_offsets[data->_curOffset]._numImages; ++i) { - glBindTexture(GL_TEXTURE_2D, textures[data->_verts[i]._texid]); - glBegin(GL_QUADS); - uint32 ntex = data->_verts[i]._pos * 4; - for (uint32 x = 0; x < data->_verts[i]._verts; ++x) { - glTexCoord2f(texc[ntex + 2], texc[ntex + 3]); - glVertex2f(texc[ntex + 0], texc[ntex + 1]); - ntex += 4; + int startOffset, endOffset; + if (initialDraw) { + startOffset = endOffset = data->_curOffset; + } else { + startOffset = data->_curOffset - 1; + endOffset = 0; + } + + while (endOffset <= startOffset) { + uint32 offset = data->_offsets[startOffset]._offset; + for (uint32 i = offset; i < offset + data->_offsets[startOffset]._numImages; ++i) { + glBindTexture(GL_TEXTURE_2D, textures[data->_verts[i]._texid]); + glBegin(GL_QUADS); + uint32 ntex = data->_verts[i]._pos * 4; + for (uint32 x = 0; x < data->_verts[i]._verts; ++x) { + glTexCoord2f(texc[ntex + 2], texc[ntex + 3]); + glVertex2f(texc[ntex + 0], texc[ntex + 1]); + ntex += 4; + } + glEnd(); } - glEnd(); + startOffset--; } glDisable(GL_TEXTURE_2D); @@ -841,6 +856,10 @@ void GfxOpenGL::drawBitmap(const Bitmap *bitmap, int dx, int dy) { glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + return; } diff --git a/engines/grim/gfx_opengl.h b/engines/grim/gfx_opengl.h index 80debca2704..b9fcabc6c9a 100644 --- a/engines/grim/gfx_opengl.h +++ b/engines/grim/gfx_opengl.h @@ -92,7 +92,7 @@ public: void destroyMaterial(Texture *material); void createBitmap(BitmapData *bitmap); - void drawBitmap(const Bitmap *bitmap, int x, int y); + void drawBitmap(const Bitmap *bitmap, int x, int y, bool initialDraw = true); void destroyBitmap(BitmapData *bitmap); void createFont(Font *font); diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index dee0fedb26d..eefcd73087a 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -873,7 +873,7 @@ void GfxTinyGL::blit(const Graphics::PixelFormat &format, BlitImage *image, byte } } -void GfxTinyGL::drawBitmap(const Bitmap *bitmap, int x, int y) { +void GfxTinyGL::drawBitmap(const Bitmap *bitmap, int x, int y, bool initialDraw) { int format = bitmap->getFormat(); if ((format == 1 && !_renderBitmaps) || (format == 5 && !_renderZBitmaps)) { return; diff --git a/engines/grim/gfx_tinygl.h b/engines/grim/gfx_tinygl.h index 3b6c0d61c26..9b9cfa7cf89 100644 --- a/engines/grim/gfx_tinygl.h +++ b/engines/grim/gfx_tinygl.h @@ -84,7 +84,7 @@ public: void destroyMaterial(Texture *material); void createBitmap(BitmapData *bitmap); - void drawBitmap(const Bitmap *bitmap, int x, int y); + void drawBitmap(const Bitmap *bitmap, int x, int y, bool initialDraw = true); void destroyBitmap(BitmapData *bitmap); void createFont(Font *font); diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp index 5fb1536c50a..11b92a688a6 100644 --- a/engines/grim/grim.cpp +++ b/engines/grim/grim.cpp @@ -528,11 +528,24 @@ void GrimEngine::updateDisplayScene() { // Draw actors buildActiveActorsList(); - foreach (Actor *a, _activeActors) { - if (a->isVisible()) - a->draw(); + if (g_grim->getGameType() == GType_GRIM) { + foreach (Actor *a, _activeActors) { + if (a->isVisible()) + a->draw(); + } + } else { + bool drewForeground = false; + foreach (Actor *a, _activeActors) { + if (a->getSortOrder() < 15 && !drewForeground) { + drewForeground = true; + _currSet->drawForeground(); + } + if (a->isVisible() && a->getSortOrder() < 100) + a->draw(); + } } + flagRefreshShadowMask(false); // Draw overlying scene components diff --git a/engines/grim/set.cpp b/engines/grim/set.cpp index 72be7b80da4..5ff21ff6f30 100644 --- a/engines/grim/set.cpp +++ b/engines/grim/set.cpp @@ -549,6 +549,11 @@ void Set::setSetup(int num) { g_grim->flagRefreshShadowMask(true); } +void Set::drawForeground() const { + assert(g_grim->getGameType() == GType_MONKEY4); + _currSetup->_bkgndBm->drawForeground(); +} + void Set::drawBackground() const { if (_currSetup->_bkgndZBm) // Some screens have no zbuffer mask (eg, Alley) _currSetup->_bkgndZBm->draw(); diff --git a/engines/grim/set.h b/engines/grim/set.h index 06bafc8b591..54ac7e23ea2 100644 --- a/engines/grim/set.h +++ b/engines/grim/set.h @@ -56,6 +56,7 @@ public: int _maxVolume; void drawBackground() const; + void drawForeground() const; void drawBitmaps(ObjectState::Position stage); void setupCamera() { _currSetup->setupCamera();