diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cd73a6..82504d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,11 @@ add_subdirectory(libs/blah) # add our source add_executable(game - + src/main.cpp src/world.cpp - ) + src/game.cpp + src/content.cpp +) # Reference blah target_link_libraries(game blah) diff --git a/src/content.cpp b/src/content.cpp new file mode 100644 index 0000000..0a0119d --- /dev/null +++ b/src/content.cpp @@ -0,0 +1,40 @@ +#include "content.h" + +using namespace TL; + +namespace +{ + FilePath root; +} + +SpriteFont Content::font; + +FilePath Content::path() +{ + if (root.length() <= 0) + { + FilePath up = ""; + do + { + root = Path::normalize(FilePath::fmt("%s/%scontent/", App::path(), up.cstr())); + up.append("../"); + } while (!Directory::exists(root) && up.length() < 30); + + if (!Directory::exists(root)) + BLAH_ERROR("Unable to find content directory!"); + + Log::print("Content Path: %s", root.cstr()); + } + + return root; +} + +void Content::load() +{ + font = SpriteFont(path() + "fonts/dogica.ttf", 8, SpriteFont::ASCII); +} + +void Content::unload() +{ + font.dispose(); +} diff --git a/src/content.h b/src/content.h new file mode 100644 index 0000000..d19821c --- /dev/null +++ b/src/content.h @@ -0,0 +1,17 @@ +#pragma once +#include + +using namespace Blah; + +namespace TL +{ + class Content + { + public: + static SpriteFont font; + + static FilePath path(); + static void load(); + static void unload(); + }; +} \ No newline at end of file diff --git a/src/game.cpp b/src/game.cpp new file mode 100644 index 0000000..6369bb0 --- /dev/null +++ b/src/game.cpp @@ -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(); + } +} diff --git a/src/game.h b/src/game.h new file mode 100644 index 0000000..53e45e2 --- /dev/null +++ b/src/game.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include "world.h" + +using namespace Blah; + +namespace TL +{ + class Game + { + public: + World world; + FrameBufferRef buffer; + Batch batch; + + void startup(); + void shutdown(); + void update(); + void render(); + }; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..4dbf712 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,45 @@ +#include +#include "game.h" + +using namespace Blah; +using namespace TL; + +namespace +{ + Game game; + + void startup() + { + game.startup(); + } + + void shutdown() + { + game.shutdown(); + } + + void update() + { + game.update(); + } + + void render() + { + game.render(); + } +} + +int main() +{ + Config config; + config.name = "Tiny Link"; + config.width = 1280; + config.height = 720; + + config.on_startup = startup; + config.on_shutdown = shutdown; + config.on_update = update; + config.on_render = render; + + App::run(&config); +} \ No newline at end of file