-
-
Save domgetter/19bb6e405d8f7d9a8eabecc178bee819 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
class ShaderProgram | |
def use | |
print "in program.use. id: " | |
puts @id | |
GL.use_program.call(@id) | |
end | |
def use | |
print "in program.use. id: " | |
puts @id | |
GL.use_program.call(@id) | |
yield | |
GL.use_program.call(0_u32) | |
end | |
def unuse | |
GL.use_program.call(0_u32) | |
end | |
end | |
SDL.init do | |
puts "sdl is running" | |
SDL::Window.new(title: "Crystal OpenGL Demo", width: 1920, height: 1080, | |
flags: LibSDL::WINDOW_OPENGL | LibSDL::WINDOW_FULLSCREEN_DESKTOP) do |window| | |
running = true | |
position_location = uninitialized LibGL::Int | |
puts "now running" | |
a = [ -1_f32, 1_f32, -1_f32 ] | |
b = [ -1_f32, -1_f32, 1_f32 ] | |
c = [ 1_f32, 1_f32, 1_f32 ] | |
d = [ 1_f32, -1_f32, -1_f32 ] | |
triangle = [ | |
a, c, b, | |
a, b, d, | |
b, c, d, | |
c, a, d | |
].flatten | |
#load shader source strings | |
#create shader programs | |
program = ShaderProgram.new("simple") | |
program.compile | |
program.bind | |
program.link | |
# aaaaa = 7 # if I uncomment, the triangles don't show up | |
# BUT, if I use the non-block version of program.use, it all works either way. | |
# So A) define aaaaa, program.use do, No Work | |
# B) nodefine aaaaa, program.use do, Work | |
# C) define aaaaa, program.use, Work | |
# D) nodefine aaaaa, program.use, Work | |
program.use do | |
# ... | |
# draw triangles to the screen | |
LibGL.draw_arrays(LibGL::TRIANGLES, 0_u32, triangle.size/3) | |
# ... | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment