Skip to content

Instantly share code, notes, and snippets.

@domgetter
Created January 11, 2019 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domgetter/19bb6e405d8f7d9a8eabecc178bee819 to your computer and use it in GitHub Desktop.
Save domgetter/19bb6e405d8f7d9a8eabecc178bee819 to your computer and use it in GitHub Desktop.
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