Class: Engine::Components::UIFontRenderer

Inherits:
Engine::Component show all
Defined in:
lib/engine/components/ui_font_renderer.rb

Instance Attribute Summary collapse

Attributes inherited from Engine::Component

#game_object

Instance Method Summary collapse

Methods inherited from Engine::Component

#_erase!, #destroy, #destroy!, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #renderer?, #set_game_object

Constructor Details

#initialize(font, string) ⇒ UIFontRenderer

Returns a new instance of UIFontRenderer.



9
10
11
12
13
14
# File 'lib/engine/components/ui_font_renderer.rb', line 9

def initialize(font, string)
  @mesh = Engine::PolygonMesh.new([Vector[-0.5, 0.5], Vector[0.5, 0.5], Vector[0.5, -0.5], Vector[-0.5, -0.5]], [[0, 0], [1, 0], [1, 1], [0, 1]])
  @texture = font.texture.texture
  @string = string
  @font = font
end

Instance Attribute Details

#meshObject (readonly)

Returns the value of attribute mesh.



3
4
5
# File 'lib/engine/components/ui_font_renderer.rb', line 3

def mesh
  @mesh
end

#textureObject (readonly)

Returns the value of attribute texture.



3
4
5
# File 'lib/engine/components/ui_font_renderer.rb', line 3

def texture
  @texture
end

Instance Method Details

#startObject



16
17
18
19
20
# File 'lib/engine/components/ui_font_renderer.rb', line 16

def start
  setup_vertex_attribute_buffer
  setup_vertex_buffer
  setup_index_buffer
end

#ui_renderer?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/engine/components/ui_font_renderer.rb', line 5

def ui_renderer?
  true
end

#update(delta_time) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/engine/components/ui_font_renderer.rb', line 27

def update(delta_time)
  shader.use
  GL.BindVertexArray(@vao)
  GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)

  set_shader_per_frame_data

  GL.DrawElementsInstanced(GL::TRIANGLES, mesh.index_data.length, GL::UNSIGNED_INT, 0, @string.length)
  GL.BindVertexArray(0)
  GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, 0)
end

#update_string(string) ⇒ Object



22
23
24
25
# File 'lib/engine/components/ui_font_renderer.rb', line 22

def update_string(string)
  @string = string
  update_vbo_buf
end