8061ffeef5
number of rendered elements. This was pretty easy since the elements were getting re-allocated in the graphics card every frame. TODO would be to make the re-allocation not happen every frame but rather only happen when a re-allocation is nescessary and rather just not fully re-populate the buffer if not every element is used or have some other sort of automated way of handling the VRAM.
67 lines
1.8 KiB
C++
67 lines
1.8 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;
|
|
std::string alpha = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`1234567890-=[]\\;',./~!@#$%^&*()_+{}|:\"<>?";
|
|
unsigned int delta_x = 9;
|
|
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));
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
MyTextTestScene::MyTextTestScene(Application& application)
|
|
: Scene(application),
|
|
m_font_image(image_loader::load_file(IMAGE_PATH "consolas-16px.png")),
|
|
m_font(m_font_image, gen_font_stuff(m_font_image)),
|
|
m_text_image(m_font.get_text_image("The difference between me (and you) is that 2 + 2 = 4!")),
|
|
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)
|
|
{
|
|
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()
|
|
{
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
glutil::clear_screen();
|
|
m_pipeline.render();
|
|
}
|
|
|
|
|