-
Notifications
You must be signed in to change notification settings - Fork 35
Added GLFW specific functionality from GLWindow.jl #118
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f3a3b2c
Added GLFW specific functionality from GLWindow.jl
louisponet d9d79fa
Changed to put everything in glfw3.jl
louisponet be8b95a
Changed Vectors to NTuples to mimic previous Vec behaviour
louisponet 60ccda5
Went through requested changes.
louisponet 6d9e01f
Merge branch 'master' into pull-request/f3a3b2ce
jayschwa 65c04f8
Merge branch 'master' into pull-request/f3a3b2ce
jayschwa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| deps/* | ||
| !deps/build.jl | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -274,11 +274,97 @@ mutable struct Window | |
| callbacks::Vector{Function} | ||
| end | ||
| Window(handle::WindowHandle) = Window(handle, Vector{Function}(_window_callbacks_len[])) | ||
| #Came from GLWindow.jl/screen.jl | ||
| """ | ||
| Function to create a pure GLFW OpenGL window | ||
| """ | ||
| function Window( | ||
| name = "GLWindow"; | ||
| resolution = standard_screen_resolution(), | ||
| debugging = false, | ||
| major = 3, | ||
| minor = 3,# this is what GLVisualize needs to offer all features | ||
| windowhints = standard_window_hints(), | ||
| contexthints = standard_context_hints(major, minor), | ||
| visible = true, | ||
| focus = false, | ||
| fullscreen = false, | ||
| monitor = nothing | ||
| ) | ||
| WindowHint(VISIBLE, visible) | ||
| WindowHint(FOCUSED, focus) | ||
| for ch in contexthints | ||
| WindowHint(ch[1], ch[2]) | ||
| end | ||
| for wh in windowhints | ||
| WindowHint(wh[1], wh[2]) | ||
| end | ||
|
|
||
| @static if is_apple() | ||
| if debugging | ||
| warn("OpenGL debug message callback not available on osx") | ||
| debugging = false | ||
| end | ||
| end | ||
|
|
||
| WindowHint(OPENGL_DEBUG_CONTEXT, Cint(debugging)) | ||
|
|
||
| monitor = if monitor == nothing | ||
| GetPrimaryMonitor() | ||
| elseif isa(monitor, Integer) | ||
| GetMonitors()[monitor] | ||
| elseif isa(monitor, Monitor) | ||
| monitor | ||
| else | ||
| error("Monitor needs to be nothing, int, or GLFW.Monitor. Found: $monitor") | ||
| end | ||
|
|
||
| window = CreateWindow(resolution..., String(name)) | ||
|
|
||
| if fullscreen | ||
| SetKeyCallback(window, (_1, button, _2, _3, _4) -> begin | ||
| button == KEY_ESCAPE && make_windowed!(window) | ||
| end) | ||
| make_fullscreen!(window, monitor) | ||
| end | ||
|
|
||
| MakeContextCurrent(window) | ||
|
|
||
| window | ||
| end | ||
|
|
||
|
|
||
| import Base.==; ==(x::Window, y::Window) = (x.handle == y.handle) | ||
| Base.cconvert(::Type{WindowHandle}, window::Window) = window.handle | ||
| Base.cconvert(::Type{Window}, handle::WindowHandle) = ccall( (:glfwGetWindowUserPointer, lib), Ref{Window}, (WindowHandle,), handle) | ||
| Base.hash(window::Window, h::UInt64) = hash(window.handle, h) | ||
|
|
||
|
|
||
| function make_windowed!(window::Window) | ||
| width, height = standard_screen_resolution() | ||
| SetWindowMonitor(window, Monitor(C_NULL), 0, 0, width, height, DONT_CARE) | ||
| return | ||
| end | ||
|
|
||
| function make_fullscreen!(window::Window, monitor::Monitor = GetPrimaryMonitor()) | ||
| vidmodes = GetVideoModes(monitor)[end] | ||
| SetWindowMonitor(window, monitor, 0, 0, vidmodes.width, vidmodes.height, GLFW.DONT_CARE) | ||
| return | ||
| end | ||
|
|
||
| """ | ||
| Sets visibility of OpenGL window. Will still render if not visible. | ||
| Only applies to the root screen holding the opengl context. | ||
| """ | ||
| function set_visibility!(screen::Window, visible::Bool) | ||
| if visible | ||
| ShowWindow(screen) | ||
| else !visible | ||
| HideWindow(screen) | ||
| end | ||
| return | ||
| end | ||
|
|
||
| struct Cursor | ||
| handle::Ptr{Void} | ||
| end | ||
|
|
@@ -298,6 +384,39 @@ struct GLFWError <: Exception | |
| end | ||
| Base.showerror(io::IO, e::GLFWError) = print(io, "GLFWError ($(e.code)): ", e.description) | ||
|
|
||
| #Came from GLWindow.jl/types.jl | ||
| struct MonitorProperties | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| name::String | ||
| isprimary::Bool | ||
| position::NTuple{2, Int} | ||
| physicalsize::NTuple{2, Int} | ||
| videomode::VidMode | ||
| videomode_supported::Vector{VidMode} | ||
| dpi::NTuple{2, Float64} | ||
| monitor::Monitor | ||
| end | ||
|
|
||
| function MonitorProperties(monitor::Monitor) | ||
| name = GetMonitorName(monitor) | ||
| isprimary = GetPrimaryMonitor() == monitor | ||
| position = GetMonitorPos(monitor) | ||
| physicalsize = GetMonitorPhysicalSize(monitor) | ||
| videomode = GetVideoMode(monitor) | ||
| sfactor = is_apple() ? 2.0 : 1.0 | ||
| dpi = (videomode.width * 25.4, videomode.height * 25.4) * sfactor ./ physicalsize | ||
| videomode_supported = GetVideoModes(monitor) | ||
|
|
||
| MonitorProperties(name, isprimary, position, physicalsize, videomode, videomode_supported, dpi, monitor) | ||
| end | ||
|
|
||
| #Came from GLWindow/core.jl | ||
| function Base.show(io::IO, m::MonitorProperties) | ||
| println(io, "name: ", m.name) | ||
| println(io, "physicalsize: ", m.physicalsize[1], "x", m.physicalsize[2]) | ||
| println(io, "resolution: ", m.videomode.width, "x", m.videomode.height) | ||
| println(io, "dpi: ", m.dpi[1], "x", m.dpi[2]) | ||
| end | ||
|
|
||
| #************************************************************************ | ||
| # GLFW API functions | ||
| #************************************************************************ | ||
|
|
@@ -473,3 +592,69 @@ GetProcAddress(procname::AbstractString) = ccall((:glfwGetProcAddress, lib), Ptr | |
| function SetWindowMonitor(window::Window, monitor::Monitor, xpos, ypos, width, height, refreshRate) | ||
| ccall((:glfwSetWindowMonitor, lib), Void, (WindowHandle, Monitor, Cint, Cint, Cint, Cint, Cint), window, monitor, xpos, ypos, width, height, refreshRate) | ||
| end | ||
|
|
||
| #came from GLWindow/core.jl | ||
| """ | ||
| Returns the monitor resolution of the primary monitor. | ||
| """ | ||
| function primarymonitorresolution() | ||
| props = MonitorProperties(GetPrimaryMonitor()) | ||
| w,h = props.videomode.width, props.videomode.height | ||
| # Vec(Int(w),Int(h)) | ||
| (Int(w),Int(h)) | ||
| end | ||
|
|
||
| #Came from GLWindow.jl/screen.jl | ||
|
|
||
| """ | ||
| Takes half the resolution of the primary monitor. | ||
| This should make for sensible defaults! | ||
| """ | ||
| function standard_screen_resolution() | ||
| w, h = primarymonitorresolution() | ||
| (div(w,2), div(h,2)) # half of total resolution seems like a good fit! | ||
| end | ||
|
|
||
|
|
||
| """ | ||
| Tries to create sensible context hints! | ||
| Taken from lessons learned at: | ||
| [GLFW](http://www.glfw.org/docs/latest/window.html) | ||
| """ | ||
| function standard_context_hints(major, minor) | ||
| # this is spaar...Modern OpenGL !!!! | ||
| major < 3 && error("OpenGL major needs to be at least 3.0. Given: $major") | ||
| # core profile is only supported for OpenGL 3.2+ (and a must for OSX, so | ||
| # for the sake of homogenity, we try to default to it for everyone!) | ||
| if (major > 3 || (major == 3 && minor >= 2 )) | ||
| profile = OPENGL_CORE_PROFILE | ||
| else | ||
| profile = OPENGL_ANY_PROFILE | ||
| end | ||
| [ | ||
| (CONTEXT_VERSION_MAJOR, major), | ||
| (CONTEXT_VERSION_MINOR, minor), | ||
| (OPENGL_FORWARD_COMPAT, Cint(1)), | ||
| (OPENGL_PROFILE, profile) | ||
| ] | ||
| end | ||
|
|
||
|
|
||
| """ | ||
| Standard window hints for creating a plain context without any multisampling | ||
| or extra buffers beside the color buffer | ||
| """ | ||
| function standard_window_hints() | ||
| [ | ||
| (SAMPLES, 0), | ||
| (DEPTH_BITS, 0), | ||
|
|
||
| (ALPHA_BITS, 8), | ||
| (RED_BITS, 8), | ||
| (GREEN_BITS, 8), | ||
| (BLUE_BITS, 8), | ||
|
|
||
| (STENCIL_BITS, 0), | ||
| (AUX_BUFFERS, 0) | ||
| ] | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this new line.