/*
GameEngine and Editor
by John Ryland
Copyright (c) 2023
*/
////////////////////////////////////////////////////////////////////////////////////
// Assets
#include <stdio.h>
#include "NkAssets.h"
namespace GameEngine {
Assets::Assets()
{
}
Assets::~Assets()
{
nk_font_atlas_clear(&atlas);
}
void Assets::InitFonts(IRenderDevice& device, FontDesc* fontList, size_t fontListSize)
{
struct nk_font_config cfg = nk_font_config(0);
cfg.oversample_h = 3;
cfg.oversample_v = 2;
nk_font_atlas_init_default(&atlas);
nk_font_atlas_begin(&atlas);
for (int i = 0; i < fontListSize; ++i)
{
fontList[i].font = nk_font_atlas_add_from_file(&atlas, fontList[i].fontFile, fontList[i].fontSize, &cfg);
}
int w, h;
const void *image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
Image img;
img.Assign(w, h, (uint8_t*)image, false);
struct nk_image font_tex = device.UploadTexture(img, false);//true);
nk_font_atlas_end(&atlas, font_tex.handle, device.NullTexture());//&device.tex_null);
}
void Assets::LoadImages(IRenderDevice& device, ImageDesc* imageList, size_t imageListSize)
{
for (int i = 0; i < imageListSize; ++i)
{
GameEngine::Image image;
image.Load(imageList[i].imageFile);
imageList[i].image = device.UploadTexture(image, true);
}
}
} // GameEngine namespace