diff --git a/engines/myst3/gfx_tinygl.cpp b/engines/myst3/gfx_tinygl.cpp index 013e59e4140..f156954ae46 100644 --- a/engines/myst3/gfx_tinygl.cpp +++ b/engines/myst3/gfx_tinygl.cpp @@ -78,30 +78,26 @@ void TinyGLRenderer::init() { } void TinyGLRenderer::clear() { + tglClearColor(0.f, 0.f, 0.f, 1.f); // Solid black tglClear(TGL_COLOR_BUFFER_BIT | TGL_DEPTH_BUFFER_BIT); tglColor3f(1.0f, 1.0f, 1.0f); } void TinyGLRenderer::selectTargetWindow(Window *window, bool is3D, bool scaled) { - // NOTE: tinyGL viewport implementation needs to be checked as it doesn't behave the same as openGL - if (!window) { // No window found ... if (scaled) { // ... in scaled mode draw in the original game screen area - Common::Rect vp = viewport(); - tglViewport(vp.left, vp.top, vp.width(), vp.height()); - //tglViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height()); + _viewport = viewport(); } else { // ... otherwise, draw on the whole screen - tglViewport(0, 0, _system->getWidth(), _system->getHeight()); + _viewport = Common::Rect(_system->getWidth(), _system->getHeight()); } } else { // Found a window, draw inside it - Common::Rect vp = window->getPosition(); - tglViewport(vp.left, vp.top, vp.width(), vp.height()); - //tglViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height()); + _viewport = window->getPosition(); } + tglViewport(_viewport.left, _system->getHeight() - _viewport.top - _viewport.height(), _viewport.width(), _viewport.height()); if (is3D) { tglMatrixMode(TGL_PROJECTION); @@ -171,14 +167,11 @@ void TinyGLRenderer::drawTexturedRect2D(const Common::Rect &screenRect, const Co transparency = 1.0; } - // HACK: tglBlit is not affected by the viewport, so we offset the draw coordinates here - int viewPort[4]; - tglGetIntegerv(TGL_VIEWPORT, viewPort); - tglEnable(TGL_TEXTURE_2D); tglDepthMask(TGL_FALSE); - Graphics::BlitTransform transform(sLeft + viewPort[0], sTop + viewPort[1]); + // HACK: tglBlit is not affected by the viewport, so we offset the draw coordinates here + Graphics::BlitTransform transform(sLeft + _viewport.left, sTop + _viewport.top); transform.sourceRectangle(textureRect.left, textureRect.top, sWidth, sHeight); transform.tint(transparency); tglBlit(((TinyGLTexture *)texture)->getBlitTexture(), transform); diff --git a/engines/myst3/gfx_tinygl.h b/engines/myst3/gfx_tinygl.h index f57a658c893..d2d52c27d7b 100644 --- a/engines/myst3/gfx_tinygl.h +++ b/engines/myst3/gfx_tinygl.h @@ -62,6 +62,7 @@ private: void drawFace(uint face, Texture *texture); TinyGL::FrameBuffer *_fb; + Common::Rect _viewport; }; } // End of namespace Myst3 diff --git a/graphics/tinygl/vertex.cpp b/graphics/tinygl/vertex.cpp index c66cbdc8f55..2d3303b51f6 100644 --- a/graphics/tinygl/vertex.cpp +++ b/graphics/tinygl/vertex.cpp @@ -74,11 +74,14 @@ void gl_eval_viewport(GLContext *c) { v = &c->viewport; + // v->ymin needs to be upside down for transformation + int ymin = c->fb->ysize - v->ysize - v->ymin; v->trans.X = (float)(((v->xsize - 0.5) / 2.0) + v->xmin); - v->trans.Y = (float)(((v->ysize - 0.5) / 2.0) + v->ymin); + v->trans.Y = (float)(((v->ysize - 0.5) / 2.0) + ymin); v->trans.Z = (float)(((zsize - 0.5) / 2.0) + ((1 << ZB_POINT_Z_FRAC_BITS)) / 2); v->scale.X = (float)((v->xsize - 0.5) / 2.0); + // v->ysize needs to be upside down for scaling v->scale.Y = (float)(-(v->ysize - 0.5) / 2.0); v->scale.Z = (float)(-((zsize - 0.5) / 2.0)); }