The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Device orientation quirks on Android
ggambetta


Joined: 01 Oct 2014
Posts: 2
I'm back after a looong time (remember http://www.mysterystudio.com? Yeah, didn't think so). It's amazing to see how much things have improved in the last few years Smile SDL2 is fantastic. I ported my game framework to SDL2 and made it run without problems on Linux, OSX and iOS.

Now Android, pretty much working, except screen orientation. I have this game with "screens", some are portrait, some are landscape. The user isn't supposed to control this, but to physically rotate the device when the game shows a landscape screen.

I managed to force the orientation on iOS using SDL_HINT_ORIENTATIONS and calling SDL_CreateWindow() again. However, the same code doesn't work on Android:

- If I set android:configChanges="orientation" and I rotate the device, it freezes (and practically freezes the phone), and my forced orientation changes (Hint + SDL_CreateWindow()) do nothing.

- If I set it to "orientation|screenSize" my forced changes still don't work, and when I physically rotate the device, I get a smooth screen rotation (and the phone doesn't freeze). This is also not what I want.

So... what would be the correct way to have this behavior? I'd be surprised if it hadn't been done before. FWIW, I'm not using OpenGL, just SDL calls.

Thanks,
--Gabriel
ggambetta


Joined: 01 Oct 2014
Posts: 2
So I fixed this, sort of.

For the orientation, I set android:screenOrientation="portrait" in the manifest file. Then I call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) when I want to go landscape.

For the garbage in the letterboxing, I call SDL_RenderClear() before rendering and presenting with SDL_RenderPresent().

-----

I would argue SDL should do this. In fact, it does for iOS, so I don't see why Android shouldn't behave the same way - controlling the orientation with the hint, and clearing the buffer when the logical size of the renderer doesn't match the physical size of the window. Is it OK if I send patches?
Device orientation quirks on Android
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
Yes, please send patches! Smile

On Tue, Oct 7, 2014 at 5:52 AM, ggambetta wrote:
Quote:
So I fixed this, sort of.

For the orientation, I set android:screenOrientation="portrait" in the manifest file. Then I call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) when I want to go landscape.

For the garbage in the letterboxing, I call SDL_RenderClear() before rendering and presenting with SDL_RenderPresent().

-----

I would argue SDL should do this. In fact, it does for iOS, so I don't see why Android shouldn't behave the same way - controlling the orientation with the hint, and clearing the buffer when the logical size of the renderer doesn't match the physical size of the window. Is it OK if I send patches?


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Device orientation quirks on Android
Jeffrey Carpenter
Guest

Heya,

I would especially like to see a patch for the "garbage in the letterboxing" issue. This issue effects other platforms, too, i.e.: OS X.

Cheers,
Jeffrey Carpenter


On 2014/10/ 07, at 7:52, ggambetta wrote:

Quote:
So I fixed this, sort of.

For the orientation, I set android:screenOrientation="portrait" in the manifest file. Then I callsetRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) when I want to go landscape.

For the garbage in the letterboxing, I call SDL_RenderClear() before rendering and presenting withSDL_RenderPresent().

-----

I would argue SDL should do this. In fact, it does for iOS, so I don't see why Android shouldn't behave the same way - controlling the orientation with the hint, and clearing the buffer when the logical size of the renderer doesn't match the physical size of the window. Is it OK if I send patches?
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org