Skip to content

Instantly share code, notes, and snippets.

View Groogy's full-sized avatar

Groogy Groogy

View GitHub Profile
@Groogy
Groogy / problem.cr
Last active September 23, 2017 16:47
class Page
# ....
private def render_glyph_to_texture(glyph, width, height) : Nil
bitmap = @face.value.glyph.value.bitmap
buffer = Bytes.new bitmap.buffer, bitmap.width * bitmap.rows
show_pixels bitmap.buffer, bitmap.width, bitmap.rows
@texture.update(bitmap.buffer, bitmap.width, bitmap.rows, 0, 0, 8)
end
def show_pixels(pixels, width, height)
require "boleite"
require "./ego/*"
require "./ego/serializers/*"
app = EgoApplication.new # Inherits from Boleite::Application, defines how to get the configuration
app.state_stack.push GameState.new(app)
app.run
require "crystal-clear"
class FooBar
invariants do
@val != nil
end
def initialize(@val = nil)
@val = 5
end
alias Vector4f32 = Boleite::Vector4f32
alias Vector2f32 = Boleite::Vector2f32
struct SimpleVertex < Boleite::Vertex
@pos = Vector4f32.zero
@color = Vector4f32.zero
@uv = Vector2f32.zero
def initialize
end
if LibGLFW3.init != 0
error_callback = ->(error : Int32, description : Int8*) {
puts "Error #{error}: #{String.new(description.as(UInt8*))}"
}
LibGLFW3.setErrorCallback(error_callback)
LibGLFW3.windowHint(LibGLFW3::OPENGL_PROFILE, LibGLFW3::OPENGL_CORE_PROFILE)
LibGLFW3.windowHint(LibGLFW3::OPENGL_FORWARD_COMPAT, 1)
LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MAJOR, 4)
LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MINOR, 2)
if LibGLFW3.init != 0
error_callback = ->(error : Int32, description : Int8*) {
puts "Error #{error}: #{String.new(description.as(UInt8*))}"
}
LibGLFW3.setErrorCallback(error_callback)
LibGLFW3.windowHint(LibGLFW3::OPENGL_PROFILE, LibGLFW3::OPENGL_CORE_PROFILE)
LibGLFW3.windowHint(LibGLFW3::OPENGL_FORWARD_COMPAT, 1)
LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MAJOR, 4)
LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MINOR, 2)
abstract class Glue
abstract def interested?(input) : Bool
abstract def execute(input) : Nil
end
class GlueImp(T, P) < Glue
def initialize(@bar : T, @callback : P)
end
def interested?(input) : Bool
receiver = Boleite::InputReceiver.new
receiver.action_table << Boleite::DefaultAction.new :close
receiver.action_table << Boleite::MoveCameraAction.new :player_camera
receiver.register :close, ->() { puts "Closing!" }
receiver.register :player_camera, ->(x : Float64, y : Float64) { puts "Moving camera!" }
receiver.process Boleite::ClosedEvent.new
receiver.process Boleite::MouseMovedEvent.new(some_x, some_y)
# Binding code
type Monitor = Void*
type Window = Void*
type Cursor = Void*
# My code
module Boleite
# Forward declaration
class RenderTarget
module Boleite
abstract struct Configuration
end
abstract class Application
getter :configuration
@configuration : Configuration
def initialize()