Skip to content
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

SDL2 Support #36

Merged
merged 4 commits into from Jun 20, 2015

Conversation

@murlock
Copy link
Contributor

commented Jun 17, 2015

Please found a SDL2 support for Ivan.

SDL1.2 is still supported and will be used as fallback if SDL2 is not detected.

What is missing :

  • Test on BIG_ENDIAN computer because I left empty function for SDL2 (will try to test with my PI2 later)
  • Complete test of keyboard (low level event (backspace, escape, ...) and high level event are managed differently : check https://wiki.libsdl.org/MigrationGuide#Input)
murlock added 4 commits Jun 12, 2015
Keyboard is now fully functional : in SDL2, there is now two
events SDL_KEYDOWN for raw input and SDL_TEXTINPUT for current
language : implicit events must be explicited in SDL_KEYDOWN (found
SDLK_ESCAPE and SDLK_BASCKPACE at this time)
Quick hack to detect first SDL2 and in case of error
fallback to SDL1.2. Not happy with this patch but at least
it works.
@emlai

This comment has been minimized.

Copy link
Member

commented Jun 18, 2015

Awesome! I tested it and noticed a few things:

  • Fullscreen mode on my system now makes the game run blazingly fast, so fast that all actions that take time (rest, go, etc.) feel almost instantaneous, with little sense of time passing by.

    To prevent this, we could add a SDL_Delay(10) inside the graphics rendering loop, but I'm not sure if this is the best solution. Any ideas?

  • The game is now stretched to fit the entire screen (instead of letterboxing), e.g. with my display the width of the game tiles is greater than their height, which looks weird.
    Also by default SDL2 uses nearest neighbor scaling which doesn't look so good either.
    There's also some weird glitch in the menu when I launch the game. I took some screenshots to demonstrate these, you can find them here.

    I then tried using SDL_WINDOW_FULLSCREEN (the "real" fullscreen mode) instead of SDL_WINDOW_FULLSCREEN_DESKTOP for the fullscreen mode, and all of the above problems went away.
    Also it produces nicer scaling results on my system compared to SDL_WINDOW_FULLSCREEN_DESKTOP, even if we switch to linear interpolation. Here's a patch with the changes.

@murlock

This comment has been minimized.

Copy link
Contributor Author

commented Jun 19, 2015

I'll do more test more in fullscreen for speed issue, but I think SDL_Delay is required.

Regarding SDL_WINDOW_FULLSCREEN_DESKTOP, I'll test with SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear") for quality.
For ratio issue, I'll give a look in SDL API, I may have missed something.

Regarding issue with full screen, I've met same issue when switching windowed/full screen and I tough that calling BlitDBToScreen will be ok.

Otherwise, it is ok for your patch.

@emlai

This comment has been minimized.

Copy link
Member

commented Jun 19, 2015

@murlock Found a fix for the ratio issue: SDL_RenderSetLogicalSize.

@emlai

This comment has been minimized.

Copy link
Member

commented Jun 19, 2015

I also noticed that if we add SDL_WINDOW_ALLOW_HIGHDPI to the window flags in SDL2, SDL_WINDOW_FULLSCREEN_DESKTOP looks good on my display, with no need to blur the pixels with SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"). So I guess we won't need SDL_WINDOW_FULLSCREEN after all.

I made the changes in my branch, diff here. Now we only need to fix the menu glitch and the speed-up.

@murlock

This comment has been minimized.

Copy link
Contributor Author

commented Jun 19, 2015

Great :)

@emlai

This comment has been minimized.

Copy link
Member

commented Jun 19, 2015

Found the reason why the window was not being redrawn correctly when switching between windowed/fullscreen: apparently SDL_WINDOWEVENT_RESIZED needs to be handled on OS X. So that's fixed.

There's still a small related bug that shows a frame of the menu in its windowed size (as shown in my screenshots) for a split second just before rendering the fullscreen sized view correctly.
Also for some reason the fade-in effect doesn't show in fullscreen (in windowed mode it works correctly though). My guess is that there might be a superfluous BlitDBToScreen somewhere but I couldn't find anything yet. But this is quite minor, and could IMO also be fixed later.

I also found a couple of other minor bugs while bug-hunting. A patch for all of these can be found in the same diff I linked above.

@emlai

This comment has been minimized.

Copy link
Member

commented Jun 19, 2015

I realized that the scaled resolution with nearest neighbor interpolation only produced good results for me because my screen height is a multiple of IVAN's hardcoded screen height. So every in-game pixel occupies exactly 3x3 actual pixels on my screen.
Of course, for displays whose height is not a multiple of 600, using nearest neighbor interpolation would produce warped results.

To solve this, we could do a quick workaround: using linear interpolation as a fallback on displays whose height is not a multiple of 600 or width not a multiple of 800.
Maybe at some point we can then make something clever to scale and letterbox the game appropriately to get nice sharp unwarped pixel art graphics at all resolutions >= 800x600, if we want.

Here's the code that does the check. It should work, let me know if it doesn't.

fejoa added a commit that referenced this pull request Jun 20, 2015
@fejoa fejoa merged commit a8434f4 into Attnam:master Jun 20, 2015
@fejoa

This comment has been minimized.

Copy link
Member

commented Jun 21, 2015

Mugs like me might like to be aware of this glitch when using MinGW and gcc while implementing SDL2:
http://stackoverflow.com/questions/22446008/winapifamily-h-no-such-file-or-directory-when-compiling-sdl-in-codeblocks

fejoa added a commit that referenced this pull request Jun 22, 2015
 - Now supported by SDL 2.0, thanks to the diligent and valued programming effort of Michael Bonfils and Emil Laine
 - See pull requests below, for detailed changes:
#36
#37
#39
fejoa added a commit that referenced this pull request Jun 22, 2015
 - Now supported by SDL 2.0, thanks to the diligent and valued programming effort of Michael Bonfils and Emil Laine
 - See pull requests below, for detailed changes:
#36
#37
#39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.