Skip to content

Commit

Permalink
sdlconsole: test fix for glyph building
Browse files Browse the repository at this point in the history
  • Loading branch information
dhthwy committed Nov 20, 2024
1 parent b44a35a commit 47c3ed7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions library/Console-sdl-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <set>
//#include <cuchar>

#include "SDL_pixels.h"
#include "modules/DFSDL.h"
#include "SDL_console.h"

Expand Down Expand Up @@ -1390,18 +1391,17 @@ class BMPFontLoader : public FontLoader {
return nullptr;
}

//sdl_console::SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0);
// FIXME: hardcoded magenta
Uint32 bg_color = sdl_console::SDL_MapRGB(surface->format, 255, 0, 255);
sdl_console::SDL_SetColorKey(surface, SDL_TRUE, bg_color);

std::vector<Glyph> glyphs;
// FIXME: magic numbers
glyphs = build_glyph_rects(surface->pitch, surface->h, 16, 16);

int width = surface->pitch;
int height = surface->h;

std::vector<Glyph> glyphs;
// FIXME: magic numbers
glyphs = build_glyph_rects(surface->format->BytesPerPixel, width, height, 16, 16);

SDL_Surface* conv_surface = sdl_console::SDL_CreateRGBSurface(0, surface->pitch, surface->h, 32,
0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
if (!conv_surface)
Expand Down Expand Up @@ -1435,7 +1435,7 @@ class BMPFontLoader : public FontLoader {
BMPFontLoader& operator=(BMPFontLoader&& other) noexcept = default;

private:
std::vector<Glyph> build_glyph_rects(int sheet_w, int sheet_h, int columns, int rows)
std::vector<Glyph> build_glyph_rects(int bytes_per_pixel, int sheet_w, int sheet_h, int columns, int rows)
{
int tile_w = sheet_w / columns;
int tile_h = sheet_h / rows;
Expand All @@ -1447,7 +1447,8 @@ class BMPFontLoader : public FontLoader {
int r = i / rows;
int c = i % columns;
Glyph glyph;
glyph.rect = { tile_w * c, tile_h * r, tile_w, tile_h };
//glyph.rect = { tile_w * c, tile_h * r, tile_w, tile_h };
glyph.rect = { tile_w * c * bytes_per_pixel, tile_h * r, tile_w * bytes_per_pixel, tile_h };
glyphs.push_back(glyph);
}
return glyphs;
Expand Down

0 comments on commit 47c3ed7

Please sign in to comment.