summaryrefslogtreecommitdiff
path: root/test/src/main.rb
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2023-04-24 13:32:39 -0300
committerFrederico Linhares <fred@linhares.blue>2023-04-24 13:32:39 -0300
commit959b717b46c00930a66fb8959d3469c0b63f3e66 (patch)
treeff03dc62b3b06929af4545c02d385320828b2229 /test/src/main.rb
parent66cb556fb6f87d195aacf8a25ffafb86d524da19 (diff)
fixt Improve text rendering
Diffstat (limited to 'test/src/main.rb')
-rw-r--r--test/src/main.rb29
1 files changed, 20 insertions, 9 deletions
diff --git a/test/src/main.rb b/test/src/main.rb
index 499a49a..bc28ffc 100644
--- a/test/src/main.rb
+++ b/test/src/main.rb
@@ -25,8 +25,13 @@ 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")
+ # FIXME: Text rendering crashes with this font:
+ # font = CandyGear::Font.new("/usr/share/fonts/TTF/sazanami-mincho.ttf", 16);
+ # FIXME: This font, under this path, may not be present in all Linuxes:
+ font = CandyGear::Font.new("/usr/share/fonts/TTF/HanaMinA.ttf", 30);
+ japanese_text = CandyGear::Texture.from_text(font, "こんにちは世界!");
+ english_text = CandyGear::Texture.from_text(
+ font, "The quick brown fox jumps");
$color = CandyGear::Vector3D.new(0.8, 0.2, 0.2);
$model = CandyGear::Model.new(mesh, texture);
@@ -34,10 +39,15 @@ 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);
+ $japanese_text_sprite = CandyGear::Sprite.new(
+ japanese_text, CandyGear::Vector4D.new(0, 0, 1.0, 1.0));
+ $japanese_text_position = CandyGear::Vector4D.new(
+ 204.0, 1.0, japanese_text.width, japanese_text.height);
+ $english_text_sprite = CandyGear::Sprite.new(
+ english_text, CandyGear::Vector4D.new(0, 0, 1.0, 1.0));
+ $english_text_position = CandyGear::Vector4D.new(
+ 204.0, japanese_text.height + 2.0,
+ english_text.width, english_text.height);
$instances = [
CandyGear::Vector3D.new(5.0, 0.0, 0.0),
@@ -54,9 +64,9 @@ def init()
color = CandyGear::Vector3D.new(0.12, 0.12, 0.18);
$view1 = CandyGear::View2D.new(
- CandyGear::Vector4D.new(0, 0, 1280, 360), 640, 180);
+ CandyGear::Vector4D.new(0, 0, 1280, 240), 640, 120);
$view2 = CandyGear::View3D.new(
- CandyGear::Vector4D.new(0, 360, 1280, 360), 1280, 360);
+ CandyGear::Vector4D.new(0, 240, 1280, 480), 1280, 480);
CandyGear.views = [$view1, $view2];
$view2.camera_position = $camera_position;
@@ -95,7 +105,8 @@ def quit() = CandyGear.quit();
def tick()
$sprite.draw($view1, $sprite_position);
- $text_sprite.draw($view1, $text_position);
+ $japanese_text_sprite.draw($view1, $japanese_text_position);
+ $english_text_sprite.draw($view1, $english_text_position);
$instances_rotation.rotate(0.0, BOX_ROTATION_SPEED);
$rectangle.draw_rectangle($view1, $color);
$instances.each do |i|