SDL/WinRT layer allows SDL2-based applications to run on many of Microsoft's platforms that utilize the "Windows Runtime" (aka "WinRT") APIs. WinRT apps are currently always full-screen apps, run in what Microsoft calls their "Modern" environment (aka. "Metro"), and are distributed via Microsoft-run online stores. Some of the operating systems that support such apps include:
To note, WinRT applications that run on Windows 8.x and/or Windows RT are often called "Windows Store" apps.
The steps for setting up a project for an SDL/WinRT app looks like the following, at a high-level:
Create a new project using one of Visual C++'s templates for a plain, non-XAML, "Direct3D App" (XAML support for SDL/WinRT is not yet ready for use). If you don't see one of these templates, in Visual C++'s 'New Project' dialog, try using the textbox titled, 'Search Installed Templates' to look for one.
In the new project, delete any file that has one of the following extensions:
When you are done, you should be left with a few files, each of which will be a necessary part of your app's project. These files will consist of:
SDL/WinRT can be built in multiple variations, spanning across three different CPU architectures (x86, x64, and ARM) and two different configurations (Debug and Release). WinRT and Visual C++ do not currently provide a means for combining multiple variations of one library into a single file. Furthermore, it does not provide an easy means for copying pre-built .dll files into your app's final output (via Post-Build steps, for example). It does, however, provide a system whereby an app can reference the MSVC projects of libraries such that, when the app is built:
To set this up for SDL/WinRT, you'll need to run through the following steps:
VisualC-WinRT/WinPhone80_VS2012/ - for Windows Phone 8.0 appsVisualC-WinRT/WinPhone81_VS2013/ - for Windows Phone 8.1 appsVisualC-WinRT/WinRT80_VS2012/ - for Windows 8.0 appsVisualC-WinRT/WinRT81_VS2013/ - for Windows 8.1 appsYour project is now linked to SDL's project, insofar that when the app is built, SDL will be built as well, with its build output getting included with your app.
Some build settings need to be changed in your app's project. This guide will outline the following:
To change these settings:
C/C++-based WinRT apps do contain a main function that the OS will invoke when
the app starts launching. The parameters of WinRT main functions are different
than those found on other platforms, Win32 included. SDL/WinRT provides a
platform-appropriate main function that will perform these actions, setup key
portions of the app, then invoke a classic, C/C++-style main function (that take
in "argc" and "argv" parameters). The code for this file is contained inside
SDL's source distribution, under src/main/winrt/SDL_winrt_main_NonXAML.cpp.
You'll need to add this file, or a copy of it, to your app's project, and make
sure it gets compiled using a Microsoft-specific set of C++ extensions called
C++/CX.
NOTE: C++/CX compilation is currently required in at least one file of your app's project. This is to make sure that Visual C++'s linker builds a 'Windows Metadata' file (.winmd) for your app. Not doing so can lead to build errors.
To include SDL_winrt_main_NonXAML.cpp:
SDL_winrt_main_NonXAML.cpp, which is found inside SDL's source
distribution, under src/main/winrt/. Make sure that the open-file dialog
closes, either by double-clicking on the file, or single-clicking on it and
then clicking Add.At this point, you can add in SDL-specific source code. Be sure to include a
C-style main function (ie: int main(int argc, char *argv[])). From there you
should be able to create a single SDL_Window (WinRT apps can only have one
window, at present), as well as an SDL_Renderer. Direct3D will be used to
draw content. Events are received via SDL's usual event functions
(SDL_PollEvent, etc.) If you have a set of existing source files and assets,
you can start adding them to the project now. If not, or if you would like to
make sure that you're setup correctly, some short and simple sample code is
provided below.
If you are creating a new app (rather than porting an existing SDL-based app), or if you would just like a simple app to test SDL/WinRT with before trying to get existing code working, some working SDL/WinRT code is provided below. To set this up:
Copy and paste the following code into the new file (minus the , then save it.
#include <SDL.h>
int main(int argc, char **argv)
{
SDL_DisplayMode mode;
SDL_Window * window = NULL;
SDL_Renderer * renderer = NULL;
SDL_Event evt;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
return 1;
}
if (SDL_GetCurrentDisplayMode(0, &mode) != 0) {
return 1;
}
if (SDL_CreateWindowAndRenderer(mode.w, mode.h, SDL_WINDOW_FULLSCREEN, &window, &renderer) != 0) {
return 1;
}
while (1) {
while (SDL_PollEvent(&evt)) {
}
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
}
If you have existing code and assets that you'd like to add, you should be able to add them now. The process for adding a set of files is as such.
Do note that WinRT only supports a subset of the APIs that are available to Win32-based apps. Many portions of the Win32 API and the C runtime are not available.
A list of unsupported C APIs can be found at http://msdn.microsoft.com/en-us/library/windows/apps/jj606124.aspx
General information on using the C runtime in WinRT can be found at http://msdn.microsoft.com/en-us/LIBRARY/hh972425(v=vs.110).aspx
A list of supported Win32 APIs for Windows 8/RT apps can be found at
http://msdn.microsoft.com/en-us/library/windows/apps/br205757.aspx. To note,
the list of supported Win32 APIs for Windows Phone 8 development is different.
That list can be found at
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662956(v=vs.105).aspx
Your app project should now be setup, and you should be ready to build your app.
To run it on the local machine, open the Debug menu and choose "Start
Debugging". This will build your app, then run your app full-screen. To switch
out of your app, press the Windows key. Alternatively, you can choose to run
your app in a window. To do this, before building and running your app, find
the drop-down menu in Visual C++'s toolbar that says, "Local Machine". Expand
this by clicking on the arrow on the right side of the list, then click on
Simulator. Once you do that, any time you build and run the app, the app will
launch in window, rather than full-screen.
To build and run the app on ARM-based, "Windows RT" devices, you'll need to:
Microsoft's Remote Debugger can be found at http://msdn.microsoft.com/en-us/library/vstudio/bt727f1t.aspx. Please note that separate versions of this debugger exist for different versions of Visual C++, one for debugging with MSVC 2012, another for debugging with MSVC 2013.
To setup Visual C++ to launch your app on an ARM device: