Sha256: cb7401286ca16ca87fd20928f7f57576c3f46f4db1d2db9d03e8484b85454021

Contents?: true

Size: 925 Bytes

Versions: 4

Compression:

Stored size: 925 Bytes

Contents

# This class facilitates rendering text with Nuklear and presenting it using
# OpenGL. It is part of the nuklear-ruby examples.
module Examples
  class OpenGLFont
    attr_reader :path

    def initialize(path, size = 12)
      @path = path
      @size = size
      @texture_id = nil
      @nuklear_handle = nil
    end

    def texture_id
      @texture_id ||= begin
        tex_names_buf = ' ' * 8
        glGenTextures(1, tex_names_buf)
        tex_names_buf.unpack('L1')[0]
      end
    end

    def nuklear_handle
      @nuklear_handle ||= Nuklear::Font.new(path, @size) do |w, h, data|
        glBindTexture(GL_TEXTURE_2D, texture_id)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        texture_id
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nuklear-0.1.3 examples/lib/opengl_font.rb
nuklear-0.1.2 examples/lib/opengl_font.rb
nuklear-0.1.1 examples/lib/opengl_font.rb
nuklear-0.1.0 examples/lib/opengl_font.rb