docs/README-winrt.md
author David Ludwig
Sat, 14 May 2016 23:29:49 -0400
changeset 10171 5b61e12c0a30
parent 10156 80e408941b90
child 10486 5bf595c48fd4
permissions -rw-r--r--
WinRT: workaround a possible Windows bug, whereby hiding cursors, disables mouse-moved events

This workaround, unfortunately, requires that apps directly link to a set of
Win32-style cursor resource files (that contain a transparent cursor image).
Copies of suitable resource files are in src/core/winrt/, and should be
included directly in an app's MSVC project.

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