SDL2 Port

Nearly complete, playable SDL2 port is here.

  1. There are only a few changes required to switch to SDL2, but maintaining both 2.x and 1.x for current codebase is not that simple.

  2. As you can see there in nothing OpenGL related was directly involved during porting. (everything is hidden in depth of SDL)

  3. It possible to gradually implement some OGL related features. (No need to switch to full HW acceleration at once.)

So what about to switch to SDL2? How long backward compatibility should be retained? Should we introduce HW accelerated features until SDL 1.x compatibility is retained (in SDL 1.x it is impossible to mix SW & HR rendering as I understand)?

Will take a closer look on this tomorrow. Can you create pull request on github? There are some possible issues that will come from this change (like possibly fixed 1.2 bugs or unicode input).

Personally I’d like to have switch as soon as possible. From what I see in Linux zoo:
Gentoo - only available as “unstable” on AMD64/x86?
Debian - SDL ttf is missing and will only be available in next stable (~1 year till release), everything else seems to be in place.
Fedora, Arch, Ubuntu - looks to be ready.

Can you make SDL ttf optional? Just put #ifdef NO_SDL_TTF that will be set via build system when necessary and I think we’re fine on Debian.
Gentoo is usually fast with updates so I think we can remove 1.2 support after next release. Or even earlier if sdl2 status here will change.

IIRC both Android and Mac maintainers (stoppicot/xyz) were in favor of such switch so these platforms should be OK as well.

unicode input is still missing, hope to implement it tomorrow (as for now text input is entirely disabled). Music is broken but other sound works. Also there is problem with alpha channel on some graphics(battle obstacles). No more regressions on the first look.
P.S. Pull req. ready.

I’m not sure I’ve ever said anything like that, the current Android port is based on work by pelya which is a port of SDL 1.2 and 1.3 plus Android-related goodies (like ten different ways to do touch input, support for stuff like samsung’s stylus or air view).

Ah, sorry - we had too many Android mainteners. I was referring to this discussion with gerstrong:

So what’s current status of SDL2 on Android? It seems that we can keep 1.2 compatibility at least for now so there will be time for transition but sooner or later we’ll have to abandon 1.2 support.

It should work on Android fine but there’s very little documentation and I’ll probably have to reimplement input (and maybe other things).

OpenGL backend kinda fixed. The cost was broken hero movement animation. (render loop merged into event loop in main thread). It is possible to use OpenGL with multithreading (with some special code additions) but built-in SDL2 2d renderer does not support that.

I checkout the sources from sdl2 branch(
but fail to run the vcmi_client. the error is vector out-of-range

if ((ret->town->primaryRes != Res::WOOD) && (ret->town->primaryRes != Res::ORE) && (ret->town->primaryRes != Res::GOLD))
ret->produce[ret->town->primaryRes] = 1;
This line throws the exception. produce.size()==8 while ret->town->primaryRes==127

After finding the definations below, i change the produce’s size to 128, failing to run the client.
enum ERes

	**WOOD_AND_ORE = 127 // special case for town bonus resource**

Does anyone find this problem too?
my env: win7 + vs2013 express + boost-1.55.0

more info: with the same game data, the offcial 0.95 release works fine.


Likely caused by town buildings change, unrelated to SDL2.

Proper fix here would be replacing code in CTownHandler with such behavior:

if (Res::WOOD_AND_ORE)
    produced[ore] = 1
    produced[wood] = 1

Will take a closer look on it in a few days.

Does “same data” includes configs? Files from “config” directory should always be in sync with code.

Thank you.
With your new code and “config” in the repo. It works now(built with SDL1.2)
Now I’m trying to build the projects with SDL2 and will report the result later.

Source of bug is macron1`s patch ( The code is for backward compatibility and used only with “old” mods, thats why the bug has not been caught yet.

Hero movement rendering is fixed :exclamation: Few transparency related issues remains.

Thank you for your efforts.
I sync the sources and find that the .vcxproj files are broken. I have trouble in building the projects with VS2013 express.
Are you building vcmi-sdl2 with other tools?

for example, there is an item in VCMI_Lib.vxproj, while the .cpp has been moved into .\mapObjects

Thank you.

Indeed Visual files are out of sync. In fact i have set them to “ignore on commit” mode and use only my own config. the thing is, no other active developer used Visual recently.

Feel free to fix that :wink:

Yes I am. I`m using Code::Blocks with MinGW toolchain.

I manage to complie the projects and play the game.
It’s cool, though it really takes me some days to work with CB+MinGW.
The wiki recommended VS2013 on Windows.
Will anybody update “How to build VCMI (Windows)”?

I find that the branch of SDL2 port on git has been removed. What’s the matter?

As far as I understand it was merged into master (develop) branch, so there is no need to use any other branches.