Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues relating to Fullscreen #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 50 additions & 28 deletions RSDKv3/Drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions RSDKv3/Drawing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 12 additions & 3 deletions RSDKv3/RetroEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down