summaryrefslogtreecommitdiff
path: root/c2.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-27 11:35:01 +1100
committerquou <quou@disroot.org>2024-12-27 11:36:20 +1100
commit6736966974aea334e119cdb0b6c330066061bf91 (patch)
treea16cc9a3d12e6f9468dbb8fe30146acd78f4af64 /c2.cpp
parent5f9100b935a27bbb6d5ac8ab2050b19ba2894087 (diff)
basic text rendering
Diffstat (limited to 'c2.cpp')
-rw-r--r--c2.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/c2.cpp b/c2.cpp
index 3ea05b9..223e0b0 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -1,4 +1,5 @@
#include "app.hpp"
+#include "ui.hpp"
#include "video.hpp"
extern "C" {
#include "plat.h"
@@ -9,6 +10,7 @@ extern "C" {
#define video_arena_size (1024 * 1024 * 16)
#define asset_arena_size (1024 * 1024 * 4)
+#define ui_arena_size (1024 * 16)
#define per_frame_memory_size (1024 * 1024)
static float verts[] = {
@@ -64,15 +66,15 @@ struct Config_Buffer {
};
int main() {
- Arena video_arena;
- Arena asset_arena;
+ Arena video_arena, asset_arena, ui_arena;
Asset_Arena assets;
Device* dev;
- Shader* shader;
+ Shader* shader, * ui_shader;
Texture* texture;
Texture* texture2;
Buffer_Id vbo, cbuf;
Sampler_Id clamped_linear;
+ UI* ui;
C2* app = App::create<C2>("c2");
void* per_frame;
int frame = 0;
@@ -87,10 +89,16 @@ int main() {
arena_alloc(app->arena, asset_arena_size),
asset_arena_size
);
+ init_arena(
+ &ui_arena,
+ arena_alloc(app->arena, ui_arena_size),
+ ui_arena_size
+ );
assets.init(&asset_arena, "pack");
dev = Device::create(&video_arena, app);
app->dev = dev;
shader = (Shader*)assets.load("triangle.csh");
+ ui_shader = (Shader*)assets.load("ui.csh");
texture = (Texture*)assets.load("22.tex");
texture2 = (Texture*)assets.load("kita.tex");
cbuf = dev->create_buffer(
@@ -103,6 +111,8 @@ int main() {
per_frame_memory_size
);
clamped_linear = create_clamped_linear(dev);
+ ui = UI::create(dev, &ui_arena, ui_shader->id);
+ ui->create_label("Hello, world", 10, 15);
assert(per_frame != 0);
uint8_t r = 0;
vbo = upload_verts(dev);
@@ -113,6 +123,8 @@ int main() {
app->begin();
dev->begin_frame();
+ ui->update(&frame_arena);
+
{
void* mem;
mem = dev->map_buffer(cbuf, 0, sizeof(Config_Buffer));
@@ -154,11 +166,14 @@ int main() {
dev->get_ctx().submit(draw, pip, pass);
+ ui->render(&frame_arena, dev->get_backbuffer());
+
r += 10;
frame++;
dev->present();
app->end();
}
+ ui->destroy();
assets.destroy();
dev->destroy_sampler(clamped_linear);
dev->destroy_buffer(vbo);