SDL port - how to use SDL_SetWindowFullscreen properly?

221 views
Skip to first unread message

Nick Weihs

unread,
Sep 7, 2017, 6:53:21 PM9/7/17
to emscripten-discuss
So I have a button in my game that is supposed to make the game go full screen.  My engine uses requestAnimationFrame via emscripten_set_main_loop, and inside it calls SDL_PollEvent() to get events for mouse presses and everything else.  So when I detect a mouse press on my button, I call SDL_SetWindowFullscreen() and I'm seeing some very strange behavior. The game starts to render as if it was full screen, but the size of the element on the page doesn't change UNTIL I press the mouse button again.

Under the hood, SDL_SetWindowFullscreen() calls the HTML5 function requestFullscreen -

In the documentation for that function it says a fullscreen request can be denied if it is called from outside of an event handler, and I don't think that requestAnimationFrame qualifies.

So my question is - how do properly call SDL_SetWindowFullscreen() from within the actual event handler from the mouse button press event or any other event?  I've tried using SDL_AddEventWatch() but that doesn't seem to work either.

Jukka Jylänki

unread,
Sep 11, 2017, 9:39:26 AM9/11/17
to emscripte...@googlegroups.com
Unfortunately the SDL API does not have a design that would allow
doing this from within SDL code. The best closest behavior you can get
with SDL API is the "deferred" behavior of fullscreen happening the
next time you click on the canvas. This deferring behavior has been
explicitly created as a workaround fallback to make existing apps work
as close to possible.

If you want to fix the behavior proper, you will need to register
HTML5 event callback handler (from html5.h) to one of the input
events, and use the HTML5 fullscreen API from there. That will
immediately give fullscreen mode to appear without deferring.

It would be possible to add mixed support to calling
SDL_SetWindowFullscreen() from a html5.h-based event handler callback,
but currently I think that does not work. There was a bug report or an
emscripten-discuss thread about this mixed
html5.h+SDL_SetWindowFullscreen() but can't find it with some
searching now. Basically one will need to hack SDL API to understand
that it's ok to do fullscreen requests from within HTML5 event
handlers, it's currently not aware of them.
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to emscripten-disc...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages