docs/README-winrt.md
author Sam Lantinga <slouken@libsdl.org>
Fri, 07 Oct 2016 17:46:58 -0700
changeset 10486 5bf595c48fd4
parent 10171 5b61e12c0a30
child 10828 2160677a2f0f
permissions -rw-r--r--
Converted README documentation to DOS text format
slouken@10486
     1
WinRT
slouken@10486
     2
=====
slouken@10486
     3
slouken@10486
     4
This port allows SDL applications to run on Microsoft's platforms that require
slouken@10486
     5
use of "Windows Runtime", aka. "WinRT", APIs.  Microsoft may, in some cases,
slouken@10486
     6
refer to them as either "Windows Store", or for Windows 10, "UWP" apps.
slouken@10486
     7
slouken@10486
     8
Some of the operating systems that include WinRT, are:
slouken@10486
     9
slouken@10486
    10
* Windows 10, via its Universal Windows Platform (UWP) APIs
slouken@10486
    11
* Windows 8.x
slouken@10486
    12
* Windows RT 8.x (aka. Windows 8.x for ARM processors)
slouken@10486
    13
* Windows Phone 8.x
slouken@10486
    14
slouken@10486
    15
slouken@10486
    16
Requirements
slouken@10486
    17
------------
slouken@10486
    18
slouken@10486
    19
* Microsoft Visual C++ (aka Visual Studio), either 2015, 2013, or 2012
slouken@10486
    20
  - Free, "Community" or "Express" editions may be used, so long as they
slouken@10486
    21
    include  support for either "Windows Store" or "Windows Phone" apps.
slouken@10486
    22
    "Express" versions marked as supporting "Windows Desktop" development
slouken@10486
    23
    typically do not include support for creating WinRT apps, to note.
slouken@10486
    24
    (The "Community" editions of Visual C++ do, however, support both
slouken@10486
    25
    desktop/Win32 and WinRT development).
slouken@10486
    26
  - Visual C++ 2012 can only build apps that target versions 8.0 of Windows,
slouken@10486
    27
    or  Windows Phone.  8.0-targetted apps will run on devices running 8.1
slouken@10486
    28
    editions of Windows, however they will not be able to take advantage of
slouken@10486
    29
    8.1-specific features.
slouken@10486
    30
  - Visual C++ 2013 cannot create app projects that target Windows 8.0.
slouken@10486
    31
    Visual C++ 2013 Update 4, can create app projects for Windows Phone 8.0,
slouken@10486
    32
    Windows Phone 8.1, and Windows 8.1, but not Windows 8.0.  An optional
slouken@10486
    33
    Visual Studio add-in, "Tools for Maintaining Store apps for Windows 8",
slouken@10486
    34
    allows Visual C++ 2013 to load and build Windows 8.0 projects that were
slouken@10486
    35
    created with Visual C++ 2012, so long as Visual C++ 2012 is installed
slouken@10486
    36
    on the same machine.  More details on targeting different versions of
slouken@10486
    37
    Windows can found at the following web pages:
slouken@10486
    38
      - [Develop apps by using Visual Studio 2013](http://msdn.microsoft.com/en-us/library/windows/apps/br211384.aspx)
slouken@10486
    39
      - [To add the Tools for Maintaining Store apps for Windows 8](http://msdn.microsoft.com/en-us/library/windows/apps/dn263114.aspx#AddMaintenanceTools)
slouken@10486
    40
* A valid Microsoft account - This requirement is not imposed by SDL, but
slouken@10486
    41
  rather by Microsoft's Visual C++ toolchain.  This is required to launch or 
slouken@10486
    42
  debug apps.
slouken@10486
    43
slouken@10486
    44
slouken@10486
    45
Status
slouken@10486
    46
------
slouken@10486
    47
slouken@10486
    48
Here is a rough list of what works, and what doens't:
slouken@10486
    49
slouken@10486
    50
* What works:
slouken@10486
    51
  * compilation via Visual C++ 2012 through 2015
slouken@10486
    52
  * compile-time platform detection for SDL programs.  The C/C++ #define,
slouken@10486
    53
    `__WINRT__`, will be set to 1 (by SDL) when compiling for WinRT.
slouken@10486
    54
  * GPU-accelerated 2D rendering, via SDL_Renderer.
slouken@10486
    55
  * OpenGL ES 2, via the ANGLE library (included separately from SDL)
slouken@10486
    56
  * software rendering, via either SDL_Surface (optionally in conjunction with
slouken@10486
    57
    SDL_GetWindowSurface() and SDL_UpdateWindowSurface()) or via the
slouken@10486
    58
    SDL_Renderer APIs
slouken@10486
    59
  * threads
slouken@10486
    60
  * timers (via SDL_GetTicks(), SDL_AddTimer(), SDL_GetPerformanceCounter(),
slouken@10486
    61
    SDL_GetPerformanceFrequency(), etc.)
slouken@10486
    62
  * file I/O via SDL_RWops
slouken@10486
    63
  * mouse input  (unsupported on Windows Phone)
slouken@10486
    64
  * audio, via a modified version of SDL's XAudio2 backend
slouken@10486
    65
  * .DLL file loading.  Libraries *MUST* be packaged inside applications.  Loading
slouken@10486
    66
    anything outside of the app is not supported.
slouken@10486
    67
  * system path retrieval via SDL's filesystem APIs
slouken@10486
    68
  * game controllers.  Support is provided via the SDL_Joystick and
slouken@10486
    69
    SDL_GameController APIs, and is backed by Microsoft's XInput API.
slouken@10486
    70
  * multi-touch input
slouken@10486
    71
  * app events.  SDL_APP_WILLENTER* and SDL_APP_DIDENTER* events get sent out as
slouken@10486
    72
    appropriate.
slouken@10486
    73
  * window events
slouken@10486
    74
  * using Direct3D 11.x APIs outside of SDL.  Non-XAML / Direct3D-only apps can
slouken@10486
    75
    choose to render content directly via Direct3D, using SDL to manage the
slouken@10486
    76
    internal WinRT window, as well as input and audio.  (Use
slouken@10486
    77
    SDL_GetWindowWMInfo() to get the WinRT 'CoreWindow', and pass it into
slouken@10486
    78
    IDXGIFactory2::CreateSwapChainForCoreWindow() as appropriate.)
slouken@10486
    79
slouken@10486
    80
* What partially works:
slouken@10486
    81
  * keyboard input.  Most of WinRT's documented virtual keys are supported, as
slouken@10486
    82
    well as many keys with documented hardware scancodes.  Converting
slouken@10486
    83
    SDL_Scancodes to or from SDL_Keycodes may not work, due to missing APIs
slouken@10486
    84
    (MapVirualKey()) in Microsoft's Windows Store / UWP APIs.
slouken@10486
    85
  * SDLmain.  WinRT uses a different signature for each app's main() function.
slouken@10486
    86
    SDL-based apps that use this port must compile in SDL_winrt_main_NonXAML.cpp
slouken@10486
    87
    (in `SDL\src\main\winrt\`) directly in order for their C-style main()
slouken@10486
    88
    functions to be called.
slouken@10486
    89
slouken@10486
    90
* What doesn't work:
slouken@10486
    91
  * compilation with anything other than Visual C++
slouken@10486
    92
  * programmatically-created custom cursors.  These don't appear to be supported
slouken@10486
    93
    by WinRT.  Different OS-provided cursors can, however, be created via
slouken@10486
    94
    SDL_CreateSystemCursor() (unsupported on Windows Phone)
slouken@10486
    95
  * SDL_WarpMouseInWindow() or SDL_WarpMouseGlobal().  This are not currently
slouken@10486
    96
    supported by WinRT itself.
slouken@10486
    97
  * joysticks and game controllers that aren't supported by Microsoft's XInput
slouken@10486
    98
    API.
slouken@10486
    99
  * turning off VSync when rendering on Windows Phone.  Attempts to turn VSync
slouken@10486
   100
    off on Windows Phone result either in Direct3D not drawing anything, or it
slouken@10486
   101
    forcing VSync back on.  As such, SDL_RENDERER_PRESENTVSYNC will always get
slouken@10486
   102
    turned-on on Windows Phone.  This limitation is not present in non-Phone
slouken@10486
   103
    WinRT (such as Windows 8.x), where turning off VSync appears to work.
slouken@10486
   104
  * probably anything else that's not listed as supported
slouken@10486
   105
slouken@10486
   106
slouken@10486
   107
slouken@10486
   108
Upgrade Notes
slouken@10486
   109
-------------
slouken@10486
   110
slouken@10486
   111
#### SDL_GetPrefPath() usage when upgrading WinRT apps from SDL 2.0.3
slouken@10486
   112
slouken@10486
   113
SDL 2.0.4 fixes two bugs found in the WinRT version of SDL_GetPrefPath().
slouken@10486
   114
The fixes may affect older, SDL 2.0.3-based apps' save data.  Please note
slouken@10486
   115
that these changes only apply to SDL-based WinRT apps, and not to apps for
slouken@10486
   116
any other platform.
slouken@10486
   117
slouken@10486
   118
1. SDL_GetPrefPath() would return an invalid path, one in which the path's
slouken@10486
   119
   directory had not been created.  Attempts to create files there
slouken@10486
   120
   (via fopen(), for example), would fail, unless that directory was
slouken@10486
   121
   explicitly created beforehand.
slouken@10486
   122
slouken@10486
   123
2. SDL_GetPrefPath(), for non-WinPhone-based apps, would return a path inside
slouken@10486
   124
   a WinRT 'Roaming' folder, the contents of which get automatically
slouken@10486
   125
   synchronized across multiple devices.  This process can occur while an
slouken@10486
   126
   application runs, and can cause existing save-data to be overwritten
slouken@10486
   127
   at unexpected times, with data from other devices.  (Windows Phone apps
slouken@10486
   128
   written with SDL 2.0.3 did not utilize a Roaming folder, due to API
slouken@10486
   129
   restrictions in Windows Phone 8.0).
slouken@10486
   130
slouken@10486
   131
slouken@10486
   132
SDL_GetPrefPath(), starting with SDL 2.0.4, addresses these by:
slouken@10486
   133
slouken@10486
   134
1. making sure that SDL_GetPrefPath() returns a directory in which data
slouken@10486
   135
   can be written to immediately, without first needing to create directories.
slouken@10486
   136
slouken@10486
   137
2. basing SDL_GetPrefPath() off of a different, non-Roaming folder, the
slouken@10486
   138
   contents of which do not automatically get synchronized across devices
slouken@10486
   139
   (and which require less work to use safely, in terms of data integrity).
slouken@10486
   140
slouken@10486
   141
Apps that wish to get their Roaming folder's path can do so either by using
slouken@10486
   142
SDL_WinRTGetFSPathUTF8(), SDL_WinRTGetFSPathUNICODE() (which returns a
slouken@10486
   143
UCS-2/wide-char string), or directly through the WinRT class,
slouken@10486
   144
Windows.Storage.ApplicationData.
slouken@10486
   145
slouken@10486
   146
slouken@10486
   147
slouken@10486
   148
Setup, High-Level Steps
slouken@10486
   149
-----------------------
slouken@10486
   150
slouken@10486
   151
The steps for setting up a project for an SDL/WinRT app looks like the
slouken@10486
   152
following, at a high-level:
slouken@10486
   153
slouken@10486
   154
1. create a new Visual C++ project using Microsoft's template for a,
slouken@10486
   155
   "Direct3D App".
slouken@10486
   156
2. remove most of the files from the project.
slouken@10486
   157
3. make your app's project directly reference SDL/WinRT's own Visual C++
slouken@10486
   158
   project file, via use of Visual C++'s "References" dialog.  This will setup
slouken@10486
   159
   the linker, and will copy SDL's .dll files to your app's final output.
slouken@10486
   160
4. adjust your app's build settings, at minimum, telling it where to find SDL's
slouken@10486
   161
   header files.
slouken@10486
   162
5. add files that contains a WinRT-appropriate main function, along with some
slouken@10486
   163
   data to make sure mouse-cursor-hiding (via SDL_ShowCursor(SDL_DISABLE) calls)
slouken@10486
   164
   work properly.
slouken@10486
   165
6. add SDL-specific app code.
slouken@10486
   166
7. build and run your app.
slouken@10486
   167
slouken@10486
   168
slouken@10486
   169
Setup, Detailed Steps
slouken@10486
   170
---------------------
slouken@10486
   171
slouken@10486
   172
### 1. Create a new project ###
slouken@10486
   173
slouken@10486
   174
Create a new project using one of Visual C++'s templates for a plain, non-XAML,
slouken@10486
   175
"Direct3D App" (XAML support for SDL/WinRT is not yet ready for use).  If you
slouken@10486
   176
don't see one of these templates, in Visual C++'s 'New Project' dialog, try
slouken@10486
   177
using the textbox titled, 'Search Installed Templates' to look for one.
slouken@10486
   178
slouken@10486
   179
slouken@10486
   180
### 2. Remove unneeded files from the project ###
slouken@10486
   181
slouken@10486
   182
In the new project, delete any file that has one of the following extensions:
slouken@10486
   183
slouken@10486
   184
- .cpp
slouken@10486
   185
- .h
slouken@10486
   186
- .hlsl
slouken@10486
   187
slouken@10486
   188
When you are done, you should be left with a few files, each of which will be a
slouken@10486
   189
necessary part of your app's project.  These files will consist of:
slouken@10486
   190
slouken@10486
   191
- an .appxmanifest file, which contains metadata on your WinRT app.  This is
slouken@10486
   192
  similar to an Info.plist file on iOS, or an AndroidManifest.xml on Android.
slouken@10486
   193
- a few .png files, one of which is a splash screen (displayed when your app
slouken@10486
   194
  launches), others are app icons.
slouken@10486
   195
- a .pfx file, used for code signing purposes.
slouken@10486
   196
slouken@10486
   197
slouken@10486
   198
### 3. Add references to SDL's project files ###
slouken@10486
   199
slouken@10486
   200
SDL/WinRT can be built in multiple variations, spanning across three different
slouken@10486
   201
CPU architectures (x86, x64, and ARM) and two different configurations
slouken@10486
   202
(Debug and Release).  WinRT and Visual C++ do not currently provide a means
slouken@10486
   203
for combining multiple variations of one library into a single file.
slouken@10486
   204
Furthermore, it does not provide an easy means for copying pre-built .dll files
slouken@10486
   205
into your app's final output (via Post-Build steps, for example).  It does,
slouken@10486
   206
however, provide a system whereby an app can reference the MSVC projects of
slouken@10486
   207
libraries such that, when the app is built:
slouken@10486
   208
slouken@10486
   209
1. each library gets built for the appropriate CPU architecture(s) and WinRT
slouken@10486
   210
   platform(s).
slouken@10486
   211
2. each library's output, such as .dll files, get copied to the app's build 
slouken@10486
   212
   output.
slouken@10486
   213
slouken@10486
   214
To set this up for SDL/WinRT, you'll need to run through the following steps:
slouken@10486
   215
slouken@10486
   216
1. open up the Solution Explorer inside Visual C++ (under the "View" menu, then
slouken@10486
   217
   "Solution Explorer")
slouken@10486
   218
2. right click on your app's solution.
slouken@10486
   219
3. navigate to "Add", then to "Existing Project..."
slouken@10486
   220
4. find SDL/WinRT's Visual C++ project file and open it.  Different project
slouken@10486
   221
   files exist for different WinRT platforms.  All of them are in SDL's
slouken@10486
   222
   source distribution, in the following directories:
slouken@10486
   223
    * `VisualC-WinRT/UWP_VS2015/`        - for Windows 10 / UWP apps
slouken@10486
   224
    * `VisualC-WinRT/WinPhone81_VS2013/` - for Windows Phone 8.1 apps
slouken@10486
   225
    * `VisualC-WinRT/WinRT80_VS2012/`    - for Windows 8.0 apps
slouken@10486
   226
    * `VisualC-WinRT/WinRT81_VS2013/`    - for Windows 8.1 apps
slouken@10486
   227
5. once the project has been added, right-click on your app's project and
slouken@10486
   228
   select, "References..."
slouken@10486
   229
6. click on the button titled, "Add New Reference..."
slouken@10486
   230
7. check the box next to SDL
slouken@10486
   231
8. click OK to close the dialog
slouken@10486
   232
9. SDL will now show up in the list of references.  Click OK to close that
slouken@10486
   233
   dialog.
slouken@10486
   234
slouken@10486
   235
Your project is now linked to SDL's project, insofar that when the app is
slouken@10486
   236
built, SDL will be built as well, with its build output getting included with
slouken@10486
   237
your app.
slouken@10486
   238
slouken@10486
   239
slouken@10486
   240
### 4. Adjust Your App's Build Settings ###
slouken@10486
   241
slouken@10486
   242
Some build settings need to be changed in your app's project.  This guide will
slouken@10486
   243
outline the following:
slouken@10486
   244
slouken@10486
   245
- making sure that the compiler knows where to find SDL's header files
slouken@10486
   246
- **Optional for C++, but NECESSARY for compiling C code:** telling the
slouken@10486
   247
  compiler not to use Microsoft's C++ extensions for WinRT development.
slouken@10486
   248
- **Optional:** telling the compiler not generate errors due to missing
slouken@10486
   249
  precompiled header files.
slouken@10486
   250
slouken@10486
   251
To change these settings:
slouken@10486
   252
slouken@10486
   253
1. right-click on the project
slouken@10486
   254
2. choose "Properties"
slouken@10486
   255
3. in the drop-down box next to "Configuration", choose, "All Configurations"
slouken@10486
   256
4. in the drop-down box next to "Platform", choose, "All Platforms"
slouken@10486
   257
5. in the left-hand list, expand the "C/C++" section
slouken@10486
   258
6. select "General"
slouken@10486
   259
7. edit the "Additional Include Directories" setting, and add a path to SDL's
slouken@10486
   260
   "include" directory
slouken@10486
   261
8. **Optional: to enable compilation of C code:** change the setting for
slouken@10486
   262
   "Consume Windows Runtime Extension" from "Yes (/ZW)" to "No".  If you're 
slouken@10486
   263
   working with a completely C++ based project, this step can usually be 
slouken@10486
   264
   omitted.
slouken@10486
   265
9. **Optional: to disable precompiled headers (which can produce 
slouken@10486
   266
   'stdafx.h'-related build errors, if setup incorrectly:** in the left-hand 
slouken@10486
   267
   list, select "Precompiled Headers", then change the setting for "Precompiled 
slouken@10486
   268
   Header" from "Use (/Yu)" to "Not Using Precompiled Headers".
slouken@10486
   269
10. close the dialog, saving settings, by clicking the "OK" button
slouken@10486
   270
slouken@10486
   271
slouken@10486
   272
### 5. Add a WinRT-appropriate main function, and a blank-cursor image, to the app. ###
slouken@10486
   273
slouken@10486
   274
A few files should be included directly in your app's MSVC project, specifically:
slouken@10486
   275
1. a WinRT-appropriate main function (which is different than main() functions on
slouken@10486
   276
   other platforms)
slouken@10486
   277
2. a Win32-style cursor resource, used by SDL_ShowCursor() to hide the mouse cursor
slouken@10486
   278
   (if and when the app needs to do so).  *If this cursor resource is not
slouken@10486
   279
   included, mouse-position reporting may fail if and when the cursor is
slouken@10486
   280
   hidden, due to possible bugs/design-oddities in Windows itself.*
slouken@10486
   281
slouken@10486
   282
To include these files:
slouken@10486
   283
slouken@10486
   284
1. right-click on your project (again, in Visual C++'s Solution Explorer), 
slouken@10486
   285
   navigate to "Add", then choose "Existing Item...".
slouken@10486
   286
2. navigate to the directory containing SDL's source code, then into its
slouken@10486
   287
   subdirectory, 'src/main/winrt/'.  Select, then add, the following files:
slouken@10486
   288
   - `SDL_winrt_main_NonXAML.cpp`
slouken@10486
   289
   - `SDL2-WinRTResources.rc`
slouken@10486
   290
   - `SDL2-WinRTResource_BlankCursor.cur`
slouken@10486
   291
3. right-click on the file `SDL_winrt_main_NonXAML.cpp` (as listed in your
slouken@10486
   292
   project), then click on "Properties...".
slouken@10486
   293
4. in the drop-down box next to "Configuration", choose, "All Configurations"
slouken@10486
   294
5. in the drop-down box next to "Platform", choose, "All Platforms"
slouken@10486
   295
6. in the left-hand list, click on "C/C++"
slouken@10486
   296
7. change the setting for "Consume Windows Runtime Extension" to "Yes (/ZW)".
slouken@10486
   297
8. click the OK button.  This will close the dialog.
slouken@10486
   298
slouken@10486
   299
slouken@10486
   300
**NOTE: C++/CX compilation is currently required in at least one file of your 
slouken@10486
   301
app's project.  This is to make sure that Visual C++'s linker builds a 'Windows 
slouken@10486
   302
Metadata' file (.winmd) for your app.  Not doing so can lead to build errors.**
slouken@10486
   303
slouken@10486
   304
slouken@10486
   305
### 6. Add app code and assets ###
slouken@10486
   306
slouken@10486
   307
At this point, you can add in SDL-specific source code.  Be sure to include a 
slouken@10486
   308
C-style main function (ie: `int main(int argc, char *argv[])`).  From there you 
slouken@10486
   309
should be able to create a single `SDL_Window` (WinRT apps can only have one 
slouken@10486
   310
window, at present), as well as an `SDL_Renderer`.  Direct3D will be used to 
slouken@10486
   311
draw content.  Events are received via SDL's usual event functions 
slouken@10486
   312
(`SDL_PollEvent`, etc.)  If you have a set of existing source files and assets, 
slouken@10486
   313
you can start adding them to the project now.  If not, or if you would like to 
slouken@10486
   314
make sure that you're setup correctly, some short and simple sample code is 
slouken@10486
   315
provided below.
slouken@10486
   316
slouken@10486
   317
slouken@10486
   318
#### 6.A. ... when creating a new app ####
slouken@10486
   319
slouken@10486
   320
If you are creating a new app (rather than porting an existing SDL-based app), 
slouken@10486
   321
or if you would just like a simple app to test SDL/WinRT with before trying to 
slouken@10486
   322
get existing code working, some working SDL/WinRT code is provided below.  To 
slouken@10486
   323
set this up:
slouken@10486
   324
slouken@10486
   325
1. right click on your app's project
slouken@10486
   326
2. select Add, then New Item.  An "Add New Item" dialog will show up.
slouken@10486
   327
3. from the left-hand list, choose "Visual C++"
slouken@10486
   328
4. from the middle/main list, choose "C++ File (.cpp)"
slouken@10486
   329
5. near the bottom of the dialog, next to "Name:", type in a name for your 
slouken@10486
   330
source file, such as, "main.cpp".
slouken@10486
   331
6. click on the Add button.  This will close the dialog, add the new file to 
slouken@10486
   332
your project, and open the file in Visual C++'s text editor.
slouken@10486
   333
7. Copy and paste the following code into the new file, then save it.
slouken@10486
   334
slouken@10486
   335
slouken@10486
   336
    #include <SDL.h>
slouken@10486
   337
    
slouken@10486
   338
    int main(int argc, char **argv)
slouken@10486
   339
    {
slouken@10486
   340
        SDL_DisplayMode mode;
slouken@10486
   341
        SDL_Window * window = NULL;
slouken@10486
   342
        SDL_Renderer * renderer = NULL;
slouken@10486
   343
        SDL_Event evt;
slouken@10486
   344
    
slouken@10486
   345
        if (SDL_Init(SDL_INIT_VIDEO) != 0) {
slouken@10486
   346
            return 1;
slouken@10486
   347
        }
slouken@10486
   348
    
slouken@10486
   349
        if (SDL_GetCurrentDisplayMode(0, &mode) != 0) {
slouken@10486
   350
            return 1;
slouken@10486
   351
        }
slouken@10486
   352
    
slouken@10486
   353
        if (SDL_CreateWindowAndRenderer(mode.w, mode.h, SDL_WINDOW_FULLSCREEN, &window, &renderer) != 0) {
slouken@10486
   354
            return 1;
slouken@10486
   355
        }
slouken@10486
   356
    
slouken@10486
   357
        while (1) {
slouken@10486
   358
            while (SDL_PollEvent(&evt)) {
slouken@10486
   359
            }
slouken@10486
   360
    
slouken@10486
   361
            SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
slouken@10486
   362
            SDL_RenderClear(renderer);
slouken@10486
   363
            SDL_RenderPresent(renderer);
slouken@10486
   364
        }
slouken@10486
   365
    }
slouken@10486
   366
slouken@10486
   367
slouken@10486
   368
#### 6.B. Adding code and assets ####
slouken@10486
   369
slouken@10486
   370
If you have existing code and assets that you'd like to add, you should be able 
slouken@10486
   371
to add them now.  The process for adding a set of files is as such.
slouken@10486
   372
slouken@10486
   373
1. right click on the app's project
slouken@10486
   374
2. select Add, then click on "New Item..."
slouken@10486
   375
3. open any source, header, or asset files as appropriate.  Support for C and 
slouken@10486
   376
C++ is available.
slouken@10486
   377
slouken@10486
   378
Do note that WinRT only supports a subset of the APIs that are available to 
slouken@10486
   379
Win32-based apps.  Many portions of the Win32 API and the C runtime are not 
slouken@10486
   380
available.
slouken@10486
   381
slouken@10486
   382
A list of unsupported C APIs can be found at 
slouken@10486
   383
<http://msdn.microsoft.com/en-us/library/windows/apps/jj606124.aspx>
slouken@10486
   384
slouken@10486
   385
General information on using the C runtime in WinRT can be found at 
slouken@10486
   386
<https://msdn.microsoft.com/en-us/library/hh972425.aspx>
slouken@10486
   387
slouken@10486
   388
A list of supported Win32 APIs for WinRT apps can be found at 
slouken@10486
   389
<http://msdn.microsoft.com/en-us/library/windows/apps/br205757.aspx>.  To note, 
slouken@10486
   390
the list of supported Win32 APIs for Windows Phone 8.0 is different.  
slouken@10486
   391
That list can be found at 
slouken@10486
   392
<http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662956(v=vs.105).aspx>
slouken@10486
   393
slouken@10486
   394
slouken@10486
   395
### 7. Build and run your app ###
slouken@10486
   396
slouken@10486
   397
Your app project should now be setup, and you should be ready to build your app.  
slouken@10486
   398
To run it on the local machine, open the Debug menu and choose "Start 
slouken@10486
   399
Debugging".  This will build your app, then run your app full-screen.  To switch 
slouken@10486
   400
out of your app, press the Windows key.  Alternatively, you can choose to run 
slouken@10486
   401
your app in a window.  To do this, before building and running your app, find 
slouken@10486
   402
the drop-down menu in Visual C++'s toolbar that says, "Local Machine".  Expand 
slouken@10486
   403
this by clicking on the arrow on the right side of the list, then click on 
slouken@10486
   404
Simulator.  Once you do that, any time you build and run the app, the app will 
slouken@10486
   405
launch in window, rather than full-screen.
slouken@10486
   406
slouken@10486
   407
slouken@10486
   408
#### 7.A. Running apps on older, ARM-based, "Windows RT" devices ####
slouken@10486
   409
slouken@10486
   410
**These instructions do not include Windows Phone, despite Windows Phone
slouken@10486
   411
typically running on ARM processors.**  They are specifically for devices
slouken@10486
   412
that use the "Windows RT" operating system, which was a modified version of
slouken@10486
   413
Windows 8.x that ran primarily on ARM-based tablet computers.
slouken@10486
   414
slouken@10486
   415
To build and run the app on ARM-based, "Windows RT" devices, you'll need to:
slouken@10486
   416
slouken@10486
   417
- install Microsoft's "Remote Debugger" on the device.  Visual C++ installs and 
slouken@10486
   418
  debugs ARM-based apps via IP networks.
slouken@10486
   419
- change a few options on the development machine, both to make sure it builds 
slouken@10486
   420
  for ARM (rather than x86 or x64), and to make sure it knows how to find the 
slouken@10486
   421
  Windows RT device (on the network).
slouken@10486
   422
slouken@10486
   423
Microsoft's Remote Debugger can be found at 
slouken@10486
   424
<https://msdn.microsoft.com/en-us/library/hh441469.aspx>.  Please note 
slouken@10486
   425
that separate versions of this debugger exist for different versions of Visual 
slouken@10486
   426
C++, one each for MSVC 2015, 2013, and 2012.
slouken@10486
   427
slouken@10486
   428
To setup Visual C++ to launch your app on an ARM device:
slouken@10486
   429
slouken@10486
   430
1. make sure the Remote Debugger is running on your ARM device, and that it's on 
slouken@10486
   431
   the same IP network as your development machine.
slouken@10486
   432
2. from Visual C++'s toolbar, find a drop-down menu that says, "Win32".  Click 
slouken@10486
   433
   it, then change the value to "ARM".
slouken@10486
   434
3. make sure Visual C++ knows the hostname or IP address of the ARM device.  To 
slouken@10486
   435
   do this:
slouken@10486
   436
    1. open the app project's properties
slouken@10486
   437
    2. select "Debugging"
slouken@10486
   438
    3. next to "Machine Name", enter the hostname or IP address of the ARM 
slouken@10486
   439
       device
slouken@10486
   440
    4. if, and only if, you've turned off authentication in the Remote Debugger,
slouken@10486
   441
       then change the setting for "Require Authentication" to No
slouken@10486
   442
    5. click "OK"
slouken@10486
   443
4. build and run the app (from Visual C++).  The first time you do this, a 
slouken@10486
   444
   prompt will show up on the ARM device, asking for a Microsoft Account.  You 
slouken@10486
   445
   do, unfortunately, need to log in here, and will need to follow the 
slouken@10486
   446
   subsequent registration steps in order to launch the app.  After you do so, 
slouken@10486
   447
   if the app didn't already launch, try relaunching it again from within Visual 
slouken@10486
   448
   C++.
slouken@10486
   449
slouken@10486
   450
slouken@10486
   451
Troubleshooting
slouken@10486
   452
---------------
slouken@10486
   453
slouken@10486
   454
#### Build fails with message, "error LNK2038: mismatch detected for 'vccorlib_lib_should_be_specified_before_msvcrt_lib_to_linker'"
slouken@10486
   455
slouken@10486
   456
Try adding the following to your linker flags.  In MSVC, this can be done by
slouken@10486
   457
right-clicking on the app project, navigating to Configuration Properties ->
slouken@10486
   458
Linker -> Command Line, then adding them to the Additional Options
slouken@10486
   459
section.
slouken@10486
   460
slouken@10486
   461
* For Release builds / MSVC-Configurations, add:
slouken@10486
   462
slouken@10486
   463
    /nodefaultlib:vccorlib /nodefaultlib:msvcrt vccorlib.lib msvcrt.lib
slouken@10486
   464
slouken@10486
   465
* For Debug builds / MSVC-Configurations, add:
slouken@10486
   466
slouken@10486
   467
    /nodefaultlib:vccorlibd /nodefaultlib:msvcrtd vccorlibd.lib msvcrtd.lib
slouken@10486
   468
slouken@10486
   469
slouken@10486
   470
#### Mouse-motion events fail to get sent, or SDL_GetMouseState() fails to return updated values
slouken@10486
   471
slouken@10486
   472
This may be caused by a bug in Windows itself, whereby hiding the mouse
slouken@10486
   473
cursor can cause mouse-position reporting to fail.
slouken@10486
   474
slouken@10486
   475
SDL provides a workaround for this, but it requires that an app links to a
slouken@10486
   476
set of Win32-style cursor image-resource files.  A copy of suitable resource
slouken@10486
   477
files can be found in `src/main/winrt/`.  Adding them to an app's Visual C++
slouken@10486
   478
project file should be sufficient to get the app to use them.