Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

and now it works in desktop mode too!

(sort of)
  • Loading branch information...
commit 662c06c3459a364ec1ae5664a27c9566e83ef9d2 1 parent b1ca899
@vogon vogon authored
View
3  Defenetron8/Defenetron8.Common/Defenetron8.Common.Desktop.csproj
@@ -56,6 +56,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -66,6 +68,7 @@
<Compile Include="Common\Direct3DDevice.cs" />
<Compile Include="Common\IDirect3DWindow.cs" />
<Compile Include="Common\Rectangle.cs" />
+ <Compile Include="Direct3DWindow.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
View
3  Defenetron8/Defenetron8.Common/Direct3DCoreWindow.cs
@@ -111,8 +111,6 @@ private void OnLogicalDpiChanged(object sender)
// handle window size change
}
- private Direct3DDevice _device;
-
DXGI.SwapChain1 IDirect3DWindow.CreateSwapChain(D3D11.Device1 device, ref DXGI.SwapChainDescription1 description)
{
var dxgiDevice = device.QueryInterface<DXGI.Device1>();
@@ -134,6 +132,7 @@ Rectangle<double> IDirect3DWindow.Bounds
}
}
+ private Direct3DDevice _device;
private CoreWindow _coreWindow;
}
View
71 Defenetron8/Defenetron8.Common/Direct3DWindow.cs
@@ -0,0 +1,71 @@
+using SharpDX;
+using System.Drawing;
+using System.Windows.Forms;
+using D3D11 = SharpDX.Direct3D11;
+using DXGI = SharpDX.DXGI;
+
+namespace Defenetron8.Common.Desktop
+{
+ public class Direct3DWindow : IDirect3DWindow
+ {
+ public Direct3DWindow()
+ {
+ _form = new Form();
+ _form.Width = 640;
+ _form.Height = 480;
+ _form.BackColor = Color.Magenta;
+
+ _device = new Direct3DDevice();
+ _device.SetWindow(this);
+ }
+
+ public void Show()
+ {
+ _form.Show();
+ }
+
+ public void Render()
+ {
+ _device.ClearBackBuffer(new Color4(123.0f / 255.0f, 160.0f / 255.0f, 183.0f / 255.0f, 1));
+ _device.Present();
+ }
+
+ DXGI.SwapChain1 IDirect3DWindow.CreateSwapChain(D3D11.Device1 device, ref DXGI.SwapChainDescription1 description)
+ {
+ var dxgiDevice = device.QueryInterface<DXGI.Device1>();
+ var dxgiAdapter = dxgiDevice.Adapter;
+
+ var dxgiFactory = dxgiAdapter.GetParent<DXGI.Factory2>();
+
+ return dxgiFactory.CreateSwapChainForHwnd(dxgiDevice, _form.Handle, ref description, null, null);
+ }
+
+ Rectangle<double> IDirect3DWindow.Bounds
+ {
+ get
+ {
+ return new Rectangle<double> { X = 0, Y = 0, Width = 640, Height = 480 };
+ }
+ }
+
+ private Form _form;
+ private Direct3DDevice _device;
+ }
+
+ public static class Direct3DWindowMain
+ {
+ public static void Run()
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+
+ MainWindow = new Direct3DWindow();
+ MainWindow.Show();
+
+ Application.Idle += (sender, args) => MainWindow.Render();
+ Application.Run();
+ }
+
+ public static Direct3DWindow MainWindow { get; private set; }
+ }
+}
View
9 Defenetron8/Defenetron8.Desktop/Defenetron8.Desktop.csproj
@@ -53,6 +53,9 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <EmbeddedResource Include="Form1.resx">
+ <DependentUpon>Form1.cs</DependentUpon>
+ </EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -75,6 +78,12 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Defenetron8.Common\Defenetron8.Common.Desktop.csproj">
+ <Project>{f1cf74d7-b6ef-492c-8d8e-9968ea722037}</Project>
+ <Name>Defenetron8.Common.Desktop</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
39 Defenetron8/Defenetron8.Desktop/Form1.Designer.cs
@@ -1,39 +0,0 @@
-namespace Defenetron8.Desktop
-{
- partial class Form1
- {
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.Text = "Form1";
- }
-
- #endregion
- }
-}
-
View
20 Defenetron8/Defenetron8.Desktop/Form1.cs
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace Defenetron8.Desktop
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
View
5 Defenetron8/Defenetron8.Desktop/Program.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
+using Defenetron8.Common.Desktop;
namespace Defenetron8.Desktop
{
@@ -14,9 +15,7 @@ static class Program
[STAThread]
static void Main()
{
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
+ Direct3DWindowMain.Run();
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.