charcoal/Example/MyTestTextScene.cpp

61 lines
1.5 KiB
C++

#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;
ret.emplace('a', charcoal::Rectangle<int>(0, image.height / 2, 0, image.width / 2));
ret.emplace('b', charcoal::Rectangle<int>(image.height / 2, image.height, image.width / 2, image.width));
return ret;
}
MyTextTestScene::MyTextTestScene(Application& application)
: Scene(application),
m_font_image(image_loader::load_file(IMAGE_PATH "uber.png")),
m_font(m_font_image, gen_font_stuff(m_font_image)),
m_text_image(m_font.get_text_image("ba")),
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()
{
glutil::clear_screen();
m_pipeline.render();
}