Fonts.cpp
// Load new texture from file path
Load new texture from file path
Load new texture from file path
int Fonts::Load(Application* app, const char* texture_path, const char* characters, uint rows)
{
	int id = -1;
	if (texture_path == nullptr || characters == nullptr || rows == 0)
	{
		LOG("Could not load font");
		return id;
	}
	SDL_Texture* tex = app->textures->Load(texture_path);
	if (tex == nullptr || strlen(characters) >= MAX_FONT_CHARS)
	{
		LOG("Could not load font at %s with characters '%s'", texture_path, characters);
		return id;
	}
	id = 0;
	for (; id < MAX_FONTS; ++id)
		if (fonts[id].texture == nullptr)
			break;
	if (id == MAX_FONTS)
	{
		LOG("Cannot load font %s. Array is full (max %d).", texture_path, MAX_FONTS);
		return id;
	}
	Font& font = fonts[id];
	font.texture = tex;
	font.rows = rows;
	strcpy_s(fonts[id].table, MAX_FONT_CHARS, characters);
	font.totalLength = strlen(characters);
	font.columns = fonts[id].totalLength / rows;
	uint tex_w, tex_h;
	app->textures->GetSize(tex, tex_w, tex_h);
	font.char_w = 32;
	font.char_h = 55;
	LOG("Successfully loaded BMP font from %s", texture_path);
	return id;
}
int Fonts :: Load ( Application * app , const char * texture_path , const char * characters , uint rows ) { int id = -1 ; if ( texture_path == nullptr || characters == nullptr || rows == 0 ) { LOG ( " " ) ; return id ; } SDL_Texture * tex = app -> textures -> Load ( texture_path ) ; if ( tex == nullptr || strlen ( characters ) >= MAX_FONT_CHARS ) { LOG ( " " , texture_path , characters ) ; return id ; } id = 0 ; for ( ; id < MAX_FONTS ; ++ id ) if ( fonts [ id ] . texture == nullptr ) break ; if ( id == MAX_FONTS ) { LOG ( " " , texture_path , MAX_FONTS ) ; return id ; } Font & font = fonts [ id ] ; font . texture = tex ; font . rows = rows ; strcpy_s ( fonts [ id ] . table , MAX_FONT_CHARS , characters ) ; font . totalLength = strlen ( characters ) ; font . columns = fonts [ id ] . totalLength / rows ; uint tex_w , tex_h ; app -> textures -> GetSize ( tex , tex_w , tex_h ) ; font . char_w = 32 ; font . char_h = 55 ; LOG ( " " , texture_path ) ; return id ; }
Load new texture from file path
Load new texture from file path
//Finish storing font data // totalLength ---	length of the lookup table // table ---------  All characters displayed in the same order as the texture // columns -------  Amount of chars per row of the texture // char_w --------	Width of each character // char_h --------	Height of each character