goxjs / glfw Goto Github PK
View Code? Open in Web Editor NEWGo cross-platform glfw library for creating an OpenGL context and receiving events.
License: MIT License
Go cross-platform glfw library for creating an OpenGL context and receiving events.
License: MIT License
I've named it goglfw
because I couldn't use the glfw
name under my github username namespace, and I wanted to indicate that it's somehow different from normal glfw
(i.e. it's a cross-platform package that works on desktop and in browser). However, despite the import path having base goglfw
, the package is typically renamed glfw
(import glfw ".../goglfw"
), which makes things confusing.
Move it under https://github.com/goxjs namespace and rename it to glfw
. So the new import path will be:
import "github.com/goxjs/glfw"
That'll solve both problems.
It appears that Open is unused by the package. I'm guessing you added it for font loading before they were embedded?
If it isn't required, removing it would also kill the dependency on "honnef.co/go/js/xhr".
c_glfw-logs.zip
$ go get -u github.com/goxjs/glfw
fatal error: error in backend: Segmented stacks do not support vararg functions.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /usr/bin/clang -I ../../go/src/github.com/go-gl/glfw/v3.3/glfw -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build507152346/b002=/tmp/go-build -gno-record-gcc-switches -funwind-tables -I $WORK/b002/ -g -O2 -D_GLFW_X11 -D_GNU_SOURCE -fsplit-stack -o $WORK/b002/_x003.o -c c_glfw.cgo2.c
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-11: note: diagnostic msg: /tmp/c_glfw-fa465c.c
clang-11: note: diagnostic msg: /tmp/c_glfw-fa465c.sh
clang-11: note: diagnostic msg:
Hello.
Caught this bug, while building your project:
Because of browser limitations (to avoid websites abusing the Fullscreen API), requesting to enter fullscreen mode can only be done successfully during user input event handlers.
Therefore, when glfw.CreateWindow
is called with fullscreen mode, we can only "schedule" the enter fullscreen request to occur at the next viable moment, which is when the user performs the next input event (mouse down, mouse up, keyboard down, or keyboard up events).
I'm not sure what can be done to improve this situation...
Relevant excerpt from #gopherjs channel on Gophers Slack:
[3:20 AM] shurcool: So I was working on https://github.com/google/gxui/pull/86 just now, rebased it against latest master, etc. I saw there was a new sample demo, a fullscreen/windowed switcher
[3:21 AM] shurcool: I tried to implement it for the browser-side GLFW using Fullscreen API (https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode)
Mozilla Developer Network
Using fullscreen mode
The fullscreen API provides an easy way for web content to be presented using the user's entire screen. This article provides information about using this API.
[3:21 AM] shurcool: but the problem is that browsers allow requesting to enter fullscreen mode only in user input callbacks.
[3:22 AM] shurcool: Now, the code to do that actually happens when the user clicks. But the problem is that due to goroutines, etc. it ends up being indirected and in reality it does not happen from the user click callback directly, and the browser fails the request. (edited)
[3:23 AM]
shurcool uploaded a file:
Pasted image at 2015-05-28, 3:23 AM
15KB PNG file • in #gopherjs • Add comment • Open original
[3:43 AM] shurcool: I wonder what's a good way to go about solving this.
[3:46 AM] neelance: you’ll need to call it directly inside of the click handler, without wrapping it into a goroutine
[3:48 AM] neelance: this is similar to the `event.preventDefault()` problem
[3:48 AM] neelance: you also can’t do that inside of a new goroutine, because then it’s too late
[11:23 AM] shurcool: Yeah, I have an idea now. When doing `glfw.CreateWindow(..., fullscreen)` it can just set a boolean flag "requestedFullscreen" to true and the very next user input handler can actually perform the browser request.
[11:53 AM] neelance: gl :simple_smile:
----- Today May 29th, 2015 -----
[9:55 PM] shurcool: Okay, partial success (and the success part is _really_ cool!)
[9:56 PM] shurcool: The sample I'm testing this with has a big button "make fullscreen". When you press it, it goes fullscreen, and then the button becomes "make windowed".
[9:56 PM] shurcool: There are 2 ways to press the button. Focus it and press Enter or Space.
[9:56 PM] shurcool: When that key is pressed down (keydown event), it triggers.
[9:57 PM] shurcool: I've added my `if requestedFullscreen` checks into "keydown" and "keyup" listener events, and when you **release the key**, it catches that and goes fullscreen.
[9:57 PM] shurcool: So that part works, and it's awesome!
[9:57 PM] shurcool: But sadly, clicking with mouse is problematic.
[9:57 PM] shurcool: To trigger the button with mouse in gxui, you need to press mouse button and release the mouse button. It triggers on mouse button release event.
[9:58 PM] shurcool: The problem is that the browser "mouseup" event triggers event processing in gxui via goroutines, etc. and by the time it does glfw.CreateWindow(fullscreen) - "mouseup" has already finished earlier.
[9:59 PM] shurcool: So if the user presses the gxui button with mouse and waits - nothing happens. It will only go fullscreen the next time they click mouse or press key or do any "user event".
[9:59 PM] shurcool: :confused:
[10:01 PM]
shurcool uploaded a file:
Fullscreen gxui sample working in browser via GopherJS and Fullscreen API.
10KB PNG file • in #gopherjs • Add comment • Open original
[10:19 PM] shurcool: I think this is the best I can do for now, so that's how it'll be... if anyone can think of a way to improve it (or if I think of something later), that'd be great!
This issue is to discuss the difference, and possible reconciliation, between mouse scrolling on different platforms and browsers.
Relevant code: https://github.com/goxjs/glfw/blob/master/browser.go#L234
When run on desktop, the scroll wheel has a delta of 1 per tick in my experience. When run in the browser I experience a delta of 10 per tick. It seems that the tick value also varies by browser according to:
http://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers
Looking into it further, it appears my browser actually uses 120 per tick. http://phrogz.net/js/wheeldelta.html
Given the ideal of a single piece of code being able to run in the same fashion on both desktop and canvas, I suggest scroll wheel ticks be normalized to a delta of 1 per tick.
Possible solutions:
In the stack overflow link above, the top suggestion of simplifying the delta to -1, 0, or 1 seems reasonable at a glance, but based on comments it seems there are issues with different hardware like track pads that also uses the wheel event. It would also limit extremely fast scrolling to one tick per callback. I tested how often this might occur by spinning my mouse wheel as fast as I could manage while recording events in the chrome dev console. The most concentrated snippet of multiple events was:
14 syscall.go:43 http:0: got scroll event: 0 -10
syscall.go:43 http:0: got scroll event: 0 -20
35 syscall.go:43 http:0: got scroll event: 0 -10
syscall.go:43 http:0: got scroll event: 0 -20
39 syscall.go:43 http:0: got scroll event: 0 -10
syscall.go:43 http:0: got scroll event: 0 -20
6 syscall.go:43 http:0: got scroll event: 0 -10
syscall.go:43 http:0: got scroll event: 0 -20
32 syscall.go:43 http:0: got scroll event: 0 -10
The number of events with multiple mouse wheel ticks in a single callback is relatively small. It isn't negligible though.
Per browser support. Infeasible unless there's list that can be automatically kept up to date and imported statically.
http://stackoverflow.com/a/30134826/3184079
Facebook published a solution licensed under BSD-3. Many of the stackoverflow comments recommend it, and it could be translated to Go without difficulty.
https://github.com/facebook/fixed-data-table/blob/master/src/vendor_upstream/dom/normalizeWheel.js
Keep track of the smallest delta seen, and divide all others by its absolute value. Simple, but I don't know if it works in all cases.
I'm going to sleep on this and give it more thought.
This issue is to discuss how to think about and how to map the GLFW desktop concepts such as windows, resizing, monitors, fullscreen mode, etc., in the context of a browser. It resumes the discussion started in #8.
Modern browsers implement the Page Visibility API which emits an event visibilitychange
when a browser page is either hidden or made visible. The current visibility of a page can be found via document.hidden
.
This can be used to implement the focus callback in the browser:
document.addEventListener('visibilitychange', (e) => focusCB(!document.hidden));
In comparison to the high level discussion of handling mouse wheel events in #10 this issue is to look into specific instances of wheel event behavior.
The basic issue is that mouse "wheel" events provide extremely different delta values on different systems. At minimum browser, OS, and hardware are likely to play a role. For example, on Chrome+Win10, each step of a mouse scroll wheel results in a wheel event with delta value 120. On Firefox+Win10 the delta is 3.
The values goxjs/glfw is getting can be found manually for your system in the web console of:
https://dmitri.shuralyov.com/projects/touch/scroll.html
To see the base values that the system is sending to the browser, use gopherjs serve
and navigate to:
http://localhost:8080/github.com/goxjs/glfw/test/events/
A list of some values can be found here:
http://stackoverflow.com/q/5527601/3184079
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.