From b2c1bd9e6dfe336eb407a082ab0858b1757cde0e Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 22 Dec 2017 12:56:22 -0600 Subject: [PATCH] Hello world, in rendered text; use nearest pixel sampling The scale change removes some blurriness that we saw when copying pixels from the bitmap font into the renderer. --- src/apple2.c | 11 +++++++++++ src/vm_bitfont.c | 9 ++++++++- src/vm_screen.c | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/apple2.c b/src/apple2.c index 1e8c72d..a3664d4 100644 --- a/src/apple2.c +++ b/src/apple2.c @@ -86,10 +86,21 @@ apple2_set_color(apple2 *mach, int mode) // correct color interpretation } +#define SHOW(ch) \ + vm_bitfont_render(mach->sysfont, mach->screen, &area, ch); \ + area.x += 7 + void apple2_run_loop(apple2 *mach) { + SDL_Rect area; + + while (vm_screen_active(mach->screen)) { + area.x = 50; + area.y = 50; + SHOW('H'); SHOW('e'); SHOW('l'); SHOW('l'); SHOW('o'); SHOW(' '); + SHOW('w'); SHOW('o'); SHOW('r'); SHOW('l'); SHOW('d'); SHOW('!'); vm_screen_refresh(mach->screen); } } diff --git a/src/vm_bitfont.c b/src/vm_bitfont.c index 9100596..82b1cb7 100644 --- a/src/vm_bitfont.c +++ b/src/vm_bitfont.c @@ -98,10 +98,17 @@ vm_bitfont_render(vm_bitfont *font, src.w = font->width; src.h = font->height; + // The source and destination width/height must match. This might be + // a faulty assumption down the road; for now, it holds. + dest->w = src.w; + dest->h = src.h; + // Get the spot in the bitmap where the glyph is found vm_bitfont_offset(font, ch, &src.x, &src.y); - if (SDL_RenderCopy(screen->render, font->texture, dest, &src) < 0) { + log_critical("src.x = %d, src.y = %d", src.x, src.y); + + if (SDL_RenderCopy(screen->render, font->texture, &src, dest) < 0) { log_critical("Failed to render glyph: %s", SDL_GetError()); return ERR_GFXOP; } diff --git a/src/vm_screen.c b/src/vm_screen.c index fe78e07..63ea86e 100644 --- a/src/vm_screen.c +++ b/src/vm_screen.c @@ -84,7 +84,7 @@ vm_screen_add_window(vm_screen *screen, int width, int height) // We plan to draw onto a surface that is xcoords x ycoords in area, // regardless of the actual size of the window. - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); // We default to a logical coordinate system of exactly the given // width and height. For emulated systems like the Apple II, this