Skip to content
This repository was archived by the owner on Apr 28, 2021. It is now read-only.

Commit e899213

Browse files
authored
add fullscreen option (#44)
* add fullscreen option * use propper GLFW version for fullscreen * try to fix travis * don't test fullscreen on headless system * remove code
1 parent 4f3eaeb commit e899213

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
language: julia
2-
os:
3-
- linux
4-
dist: trusty
52
julia:
63
- 0.6
74
- nightly
85
notifications:
96
email: false
7+
os:
8+
- linux
9+
- osx
10+
dist: trusty
11+
sudo: false
1012
addons:
1113
apt:
1214
packages:

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ FixedPointNumbers 0.3.0
88
ColorTypes 0.3.1
99
StaticArrays # FieldVector
1010

11-
GLFW
11+
GLFW 1.4.0 # version with fullscreen support
1212
FileIO

src/screen.jl

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ function standard_window_hints()
162162
(GLFW.AUX_BUFFERS, 0)
163163
]
164164
end
165+
166+
167+
full_screen_usage_message() = """
168+
Keyword arg fullscreen accepts:
169+
Integer: The number of the Monitor to Select
170+
Bool: if true, primary monitor gets fullscreen, false no fullscren (default)
171+
GLFW.Monitor: Fullscreens on the passed monitor
172+
"""
173+
165174
"""
166175
Function to create a pure GLFW OpenGL window
167176
"""
@@ -174,7 +183,8 @@ function create_glcontext(
174183
windowhints = standard_window_hints(),
175184
contexthints = standard_context_hints(major, minor),
176185
visible = true,
177-
focus = false
186+
focus = false,
187+
fullscreen = false
178188
)
179189
# we create a new context, so we need to clear the shader cache.
180190
# TODO, cache shaders in GLAbstraction per GL context
@@ -195,7 +205,30 @@ function create_glcontext(
195205
end
196206
end
197207
GLFW.WindowHint(GLFW.OPENGL_DEBUG_CONTEXT, Cint(debugging))
208+
monitor = if fullscreen != nothing
209+
if isa(fullscreen, GLFW.Monitor)
210+
monitor
211+
elseif isa(fullscreen, Bool)
212+
fullscreen ? GLFW.GetPrimaryMonitor() : GLFW.Monitor(C_NULL)
213+
elseif isa(fullscreen, Integer)
214+
GLFW.GetMonitors()[fullscreen]
215+
216+
else
217+
error(string(
218+
"Usage Error. Keyword argument fullscreen has value: $fullscreen.\n",
219+
full_screen_usage_message()
220+
))
221+
end
222+
else
223+
GLFW.Monitor(C_NULL)
224+
end
198225
window = GLFW.CreateWindow(resolution..., String(name))
226+
if monitor != GLFW.Monitor(C_NULL)
227+
GLFW.SetKeyCallback(window, (_1, button, _2, _3, _4) -> begin
228+
button == GLFW.KEY_ESCAPE && GLWindow.make_windowed!(window)
229+
end)
230+
GLWindow.make_fullscreen!(window)
231+
end
199232
GLFW.MakeContextCurrent(window)
200233
# tell GLAbstraction that we created a new context.
201234
# This is important for resource tracking
@@ -205,6 +238,19 @@ function create_glcontext(
205238
window
206239
end
207240

241+
make_fullscreen!(screen::Screen, monitor::GLFW.Monitor = GLFW.GetPrimaryMonitor()) = make_fullscreen!(nativewindow(screen), monitor)
242+
function make_fullscreen!(window::GLFW.Window, monitor::GLFW.Monitor = GLFW.GetPrimaryMonitor())
243+
vidmodes = GLFW.GetVideoModes(monitor)[end]
244+
GLFW.SetWindowMonitor(window, monitor, 0, 0, vidmodes.width, vidmodes.height, GLFW.DONT_CARE)
245+
return
246+
end
247+
248+
make_windowed!(screen::Screen) = make_windowed!(nativewindow(screen))
249+
function make_windowed!(window::GLFW.Window)
250+
width, height = standard_screen_resolution()
251+
GLFW.SetWindowMonitor(window, GLFW.Monitor(C_NULL), 0, 0, width, height, GLFW.DONT_CARE)
252+
return
253+
end
208254

209255
"""
210256
Most basic Screen constructor, which is usually used to create a parent screen.
@@ -230,7 +276,8 @@ function Screen(name = "GLWindow";
230276
stroke = (0f0, color),
231277
hidden = false,
232278
visible = true,
233-
focus = false
279+
focus = false,
280+
fullscreen = false
234281
)
235282
# create glcontext
236283

@@ -239,7 +286,8 @@ function Screen(name = "GLWindow";
239286
resolution = resolution, debugging = debugging,
240287
major = major, minor = minor,
241288
windowhints = windowhints, contexthints=contexthints,
242-
visible = visible, focus = focus
289+
visible = visible, focus = focus,
290+
fullscreen = fullscreen
243291
)
244292
#create standard signals
245293
signal_dict = register_callbacks(window, callbacks)

0 commit comments

Comments
 (0)