diff --git a/RSDKv3/Drawing.cpp b/RSDKv3/Drawing.cpp index cb228617..e9076404 100644 --- a/RSDKv3/Drawing.cpp +++ b/RSDKv3/Drawing.cpp @@ -60,6 +60,7 @@ byte texBufferMode = 0; #if !RETRO_USE_ORIGINAL_CODE int viewOffsetX = 0; +int viewOffsetY = 0; #endif int viewWidth = 0; int viewHeight = 0; @@ -147,6 +148,7 @@ int InitRenderDevice() SCREEN_CENTERX = SCREEN_XSIZE / 2; viewOffsetX = 0; + viewOffsetY = 0; Engine.window = SDL_CreateWindow(gameTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_XSIZE * Engine.windowScale, SCREEN_YSIZE * Engine.windowScale, SDL_WINDOW_ALLOW_HIGHDPI | flags); @@ -734,7 +736,7 @@ void FlipScreenNoFB() glLoadIdentity(); glOrtho(0, SCREEN_XSIZE << 4, SCREEN_YSIZE << 4, 0.0, -1.0, 1.0); - glViewport(viewOffsetX, 0, viewWidth, viewHeight); + glViewport(viewOffsetX, viewOffsetY, viewWidth, viewHeight); glBindTexture(GL_TEXTURE_2D, gfxTextureID[texPaletteNum]); glEnableClientState(GL_COLOR_ARRAY); @@ -775,7 +777,7 @@ void FlipScreenNoFB() // Return for blended rendering glMatrixMode(GL_PROJECTION); - glViewport(viewOffsetX, 0, viewWidth, viewHeight); + glViewport(viewOffsetX, viewOffsetY, viewWidth, viewHeight); glPopMatrix(); } else { @@ -822,7 +824,7 @@ void FlipScreenHRes() glLoadIdentity(); glOrtho(0, SCREEN_XSIZE << 4, SCREEN_YSIZE << 4, 0.0, -1.0, 1.0); - glViewport(viewOffsetX, 0, bufferWidth, bufferHeight); + glViewport(viewOffsetX, viewOffsetY, bufferWidth, bufferHeight); glBindTexture(GL_TEXTURE_2D, gfxTextureID[texPaletteNum]); glDisable(GL_BLEND); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -868,7 +870,7 @@ void RenderFromTexture() } #endif glLoadIdentity(); - glViewport(viewOffsetX, 0, viewWidth, viewHeight); + glViewport(viewOffsetX, viewOffsetY, viewWidth, viewHeight); glVertexPointer(2, GL_SHORT, sizeof(DrawVertex), &screenRect[0].x); glTexCoordPointer(2, GL_SHORT, sizeof(DrawVertex), &screenRect[0].u); glDisable(GL_BLEND); @@ -942,7 +944,7 @@ void RenderFromRetroBuffer() glClear(GL_COLOR_BUFFER_BIT); } #endif - glViewport(viewOffsetX, 0, viewWidth, viewHeight); + glViewport(viewOffsetX, viewOffsetY, viewWidth, viewHeight); glVertexPointer(2, GL_SHORT, sizeof(DrawVertex), &retroScreenRect[0].x); glTexCoordPointer(2, GL_SHORT, sizeof(DrawVertex), &retroScreenRect[0].u); @@ -1002,7 +1004,7 @@ void FlipScreenVideo() glClear(GL_COLOR_BUFFER_BIT); } #endif - glViewport(viewOffsetX, 0, viewWidth, viewHeight); + glViewport(viewOffsetX, viewOffsetY, viewWidth, viewHeight); glVertexPointer(2, GL_FLOAT, sizeof(DrawVertex3D), &screenVerts[0].x); glTexCoordPointer(2, GL_SHORT, sizeof(DrawVertex3D), &screenVerts[0].u); glDisable(GL_BLEND); @@ -1078,46 +1080,61 @@ void SetFullScreen(bool fs) float scaleH = (mode.h / (float)SCREEN_YSIZE); Engine.useFBTexture = ((float)scaleH - (int)scaleH) != 0 || Engine.scalingMode; - float width = w; + float width = w, height = h; #if RETRO_PLATFORM != RETRO_iOS && RETRO_PLATFORM != RETRO_ANDROID - float aspect = SCREEN_XSIZE_CONFIG / (float)SCREEN_YSIZE; - width = aspect * h; - viewOffsetX = abs(w - width) / 2; - if (width > w) { - int gameWidth = (w / (float)h) * SCREEN_YSIZE; - if (renderType == RENDER_SW) { - SetScreenSize(gameWidth, (gameWidth + 9) & -0x8); - } - else if (renderType == RENDER_HW){ - SetScreenSize(gameWidth, (gameWidth + 9) & -0x10); - } + int winW = 0, winH = 0; +#if RETRO_USING_OPENGL + SDL_GL_GetDrawableSize(Engine.window, &winW, &winH); +#else + SDL_GetRendererOutputSize(Engine.renderer, &winW, &winH); +#endif - width = 0; - while (width <= w) { - width += SCREEN_XSIZE; - } - width -= SCREEN_XSIZE; - viewOffsetX = abs(w - width) / 2; + scaleH = winH / (float)SCREEN_YSIZE; + + width = scaleH * (float)SCREEN_XSIZE; + height = winH; + + if (width > winW) { + width = winW; + + float scaleW = winW / (float)SCREEN_XSIZE; + height = scaleW * (float)SCREEN_YSIZE; + + viewOffsetX = 0; + viewOffsetY = abs(winH - height) / 2; + } + else { + viewOffsetX = abs(winW - width) / 2; + viewOffsetY = 0; } + #else viewOffsetX = 0; + viewOffsetY = 0; #endif - SetScreenDimensions(SCREEN_XSIZE, SCREEN_YSIZE, width, h); + SetScreenDimensions(SCREEN_XSIZE, SCREEN_YSIZE, width, height); } else { viewOffsetX = 0; + viewOffsetY = 0; #if RETRO_USING_SDL1 Engine.windowSurface = SDL_SetVideoMode(SCREEN_XSIZE * Engine.windowScale, SCREEN_YSIZE * Engine.windowScale, 16, SDL_SWSURFACE); SDL_ShowCursor(SDL_TRUE); #endif Engine.useFBTexture = Engine.scalingMode; - SetScreenDimensions(SCREEN_XSIZE_CONFIG, SCREEN_YSIZE, SCREEN_XSIZE_CONFIG * Engine.windowScale, SCREEN_YSIZE * Engine.windowScale); #if RETRO_USING_SDL2 SDL_SetWindowFullscreen(Engine.window, SDL_FALSE); SDL_SetWindowSize(Engine.window, SCREEN_XSIZE_CONFIG * Engine.windowScale, SCREEN_YSIZE * Engine.windowScale); SDL_SetWindowPosition(Engine.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_RestoreWindow(Engine.window); +#if RETRO_USING_OPENGL + int drawableWidth, drawableHeight; + SDL_GL_GetDrawableSize(Engine.window, &drawableWidth, &drawableHeight); + SetScreenDimensions(SCREEN_XSIZE, SCREEN_YSIZE, drawableWidth, drawableHeight); +#else + SetScreenDimensions(SCREEN_XSIZE, SCREEN_YSIZE, SCREEN_XSIZE * Engine.windowScale, SCREEN_YSIZE * Engine.windowScale); +#endif #endif } } @@ -1365,10 +1382,15 @@ void SetScreenDimensions(int width, int height, int winWidth, int winHeight) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SCREEN_XSIZE * 2, SCREEN_YSIZE * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); #endif + int widthFix = 1; + if (SCREEN_XSIZE <= 262) { + widthFix++; + } + screenRect[0].x = -1; screenRect[0].y = 1; screenRect[0].u = 0; - screenRect[0].v = SCREEN_XSIZE * 2; + screenRect[0].v = SCREEN_XSIZE * 2 * widthFix; screenRect[1].x = 1; screenRect[1].y = 1; @@ -1378,7 +1400,7 @@ void SetScreenDimensions(int width, int height, int winWidth, int winHeight) screenRect[2].x = -1; screenRect[2].y = -1; screenRect[2].u = (SCREEN_YSIZE - 0.5) * 4; - screenRect[2].v = SCREEN_XSIZE * 2; + screenRect[2].v = SCREEN_XSIZE * 2 * widthFix; screenRect[3].x = 1; screenRect[3].y = -1; diff --git a/RSDKv3/Drawing.hpp b/RSDKv3/Drawing.hpp index 9b494c83..563d1844 100644 --- a/RSDKv3/Drawing.hpp +++ b/RSDKv3/Drawing.hpp @@ -101,6 +101,7 @@ extern byte texBufferMode; #if !RETRO_USE_ORIGINAL_CODE extern int viewOffsetX; +extern int viewOffsetY; #endif extern int viewWidth; extern int viewHeight; diff --git a/RSDKv3/RetroEngine.cpp b/RSDKv3/RetroEngine.cpp index 81ee4eef..2a42e323 100644 --- a/RSDKv3/RetroEngine.cpp +++ b/RSDKv3/RetroEngine.cpp @@ -71,10 +71,19 @@ bool ProcessEvents() if (touches <= 1) { // Touch always takes priority over mouse uint state = SDL_GetMouseState(&touchX[0], &touchY[0]); - int width = 0, height = 0; + int width = 0, height = 0, pixW = 0, pixH = 0; SDL_GetWindowSize(Engine.window, &width, &height); - touchX[0] = ((touchX[0] - viewOffsetX) / (float)width) * SCREEN_XSIZE; - touchY[0] = (touchY[0] / (float)height) * SCREEN_YSIZE; +#if RETRO_USING_OPENGL + SDL_GL_GetDrawableSize(Engine.window, &pixW, &pixH); +#else + SDL_GetRendererOutputSize(Engine.renderer, &pixW, &pixH); +#endif + + float scaleX = (float)pixW / (float)width; + float scaleY = (float)pixH / (float)height; + + touchX[0] = ((touchX[0] - viewOffsetX / scaleX) / ((float)width - viewOffsetX)) * SCREEN_XSIZE; + touchY[0] = ((touchY[0] - viewOffsetY / scaleY) / ((float)height - viewOffsetY)) * SCREEN_YSIZE; touchDown[0] = state & SDL_BUTTON_LMASK; if (touchDown[0])