diff options
author | Einar Johan Trøan Sømåen | 2012-05-09 18:04:02 +0200 |
---|---|---|
committer | Einar Johan Trøan Sømåen | 2012-06-02 12:42:09 +0200 |
commit | 9355850d0728df266b33446e58ab0f330d34321d (patch) | |
tree | 8ec38573642e041c02d251ab83f9cc4c55b10d70 | |
parent | 21033f631f5895bb88779c1dd77b6d17466c6840 (diff) | |
download | scummvm-rg350-9355850d0728df266b33446e58ab0f330d34321d.tar.gz scummvm-rg350-9355850d0728df266b33446e58ab0f330d34321d.tar.bz2 scummvm-rg350-9355850d0728df266b33446e58ab0f330d34321d.zip |
WINTERMUTE: Make the engine atleast draw something.
-rw-r--r-- | engines/wintermute/BRenderSDL.cpp | 18 | ||||
-rw-r--r-- | engines/wintermute/BRenderSDL.h | 3 | ||||
-rw-r--r-- | engines/wintermute/BSurfaceSDL.cpp | 60 | ||||
-rw-r--r-- | engines/wintermute/BSurfaceSDL.h | 4 | ||||
-rw-r--r-- | engines/wintermute/wintermute.cpp | 3 |
5 files changed, 60 insertions, 28 deletions
diff --git a/engines/wintermute/BRenderSDL.cpp b/engines/wintermute/BRenderSDL.cpp index 9e9d7ef6d5..1daf2aafc8 100644 --- a/engines/wintermute/BRenderSDL.cpp +++ b/engines/wintermute/BRenderSDL.cpp @@ -35,7 +35,7 @@ #include "engines/wintermute/MathUtil.h"
#include "engines/wintermute/BGame.h"
#include "engines/wintermute/BSprite.h"
-
+#include "common/system.h"
#include "SDL.h"
namespace WinterMute {
@@ -161,8 +161,7 @@ HRESULT CBRenderSDL::InitRenderer(int width, int height, bool windowed) { if (!_renderer) return E_FAIL;
#endif
_renderSurface = new Graphics::Surface();
- Graphics::PixelFormat format(4, 8, 8, 8, 8, 24, 16, 8, 0);
- _renderSurface->create(640,480, format); // TODO: Unhardcode this.
+ _renderSurface->create(640,480, g_system->getScreenFormat()); // TODO: Unhardcode this.
_active = true;
@@ -211,8 +210,9 @@ HRESULT CBRenderSDL::Flip() { }
}
#endif
-
-
+ // TODO, unhardcode.
+ g_system->copyRectToScreen((byte*)_renderSurface->pixels, _renderSurface->pitch, 0, 0, 640, 480);
+ g_system->updateScreen();
//SDL_RenderPresent(_renderer);
return S_OK;
@@ -272,6 +272,14 @@ HRESULT CBRenderSDL::FadeToColor(uint32 Color, RECT *rect) { return S_OK;
}
+// Replacement for SDL2's SDL_RenderCopy
+void CBRenderSDL::drawFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect) {
+ for (int i = 0; i < srcRect->height(); i++) {
+ void *destPtr = _renderSurface->getBasePtr(dstRect->left, dstRect->top + i);
+ void *srcPtr = surf->getBasePtr(srcRect->left, srcRect->top + i);
+ memcpy(destPtr, srcPtr, _renderSurface->format.bytesPerPixel * srcRect->width());
+ }
+}
//////////////////////////////////////////////////////////////////////////
HRESULT CBRenderSDL::DrawLine(int X1, int Y1, int X2, int Y2, uint32 Color) {
byte r = D3DCOLGetR(Color);
diff --git a/engines/wintermute/BRenderSDL.h b/engines/wintermute/BRenderSDL.h index 3ef5cc1cde..73d3bbac29 100644 --- a/engines/wintermute/BRenderSDL.h +++ b/engines/wintermute/BRenderSDL.h @@ -65,6 +65,9 @@ public: SDL_Window *GetSdlWindow() const {
// return _win;
}
+
+ void drawFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRest);
+
HRESULT SetViewport(int left, int top, int right, int bottom);
diff --git a/engines/wintermute/BSurfaceSDL.cpp b/engines/wintermute/BSurfaceSDL.cpp index 4f36a13dd5..e3853fb252 100644 --- a/engines/wintermute/BSurfaceSDL.cpp +++ b/engines/wintermute/BSurfaceSDL.cpp @@ -44,7 +44,7 @@ namespace WinterMute { //////////////////////////////////////////////////////////////////////////
CBSurfaceSDL::CBSurfaceSDL(CBGame *inGame) : CBSurface(inGame) {
- _texture = NULL;
+ _surface = new Graphics::Surface();
_alphaMask = NULL;
_lockPixels = NULL;
@@ -54,6 +54,7 @@ CBSurfaceSDL::CBSurfaceSDL(CBGame *inGame) : CBSurface(inGame) { //////////////////////////////////////////////////////////////////////////
CBSurfaceSDL::~CBSurfaceSDL() {
//TODO
+ delete _surface;
#if 0
if (_texture) SDL_DestroyTexture(_texture);
delete[] _alphaMask;
@@ -124,12 +125,14 @@ HRESULT CBSurfaceSDL::Create(char *Filename, bool default_ck, byte ck_red, byte uint32 bmask = surface->format.bMax() << surface->format.bShift;
uint32 amask = surface->format.aMax();
- SDL_Surface *surf = SDL_CreateRGBSurfaceFrom(surface->pixels, _width, _height, surface->format.bytesPerPixel * 8, surface->pitch, rmask, gmask, bmask, amask);
+// SDL_Surface *surf = SDL_CreateRGBSurfaceFrom(surface->pixels, _width, _height, surface->format.bytesPerPixel * 8, surface->pitch, rmask, gmask, bmask, amask);
// no alpha, set color key
- if (surface->format.bytesPerPixel != 4)
- SDL_SetColorKey(surf, SDL_TRUE, SDL_MapRGB(surf->format, ck_red, ck_green, ck_blue));
-
+/* if (surface->format.bytesPerPixel != 4)
+ SDL_SetColorKey(surf, SDL_TRUE, SDL_MapRGB(surf->format, ck_red, ck_green, ck_blue));*/
+ _surface = new Graphics::Surface();
+ _surface->copyFrom(*surface);
+
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); //TODO
//_texture = SdlUtil::CreateTextureFromSurface(renderer->GetSdlRenderer(), surf);
warning("Surface-textures not fully ported yet");
@@ -281,7 +284,13 @@ HRESULT CBSurfaceSDL::CreateFromSDLSurface(SDL_Surface *surface) { bool CBSurfaceSDL::IsTransparentAt(int X, int Y) {
int access;
int width, height;
- warning("CBSurfaceSDL::IsTransparentAt not ported yet");
+ // This particular warning is rather messy, as this function is called a ton,
+ // thus we avoid printing it more than once.
+ static bool hasWarned = false;
+ if (!hasWarned) {
+ warning("CBSurfaceSDL::IsTransparentAt not ported yet");
+ hasWarned = true;
+ }
//SDL_QueryTexture(_texture, NULL, &access, &width, &height); //TODO
//if (access != SDL_TEXTUREACCESS_STREAMING) return false;
if (X < 0 || X >= width || Y < 0 || Y >= height) return true;
@@ -388,7 +397,7 @@ HRESULT CBSurfaceSDL::DrawSprite(int X, int Y, RECT *Rect, float ZoomX, float Zo // thus we avoid printing it more than once.
static bool hasWarned = false;
if (!hasWarned) {
- warning("CBSurfaceSDL::DrawSprite not ported yet"); // TODO.
+ warning("CBSurfaceSDL::DrawSprite not fully ported yet"); // TODO.
hasWarned = true;
}
#if 0
@@ -399,24 +408,33 @@ HRESULT CBSurfaceSDL::DrawSprite(int X, int Y, RECT *Rect, float ZoomX, float Zo SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_NONE);
else
SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_BLEND);
-
- SDL_Rect srcRect;
- srcRect.x = Rect->left;
- srcRect.y = Rect->top;
- srcRect.w = Rect->right - Rect->left;
- srcRect.h = Rect->bottom - Rect->top;
-
- SDL_Rect position;
- position.x = X;
- position.y = Y;
- position.w = (float)srcRect.w * ZoomX / 100.f;
- position.h = (float)srcRect.h * ZoomX / 100.f;
+#endif
+ // TODO: This _might_ miss the intended behaviour by 1 in each direction
+ // But I think it fits the model used in Wintermute.
+ Common::Rect srcRect;
+ srcRect.left = Rect->left;
+ srcRect.top = Rect->top;
+ srcRect.setWidth(Rect->right - Rect->left);
+ srcRect.setHeight(Rect->bottom - Rect->top);
+
+ Common::Rect position;
+ position.left = X;
+ position.top = Y;
+ // TODO: Scaling...
+ /*
+ position.setWidth((float)srcRect.width() * ZoomX / 100.f);
+ position.setHeight((float)srcRect.height() * ZoomX / 100.f);
+*/
+ position.setWidth(srcRect.width());
+ position.setHeight(srcRect.height());
renderer->ModTargetRect(&position);
- position.x += offsetX;
- position.y += offsetY;
+ position.left += offsetX;
+ position.top += offsetY;
+ renderer->drawFromSurface(_surface, &srcRect, &position);
+#if 0
SDL_RenderCopy(renderer->GetSdlRenderer(), _texture, &srcRect, &position);
#endif
diff --git a/engines/wintermute/BSurfaceSDL.h b/engines/wintermute/BSurfaceSDL.h index 557eefeedf..9053af3d7d 100644 --- a/engines/wintermute/BSurfaceSDL.h +++ b/engines/wintermute/BSurfaceSDL.h @@ -29,6 +29,7 @@ #ifndef WINTERMUTE_BSURFACESDL_H
#define WINTERMUTE_BSURFACESDL_H
+#include "graphics/surface.h"
#include "BSurface.h"
#include "SDL.h" // TODO, remove
class SDL_Texture;
@@ -64,7 +65,8 @@ public: static long DLL_CALLCONV TellProc(fi_handle handle);*/
private:
- SDL_Texture *_texture;
+// SDL_Texture *_texture;
+ Graphics::Surface *_surface;
HRESULT DrawSprite(int X, int Y, RECT *Rect, float ZoomX, float ZoomY, uint32 Alpha, bool AlphaDisable, TSpriteBlendMode BlendMode, bool MirrorX, bool MirrorY, int offsetX = 0, int offsetY = 0);
void GenAlphaMask(SDL_Surface *surface);
diff --git a/engines/wintermute/wintermute.cpp b/engines/wintermute/wintermute.cpp index 6546dcadaf..298e4a97c6 100644 --- a/engines/wintermute/wintermute.cpp +++ b/engines/wintermute/wintermute.cpp @@ -71,7 +71,8 @@ namespace WinterMute { Common::Error WinterMuteEngine::run() { // Initialize graphics using following: - initGraphics(640, 480, false); + Graphics::PixelFormat format(4, 8, 8, 8, 8, 24, 16, 8, 0); + initGraphics(640, 480, false, &format); // You could use backend transactions directly as an alternative, // but it isn't recommended, until you want to handle the error values |