2018-10-19 05:08:21 +00:00
|
|
|
#include "MyTextTestScene.h"
|
|
|
|
|
|
|
|
#include <charcoal/TextureFactory.h>
|
|
|
|
|
|
|
|
#include <charcoal-builtin/MeshGenerator.h>
|
|
|
|
#include <charcoal-builtin/TextureGenerator.h>
|
|
|
|
#include <charcoal-builtin/GLUtil.h>
|
|
|
|
|
|
|
|
std::map<char, charcoal::Rectangle<int>> gen_font_stuff(const image_loader::ImageRGBA& image)
|
|
|
|
{
|
|
|
|
std::map<char, charcoal::Rectangle<int>> ret;
|
2018-10-19 22:30:54 +00:00
|
|
|
std::string alpha = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
unsigned int delta_x = 18;
|
|
|
|
unsigned int height = image.height;
|
|
|
|
for (unsigned int i = 0; i < alpha.size(); ++i)
|
|
|
|
{
|
|
|
|
ret.emplace(alpha[i], charcoal::Rectangle<int>(0, height, i * delta_x, (i + 1) * delta_x));
|
|
|
|
}
|
2018-10-19 05:08:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyTextTestScene::MyTextTestScene(Application& application)
|
|
|
|
: Scene(application),
|
2018-10-19 22:30:54 +00:00
|
|
|
m_font_image(image_loader::load_file(IMAGE_PATH "consolas-32px.png")),
|
2018-10-19 05:08:21 +00:00
|
|
|
m_font(m_font_image, gen_font_stuff(m_font_image)),
|
2018-10-19 22:30:54 +00:00
|
|
|
m_text_image(m_font.get_text_image("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 test")),
|
2018-10-19 05:08:21 +00:00
|
|
|
m_text(
|
|
|
|
meshgenerator::gen_rect_pt<textured::Vertex, textured::Index>(DRAW_TRIANGLES, (float)m_text_image.width, (float)m_text_image.height),
|
|
|
|
DRAW_TRIANGLES,
|
|
|
|
TextureFactory::gen_image_texture(m_text_image),
|
|
|
|
texturegenerator::gen_quick_sampler()
|
|
|
|
),
|
|
|
|
m_camera(m_screen_size),
|
|
|
|
m_text_batch(&m_text, 1)
|
|
|
|
{
|
|
|
|
m_pipeline.set_camera(&m_camera);
|
|
|
|
m_pipeline.add_batch(&m_text_batch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyTextTestScene::init()
|
|
|
|
{
|
|
|
|
m_text_batch.init();
|
|
|
|
|
|
|
|
m_text_batch.reset_rendered();
|
|
|
|
m_text_batch.add_rendered(m_text_pose);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyTextTestScene::update(float delta_time, clock_t clock)
|
|
|
|
{
|
|
|
|
// Do Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyTextTestScene::prerender()
|
|
|
|
{
|
|
|
|
m_camera.prerender();
|
|
|
|
m_text_batch.prerender();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyTextTestScene::render()
|
|
|
|
{
|
2018-10-19 22:30:54 +00:00
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
2018-10-19 05:08:21 +00:00
|
|
|
glutil::clear_screen();
|
|
|
|
m_pipeline.render();
|
|
|
|
}
|
|
|
|
|
|
|
|
|