Skip to content

Commit

Permalink
Full support for high-DPI displays on all platforms (tmewett#207)
Browse files Browse the repository at this point in the history
Tiles (fonts and graphics) are now regenerated from a high-resolution
image every time the window is resized. This allows us to perfectly
fit the scene into the window, leaving no black padding on the sides.

To access all pixels in a HiDPI setting, we also switched from
rendering surfaces with `SDL_UpdateWindowSurface`, to
rendering textures with `SDL_RenderPresent`.

Some video drivers are quite inefficient, notably in virtual machines,
so there is a new `--no-gpu` command-line parameter to disable
hardware acceleration. The software renderer does not support
HiDPI, though.
  • Loading branch information
Antony Boucher authored Jan 9, 2021
1 parent 8b4fd40 commit 9485022
Show file tree
Hide file tree
Showing 41 changed files with 876 additions and 188 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ifeq ($(TERMINAL),YES)
endif

ifeq ($(GRAPHICS),YES)
sources += $(addprefix src/platform/,sdl2-platform.c)
sources += $(addprefix src/platform/,sdl2-platform.c tiles.c)
cflags += $(shell $(SDL_CONFIG) --cflags)
cppflags += -DBROGUE_SDL
libs += $(shell $(SDL_CONFIG) --libs) -lSDL2_image
Expand Down Expand Up @@ -51,6 +51,7 @@ windows/icon.o: windows/icon.rc

bin/brogue.exe: $(objects) windows/icon.o
$(CC) $(cflags) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(libs) $(LDLIBS)
mt -manifest windows/brogue.exe.manifest -outputresource:bin/brogue.exe;1

clean:
$(RM) src/brogue/*.o src/platform/*.o bin/brogue{,.exe}
Expand Down
Binary file removed bin/assets/font-1.png
Binary file not shown.
Binary file removed bin/assets/font-10.png
Binary file not shown.
Binary file removed bin/assets/font-11.png
Binary file not shown.
Binary file removed bin/assets/font-12.png
Binary file not shown.
Binary file removed bin/assets/font-13.png
Binary file not shown.
Binary file removed bin/assets/font-14.png
Binary file not shown.
Binary file removed bin/assets/font-15.png
Binary file not shown.
Binary file removed bin/assets/font-2.png
Binary file not shown.
Binary file removed bin/assets/font-3.png
Binary file not shown.
Binary file removed bin/assets/font-4.png
Binary file not shown.
Binary file removed bin/assets/font-5.png
Binary file not shown.
Binary file removed bin/assets/font-6.png
Binary file not shown.
Binary file removed bin/assets/font-7.png
Binary file not shown.
Binary file removed bin/assets/font-8.png
Binary file not shown.
Binary file removed bin/assets/font-9.png
Binary file not shown.
Binary file removed bin/assets/tiles-1.png
Binary file not shown.
Binary file removed bin/assets/tiles-10.png
Binary file not shown.
Binary file removed bin/assets/tiles-11.png
Binary file not shown.
Binary file removed bin/assets/tiles-12.png
Binary file not shown.
Binary file removed bin/assets/tiles-13.png
Binary file not shown.
Binary file removed bin/assets/tiles-14.png
Binary file not shown.
Binary file removed bin/assets/tiles-15.png
Binary file not shown.
Binary file removed bin/assets/tiles-2.png
Binary file not shown.
Binary file removed bin/assets/tiles-3.png
Binary file not shown.
Binary file removed bin/assets/tiles-4.png
Binary file not shown.
Binary file removed bin/assets/tiles-5.png
Diff not rendered.
Binary file removed bin/assets/tiles-6.png
Diff not rendered.
Binary file removed bin/assets/tiles-7.png
Diff not rendered.
Binary file removed bin/assets/tiles-8.png
Diff not rendered.
Binary file removed bin/assets/tiles-9.png
Diff not rendered.
Binary file added bin/assets/tiles.bin
Binary file not shown.
Binary file added bin/assets/tiles.png
1 change: 1 addition & 0 deletions changes/hi-dpi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Brogue CE now supports High DPI displays on Windows, Linux and macOS (Retina).
1 change: 1 addition & 0 deletions changes/scalable-window.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The window is now freely resizable, to perfectly fit any monitor up to 4K size.
27 changes: 18 additions & 9 deletions src/platform/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <math.h>
#include <limits.h>
#include "platform.h"

// Expanding a macro as a string constant requires two levels of macros
Expand All @@ -6,13 +8,11 @@

struct brogueConsole currentConsole;

int brogueFontSize = 0;
char dataDirectory[BROGUE_FILENAME_MAX] = STRINGIFY(DATADIR);
boolean serverMode = false;
boolean hasGraphics = false;
boolean graphicsEnabled = false;
boolean isCsvFormat = false;
boolean initialFullScreen = false;

static void printCommandlineHelp() {
printf("%s",
Expand All @@ -27,9 +27,10 @@ static void printCommandlineHelp() {
"--server-mode run the game in web-brogue server mode\n"
#endif
#ifdef BROGUE_SDL
"--size N starts the game at font size N (1 to 13)\n"
"--size N starts the game at font size N (1 to 20)\n"
"--graphics -G enable graphical tiles\n"
"--full-screen -F enable full screen\n"
"--no-gpu disable hardware-accelerated graphics and HiDPI\n"
#endif
#ifdef BROGUE_CURSES
"--term -t run in ncurses-based terminal mode\n"
Expand Down Expand Up @@ -180,17 +181,25 @@ int main(int argc, char *argv[])

#ifdef BROGUE_SDL
if (strcmp(argv[i], "--size") == 0) {
// pick a font size
int size = atoi(argv[i + 1]);
if (size != 0) {
if (i + 1 < argc) {
int size = atoi(argv[i + 1]);
if (size > 0 && size <= 20) {
windowWidth = round(pow(1.1, size) * 620.);
windowHeight = windowWidth * 9/16;
};

i++;
brogueFontSize = size;
continue;
};
}
}

if (strcmp(argv[i], "-F") == 0 || strcmp(argv[i], "--full-screen") == 0) {
initialFullScreen = true;
fullScreen = true;
continue;
}

if (strcmp(argv[i], "--no-gpu") == 0) {
softwareRendering = true;
continue;
}
#endif
Expand Down
6 changes: 4 additions & 2 deletions src/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ unsigned int glyphToUnicode(enum displayGlyph glyph);

#ifdef BROGUE_SDL
extern struct brogueConsole sdlConsole;
extern int windowWidth;
extern int windowHeight;
extern boolean fullScreen;
extern boolean softwareRendering;
#endif

#ifdef BROGUE_CURSES
Expand All @@ -104,9 +108,7 @@ extern struct brogueConsole webConsole;

extern struct brogueConsole currentConsole;
extern boolean noMenu;
extern int brogueFontSize;
extern char dataDirectory[];
extern boolean initialFullScreen;

// defined in brogue
extern playerCharacter rogue;
Expand Down
Loading

0 comments on commit 9485022

Please sign in to comment.