Switch platforms between DirectX and OpenGL (Win10 Universal and Cross Platform) [SOLVED]

Can you convert the project from OpenGL to DirectX and back again? Need it to port to both xbox and linux.

SOLUTION
When I first added all projects at once I got some weird problem with the app manifest. Creating it in this order was the only thing that worked for me.

  • Created a Windows 10 Universial project
    -I named the solution “MyGame”, and then renamed the project “MyGameDX”

-Added a simple Hello world code to try out.

  • Right click the solution and add project type “SharedProject”
    -Named it “MyGameSharedProject”

  • Added MyGameSharedProject to MyGameDX references.

  • Moved “Game1.cs” and the Content folder to the shared project.

  • Open MyGameSharedProject\MyGameSharedProject.projitems with a text editor.
    Change
    <None Include="$(MSBuildThisFileDirectory)Content\Content.mgcb" />
    to
    <None Include="$(MonoGameContentReference)Content\Content.mgcb" />

  • Open MyGameDX.csproj with a text editor. I added this after another ItemGroup.
    <ItemGroup>
    <MonoGameContentReference Include="..\MyGameSharedProject\Content\Content.mgcb" />
    </ItemGroup>
    The visual studio should update your MyGameDX project with a little reference icon to Content.

-Running the project should work now.

  • Right click the solution and add project type “Monogame Cross Platform”. Named it “MyGameGL”.

  • In solution properties, changed StartUp project to MyGameGL.

  • Removed “Game1.cs” and the Content folder from the GL project.

  • Added MyGameSharedProject to MyGameGL references.

  • Open MyGameGL.csproj with a text editor. I changed the content path
    <MonoGameContentReference Include="Content\Content.mgcb" />
    to
    <MonoGameContentReference Include="..\MyGameSharedProject\Content\Content.mgcb" />

  • Had to add “using MyGame;” in the Program.cs

-Running the project should work again. (I suggest you immedietly select the other project and try run that again)

I don’t think you can directly convert projects.
Usually for platform-independency you would have a shared project with all the game-code in it and then use that in your DesktopGL/DirectX/Android/etc. Project.

OR…

You can add an “Existing Item” from the Solution Explorer and add it as “Add as link”, when you update something from your Android project it will also reflect on Windows or from your other platform specific project, with this you don’t have to copy the updated source from other solution.

1 Like

I guess that means: I will have to manually update every time I add or move a file in my original project. Its slightly better at least.

1 Like

Yeah, this is easy to do using Shared Projects:

  1. Add YourGame.SharedProject to the solution
  2. Add YourGame.DirectX to the solution
  3. Add YourGame.OpenGL to the solution
  4. Add references to the shared proj to the other two
  5. Move all your game code to the shared proj
  6. Moving content is a little trickier: Add the .mgcb to the shared proj, and then open YourGame.SharedProject.projitems in a text editor. Change the xml tag of that file to MonoGameContentReference

So now you should have the shared project with all the logic of your game, and the other two are literally empty with only the Program.cs file. I use this technique all my monogame projects, there are a bunch of examples up on my github: https://github.com/dmanning23

Hope this helps. Cheers!

1 Like