🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

519 lines
23 KiB

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