From 66cb556fb6f87d195aacf8a25ffafb86d524da19 Mon Sep 17 00:00:00 2001
From: Frederico Linhares <fred@linhares.blue>
Date: Thu, 20 Apr 2023 16:17:49 -0300
Subject: feat Create text rendering system

---
 test/src/main.rb | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'test/src')

diff --git a/test/src/main.rb b/test/src/main.rb
index 33d0b1d..499a49a 100644
--- a/test/src/main.rb
+++ b/test/src/main.rb
@@ -1,4 +1,4 @@
-# Copyright 2022 Frederico de Oliveira Linhares
+# Copyright 2022-2023 Frederico de Oliveira Linhares
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -25,6 +25,8 @@ end
 def init()
   texture = CandyGear::Texture.from_image("textures/color_texture.qoi");
   mesh = CandyGear::Mesh.new("meshes/cube.cgmesh");
+  font = CandyGear::Font.new("/usr/share/fonts/TTF/Vera.ttf", 16);
+  text = CandyGear::Texture.from_text(font, "HelloWorld")
 
   $color = CandyGear::Vector3D.new(0.8, 0.2, 0.2);
   $model = CandyGear::Model.new(mesh, texture);
@@ -32,6 +34,10 @@ def init()
     texture, CandyGear::Vector4D.new(0, 0, 1.0, 1.0));
   $rectangle = CandyGear::Vector4D.new(103.0, 1.0, 100.0, 100.0);
   $sprite_position = CandyGear::Vector4D.new(1.0, 1.0, 100.0, 100.0);
+  $text_sprite = CandyGear::Sprite.new(
+    text, CandyGear::Vector4D.new(0, 0, 1.0, 1.0));
+  $text_position = CandyGear::Vector4D.new(
+    204.0, 1.0, text.width, text.height);
 
   $instances = [
     CandyGear::Vector3D.new(5.0, 0.0, 0.0),
@@ -89,6 +95,7 @@ def quit() = CandyGear.quit();
 
 def tick()
   $sprite.draw($view1, $sprite_position);
+  $text_sprite.draw($view1, $text_position);
   $instances_rotation.rotate(0.0, BOX_ROTATION_SPEED);
   $rectangle.draw_rectangle($view1, $color);
   $instances.each do |i|
-- 
cgit v1.2.3