Last active
August 19, 2017 11:27
-
-
Save Groogy/3b5c09e8ab03e9d80e6b1dcbf0fdaa2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias Vector4f32 = Boleite::Vector4f32 | |
alias Vector2f32 = Boleite::Vector2f32 | |
struct SimpleVertex < Boleite::Vertex | |
@pos = Vector4f32.zero | |
@color = Vector4f32.zero | |
@uv = Vector2f32.zero | |
def initialize | |
end | |
def initialize(@pos, @color, @uv) | |
end | |
def initialize(pos, color, uv) | |
@pos = Vector4f32.new(pos) | |
@color = Vector4f32.new(color) | |
@uv = Vector2f32.new(uv) | |
end | |
end | |
class GameState < Boleite::State | |
class InputHandler < Boleite::InputReceiver | |
def initialize(state) | |
register Boleite::PassThroughAction, ->on_input(Boleite::InputEvent) | |
end | |
def on_input(event) | |
end | |
end | |
@input : InputHandler | Nil | |
@vbo : Boleite::VertexBufferObject | |
@shader : Boleite::Shader | |
def initialize(@app : EgoApplication) | |
super() | |
translation = Boleite::Matrix44f32.identity | |
translation = Boleite::Matrix.translate translation, Boleite::Vector3f32.new(-0.25f32, 0.0f32, 0.0f32) | |
texture = Boleite::Texture.load_file "test.bmp", app.graphics | |
@shader = Boleite::Shader.load_file "test.shader", @app.graphics | |
@shader.set_parameter "testTexture", texture | |
@shader.world_transform = translation | |
vertices = [ | |
SimpleVertex.new([0.0f32, 0.0f32, 0.0f32, 1.0f32], [1.0f32, 0.0f32, 0.0f32, 1.0f32], [0.0f32, 0.0f32]), | |
SimpleVertex.new([0.0f32, 1.0f32, 0.0f32, 1.0f32], [0.0f32, 1.0f32, 0.0f32, 1.0f32], [0.0f32, 1.0f32]), | |
SimpleVertex.new([1.0f32, 0.0f32, 0.0f32, 1.0f32], [0.0f32, 0.0f32, 1.0f32, 1.0f32], [1.0f32, 0.0f32]), | |
SimpleVertex.new([1.0f32, 1.0f32, 0.0f32, 1.0f32], [1.0f32, 1.0f32, 1.0f32, 1.0f32], [1.0f32, 1.0f32]), | |
] | |
layout = Boleite::VertexLayout.new [ | |
Boleite::VertexAttribute.new(4, :float, 40_u32, 0_u32), | |
Boleite::VertexAttribute.new(4, :float, 40_u32, 16_u32), | |
Boleite::VertexAttribute.new(2, :float, 40_u32, 32_u32), | |
] | |
@vbo = @app.graphics.create_vertex_buffer_object | |
@vbo.layout = layout | |
@vbo.primitive = Boleite::Primitive::TrianglesStrip | |
buffer = @vbo.create_buffer | |
buffer.add_data vertices[0] | |
buffer.add_data vertices[1] | |
buffer.add_data vertices[2] | |
buffer.add_data vertices[3] | |
@input = nil | |
end | |
def enable | |
input = InputHandler.new(self) | |
@app.input_router.register(input) | |
@input = input | |
end | |
def disable | |
@app.input_router.unregister(@input) | |
@input = nil | |
end | |
def update(delta) | |
end | |
def render(delta) | |
@shader.activate do | |
@vbo.render | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment