From 3c731d814cee2d40fdaeb2477a72aa0d890863b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Thu, 14 Jul 2016 02:44:19 +0900 Subject: [PATCH 1/3] Implement fullscreen toggle. --- modules/graphics/mrblib/screen.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/graphics/mrblib/screen.rb b/modules/graphics/mrblib/screen.rb index d69d205..bba797a 100644 --- a/modules/graphics/mrblib/screen.rb +++ b/modules/graphics/mrblib/screen.rb @@ -21,13 +21,15 @@ class Screen # # @param [Integer] w # @param [Integer] h - def initialize(w, h) + # @param [Boolean] fullscreen + def initialize(w, h, fullscreen = true) @scale = 1.0 @logger = Moon::ContextLogger.new(STDERR, 'Screen') + @fullscreen = fullscreen create_window w, h initialize_renderer initialize_clear_color - initialize_screen_size + initialize_screen_size if !fullscreen? @vsync = true end @@ -35,6 +37,7 @@ def initialize(w, h) # # @param [Integer] w width of the window # @param [Integer] h height of the window + # @param [Boolean] fullscreen def create_window(w, h) @logger.debug "Creating Window: w=#{w} h=#{h}" GLFW.window_hint GLFW::RESIZABLE, GL2::GL_FALSE @@ -44,9 +47,11 @@ def create_window(w, h) GLFW.window_hint GLFW::OPENGL_PROFILE, GLFW::OPENGL_CORE_PROFILE # for 3.0 and on Moon::Shader.is_legacy = false + monitor = GLFW.primary_monitor if fullscreen? + title = 'Moon Player' begin - @window = GLFW::Window.new w, h, title + @window = GLFW::Window.new w, h, title, monitor @logger.warn "3.3 Window Created" rescue GLFWError @logger.warn "Failed to obtain 3.3 context, falling back to 2.1" @@ -55,7 +60,7 @@ def create_window(w, h) GLFW.window_hint GLFW::CONTEXT_VERSION_MINOR, 1 Moon::Shader.is_legacy = true - @window = GLFW::Window.new w, h, title + @window = GLFW::Window.new w, h, title, monitor @logger.warn "2.1 Window Created" end end @@ -99,6 +104,11 @@ def should_close? @window.should_close? end + # Is the window currently fullscreen? + def fullscreen? + @fullscreen + end + # Swaps buffers, call this once per frame def swap @window.swap_buffers From 8ccfcdb673933d7d3343eaf54ed1da92851438ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Thu, 14 Jul 2016 11:49:10 +0900 Subject: [PATCH 2/3] Make the window size same as screen resolution. --- modules/graphics/mrblib/screen.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/graphics/mrblib/screen.rb b/modules/graphics/mrblib/screen.rb index bba797a..816d4d0 100644 --- a/modules/graphics/mrblib/screen.rb +++ b/modules/graphics/mrblib/screen.rb @@ -29,7 +29,7 @@ def initialize(w, h, fullscreen = true) create_window w, h initialize_renderer initialize_clear_color - initialize_screen_size if !fullscreen? + initialize_screen_size #if !fullscreen? @vsync = true end @@ -47,7 +47,12 @@ def create_window(w, h) GLFW.window_hint GLFW::OPENGL_PROFILE, GLFW::OPENGL_CORE_PROFILE # for 3.0 and on Moon::Shader.is_legacy = false - monitor = GLFW.primary_monitor if fullscreen? + if fullscreen? + monitor = GLFW.primary_monitor + vid_mode = monitor.vid_mode + w = vid_mode.width + h = vid_mode.height + end title = 'Moon Player' begin From efbc7b5587c8cfcb24a66a9ae31a989d0c4e9eec Mon Sep 17 00:00:00 2001 From: IceDragon200 Date: Thu, 14 Jul 2016 16:04:26 -0500 Subject: [PATCH 3/3] Added logging to Screen fullscreen init --- modules/graphics/mrblib/screen.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/graphics/mrblib/screen.rb b/modules/graphics/mrblib/screen.rb index 816d4d0..1e7153b 100644 --- a/modules/graphics/mrblib/screen.rb +++ b/modules/graphics/mrblib/screen.rb @@ -48,10 +48,12 @@ def create_window(w, h) Moon::Shader.is_legacy = false if fullscreen? + @logger.debug "Fullscreen Window requested" monitor = GLFW.primary_monitor vid_mode = monitor.vid_mode w = vid_mode.width h = vid_mode.height + @logger.debug "New Window Size: w=#{w} h=#{h}" end title = 'Moon Player'