Also render UI at chosen resolution.

This commit is contained in:
Steve 2018-12-17 08:30:47 +00:00
parent 3739ef4a42
commit 975ece4796
13 changed files with 40 additions and 33 deletions

View File

@ -2,8 +2,10 @@ Changelog
1.5 1.5
* Game now renders at chosen resolution instead of scaling up from 1280 x 720
* Added command line switch -size to allow for custom window sizes. * Added command line switch -size to allow for custom window sizes.
- For example: -size 900x600 for a width and height of 900 x 600. - For example: -size 900x600 for a width and height of 900 x 600.
* Minimum resolution is now 1280 x 720
* Graphics and fonts now use texture atlases to help with performance. * Graphics and fonts now use texture atlases to help with performance.
* Misc. bug fixes. * Misc. bug fixes.

View File

@ -276,13 +276,13 @@ static void drawMenu(void)
if (app.modalDialog.type == MD_NONE) if (app.modalDialog.type == MD_NONE)
{ {
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 400; r.w = 400;
r.h = 400; r.h = 400;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;

View File

@ -56,8 +56,6 @@ void initMissionInfo(void)
void drawMissionInfo(void) void drawMissionInfo(void)
{ {
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
switch (battle.status) switch (battle.status)
@ -111,6 +109,8 @@ static void drawMissionSummary(AtlasImage *header)
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
blit(header, UI_WIDTH / 2, 150, 1); blit(header, UI_WIDTH / 2, 150, 1);
if (!game.currentMission->challengeData.isChallenge) if (!game.currentMission->challengeData.isChallenge)

View File

@ -100,13 +100,13 @@ void drawFighterDatabase(void)
Entity *fighter; Entity *fighter;
int i, y, numCannons; int i, y, numCannons;
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 700; r.w = 700;
r.h = 650; r.h = 650;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;

View File

@ -91,13 +91,13 @@ static void drawMain(void)
{ {
SDL_Rect r; SDL_Rect r;
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 500; r.w = 500;
r.h = 600; r.h = 600;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;
@ -157,6 +157,11 @@ static void controls(void)
static void changeWindowSize(char *value) static void changeWindowSize(char *value)
{ {
sscanf(value, "%d x %d", &app.winWidth, &app.winHeight); sscanf(value, "%d x %d", &app.winWidth, &app.winHeight);
SDL_SetWindowSize(app.window, app.winWidth, app.winHeight);
app.uiOffset.x = (app.winWidth / 2) - (UI_WIDTH / 2);
app.uiOffset.y = (app.winHeight / 2) - (UI_HEIGHT / 2);
} }
static void changeSoundVolume(char *value) static void changeSoundVolume(char *value)

View File

@ -131,13 +131,13 @@ void drawStats(void)
int i, y, startIndex; int i, y, startIndex;
SDL_Rect r; SDL_Rect r;
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 500; r.w = 500;
r.h = 600; r.h = 600;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;

View File

@ -133,13 +133,13 @@ void drawTrophies(void)
SDL_Rect r; SDL_Rect r;
int start, end, i, x, y; int start, end, i, x, y;
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = boxWidth; r.w = boxWidth;
r.h = 650; r.h = 650;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;

View File

@ -498,8 +498,7 @@ typedef struct {
int saveGame; int saveGame;
int winWidth; int winWidth;
int winHeight; int winHeight;
PointF scale; SDL_Point uiOffset;
PointF uiScale;
int fullscreen; int fullscreen;
int musicVolume; int musicVolume;
int soundVolume; int soundVolume;

View File

@ -152,13 +152,13 @@ void drawControls(void)
int i; int i;
SDL_Rect r; SDL_Rect r;
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 800; r.w = 800;
r.h = 650; r.h = 650;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;

View File

@ -73,6 +73,13 @@ void prepareScene(void)
void presentScene(void) void presentScene(void)
{ {
SDL_Rect uiDest;
uiDest.w = UI_WIDTH;
uiDest.h = UI_HEIGHT;
uiDest.x = (app.winWidth / 2) - (UI_WIDTH / 2);
uiDest.y = (app.winHeight / 2) - (UI_HEIGHT / 2);
if (dev.debug) if (dev.debug)
{ {
drawText(5, app.winHeight - 25, 14, TA_LEFT, colors.white, "DEBUG MODE"); drawText(5, app.winHeight - 25, 14, TA_LEFT, colors.white, "DEBUG MODE");
@ -85,7 +92,7 @@ void presentScene(void)
SDL_SetRenderTarget(app.renderer, NULL); SDL_SetRenderTarget(app.renderer, NULL);
SDL_RenderCopy(app.renderer, app.backBuffer, NULL, NULL); SDL_RenderCopy(app.renderer, app.backBuffer, NULL, NULL);
SDL_RenderCopy(app.renderer, app.uiBuffer, NULL, NULL); SDL_RenderCopy(app.renderer, app.uiBuffer, NULL, &uiDest);
if (!app.hideMouse) if (!app.hideMouse)
{ {
drawMouse(); drawMouse();

View File

@ -113,19 +113,13 @@ void initSDL(int argc, char *argv[])
app.backBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, app.winWidth, app.winHeight); app.backBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, app.winWidth, app.winHeight);
app.scale.x = app.scale.y = 1;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Game scale factor: %.2f,%.2f\n", app.scale.x, app.scale.y);
app.uiBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, UI_WIDTH, UI_HEIGHT); app.uiBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, UI_WIDTH, UI_HEIGHT);
SDL_SetTextureBlendMode(app.uiBuffer, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(app.uiBuffer, SDL_BLENDMODE_BLEND);
app.uiScale.x = UI_WIDTH; app.uiOffset.x = (app.winWidth / 2) - (UI_WIDTH / 2);
app.uiScale.x /= app.winWidth; app.uiOffset.y = (app.winHeight / 2) - (UI_HEIGHT / 2);
app.uiScale.y = UI_HEIGHT;
app.uiScale.y /= app.winHeight;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "UI scale factor: %.2f,%.2f\n", app.uiScale.x, app.uiScale.y); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "UI offset: %d,%d\n", app.uiOffset.x, app.uiOffset.y);
} }
void initGameSystem(void) void initGameSystem(void)

View File

@ -166,11 +166,11 @@ void doInput(void)
SDL_GetMouseState(&x, &y); SDL_GetMouseState(&x, &y);
app.mouse.x = x * app.scale.x; app.mouse.x = x;
app.mouse.y = y * app.scale.y; app.mouse.y = y;
app.uiMouse.x = x * app.uiScale.x; app.uiMouse.x = x - app.uiOffset.x;
app.uiMouse.y = y * app.uiScale.y; app.uiMouse.y = y - app.uiOffset.y;
} }
void clearInput(void) void clearInput(void)

View File

@ -101,14 +101,14 @@ void drawModalDialog(void)
{ {
SDL_Rect r; SDL_Rect r;
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
app.textWidth = 700; app.textWidth = 700;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 96); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 96);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 800; r.w = 800;
r.h = getWrappedTextHeight(app.modalDialog.message, 24) + 100; r.h = getWrappedTextHeight(app.modalDialog.message, 24) + 100;
r.x = (UI_WIDTH / 2) - (r.w / 2); r.x = (UI_WIDTH / 2) - (r.w / 2);