mirror of
https://github.com/NoelFB/tiny_link.git
synced 2025-12-14 14:07:07 +08:00
adding gameplay buffer
This commit is contained in:
55
src/game.cpp
Normal file
55
src/game.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include "game.h"
|
||||
#include "content.h"
|
||||
|
||||
using namespace TL;
|
||||
|
||||
void Game::startup()
|
||||
{
|
||||
// load our content
|
||||
Content::load();
|
||||
|
||||
// framebuffer for the game
|
||||
buffer = FrameBuffer::create(320, 180);
|
||||
|
||||
// set batcher to use Nearest Filter
|
||||
batch.default_sampler = TextureSampler(TextureFilter::Nearest);
|
||||
}
|
||||
|
||||
void Game::shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Game::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Game::render()
|
||||
{
|
||||
// draw gameplay stuff
|
||||
{
|
||||
buffer->clear(Color::red);
|
||||
|
||||
batch.str(Content::font, "Hello World", Vec2(32, 32), Color::white);
|
||||
batch.render(buffer);
|
||||
batch.clear();
|
||||
}
|
||||
|
||||
// draw buffer to the screen
|
||||
{
|
||||
float scale = Calc::min(
|
||||
App::backbuffer->width() / (float)buffer->width(),
|
||||
App::backbuffer->height() / (float)buffer->height());
|
||||
|
||||
Vec2 screen_center = Vec2(App::backbuffer->width(), App::backbuffer->height()) / 2;
|
||||
Vec2 buffer_center = Vec2(buffer->width(), buffer->height()) / 2;
|
||||
|
||||
App::backbuffer->clear(Color::black);
|
||||
batch.push_matrix(Mat3x2::create_transform(screen_center, buffer_center, Vec2::one * scale, 0));
|
||||
batch.tex(buffer->attachment(0), Vec2::zero, Color::white);
|
||||
batch.pop_matrix();
|
||||
batch.render(App::backbuffer);
|
||||
batch.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user