#include "MPFW_Backend_raylib.h"
#include <raylib.h>
#include <vector>
std::vector<Font> _fonts_RL;

void BackEnd_Raylib::Create(MPFW::Backends::Video::ContextParameters param)
{
	InitWindow(param.width, param.height, param.name.c_str());
	SetTargetFPS(param.desiredFps);
}

int BackEnd_Raylib::BE_LoadFont(std::string path)
{
	_fonts_RL.push_back(LoadFontEx(path.c_str(), 360, 0, 4000));
	return _fonts_RL.size() - 1;
}

void BackEnd_Raylib::BE_DrawText(int fontId, std::string text, int x, int y, int fontSize)
{
	DrawTextEx(_fonts_RL[fontId], text.c_str(), { (float)x,(float)y }, fontSize, 0, WHITE);
}

int BackEnd_Raylib::BE_LoadTexture(MPFW::Backends::Video::Agnostic::Picture pic)
{
	Image i;
	i.data = malloc(pic.width * pic.height * 4);
	i.width = pic.width;
	i.height = pic.height;
	std::memcpy(i.data, pic.data.data(), pic.data.size()*4);
	i.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;

	Texture t = LoadTextureFromImage(i);

	free(i.data);

	return t.id;
	

}


