add optional interframe blending with m key

This commit is contained in:
Matthew Berry 2021-03-31 00:26:10 -07:00
parent 09481ae54d
commit 6f7f10d292
3 changed files with 15 additions and 1 deletions

View file

@ -10,6 +10,8 @@ class Display
@last_time = Time.utc
@seconds : Int32 = Time.utc.second
@blend : Bool = false
def initialize
@window = SDL::Window.new(window_title(59.7), WIDTH * SCALE, HEIGHT * SCALE, flags: SDL::Window::Flags::OPENGL)
setup_gl
@ -22,6 +24,15 @@ class Display
update_draw_count
end
def toggle_blending : Nil
if @blend
LibGL.disable(LibGL::BLEND)
else
LibGL.enable(LibGL::BLEND)
end
@blend = !@blend
end
private def window_title(fps : Float) : String
"crab - #{fps.round(1)} fps"
end
@ -79,6 +90,8 @@ class Display
puts "OpenGL version: #{String.new(LibGL.get_string(LibGL::VERSION))}"
puts "Shader language version: #{String.new(LibGL.get_string(LibGL::SHADING_LANGUAGE_VERSION))}"
LibGL.blend_func(LibGL::SRC_ALPHA, LibGL::ONE_MINUS_SRC_ALPHA)
vert_shader_id = compile_shader(File.read("src/crab/shaders/gba_colors.vert"), LibGL::VERTEX_SHADER)
frag_shader_id = compile_shader(File.read("src/crab/shaders/gba_colors.frag"), LibGL::FRAGMENT_SHADER)

View file

@ -70,6 +70,7 @@ class Keypad
when .r? then @keyinput.r = bit
# Extras
when .tab? then @gba.apu.toggle_sync if event.pressed?
when .m? then @gba.display.toggle_blending if event.pressed?
else nil
end
when SDL::Event::JoyHat

View file

@ -15,5 +15,5 @@ void main() {
30 * color.b + 230 * color.g + 10 * color.r,
220 * color.b + 10 * color.g + 50 * color.r) / 255,
vec3(1.0 / outGamma));
frag_color.a = 1.0;
frag_color.a = 0.5;
}