Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen: Fullscreen support #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions modules/graphics/mrblib/screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ 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

# Creates the internal window
#
# @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
Expand All @@ -44,9 +47,18 @@ 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

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'
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"
Expand All @@ -55,7 +67,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
Expand Down Expand Up @@ -99,6 +111,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
Expand Down