Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions Desktop/Common/Direct3D10DemoApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using SharpDX.Direct3D;
using SharpDX.Direct3D10;
using SharpDX.DXGI;
using Device = SharpDX.Direct3D10.Device;
using Device1 = SharpDX.Direct3D10.Device1;
using DriverType = SharpDX.Direct3D10.DriverType;
using FeatureLevel = SharpDX.Direct3D10.FeatureLevel;


namespace SharpDX.Samples
{
/// <summary>
/// Root class for Direct3D10(.1) Demo App
/// </summary>
public class Direct3D10DemoApp : DemoApp
{
Device1 _device;
SwapChain _swapChain;
Texture2D _backBuffer;
RenderTargetView _backBufferView;

/// <summary>
/// Returns the device
/// </summary>
public Device1 Device
{
get
{
return _device;
}
}

/// <summary>
/// Returns the backbuffer used by the SwapChain
/// </summary>
public Texture2D BackBuffer
{
get
{
return _backBuffer;
}
}

/// <summary>
/// Returns the render target view on the backbuffer used by the SwapChain.
/// </summary>
public RenderTargetView BackBufferView
{
get
{
return _backBufferView;
}
}

protected override void Initialize(DemoConfiguration demoConfiguration)
{
// SwapChain description
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription =
new ModeDescription(demoConfiguration.Width, demoConfiguration.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = DisplayHandle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};

// Create Device and SwapChain
Device1.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, FeatureLevel.Level_10_0, out _device, out _swapChain);

// Ignore all windows events
Factory factory = _swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(DisplayHandle, WindowAssociationFlags.IgnoreAll);

// New RenderTargetView from the backbuffer
_backBuffer = Texture2D.FromSwapChain<Texture2D>(_swapChain, 0);

_backBufferView = new RenderTargetView(_device, _backBuffer);


}

protected override void BeginDraw()
{
base.BeginDraw();
Device.Rasterizer.SetViewports(new Viewport(0, 0, Config.Width, Config.Height));
Device.OutputMerger.SetTargets(_backBufferView);
}


protected override void EndDraw()
{
_swapChain.Present(Config.WaitVerticalBlanking?1:0, PresentFlags.None);
}
}
}
4 changes: 4 additions & 0 deletions Desktop/Common/SharpDX.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<Reference Include="SharpDX.Direct2D1">
<HintPath>..\..\..\Bin\Desktop\SharpDX.Direct2D1.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Direct3D10">
<HintPath>..\..\..\Bin\Desktop\SharpDX.Direct3D10.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Direct3D11">
<HintPath>..\..\..\Bin\Desktop\SharpDX.Direct3D11.dll</HintPath>
</Reference>
Expand All @@ -67,6 +70,7 @@
<Compile Include="DemoTime.cs" />
<Compile Include="Direct2D1DemoApp.cs" />
<Compile Include="Direct2D1WinFormDemoApp.cs" />
<Compile Include="Direct3D10DemoApp.cs" />
<Compile Include="Direct3D11DemoApp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
87 changes: 87 additions & 0 deletions Desktop/Direct3D10/DisplayFontApp/DisplayFontApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A0A13A2D-9D57-4057-AA8C-A46D18B99354}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DisplayFontApp</RootNamespace>
<AssemblyName>DisplayFontApp</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>10cd9ae8</NuGetPackageImportStamp>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpDX">
<HintPath>..\..\..\..\Bin\Desktop\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.D3DCompiler">
<HintPath>..\..\..\..\Bin\Desktop\SharpDX.D3DCompiler.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Desktop">
<HintPath>..\..\..\..\Bin\Desktop\SharpDX.Desktop.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Direct3D10">
<HintPath>..\..\..\..\Bin\Desktop\SharpDX.Direct3D10.dll</HintPath>
</Reference>
<Reference Include="SharpDX.DXGI">
<HintPath>..\..\..\..\Bin\Desktop\SharpDX.DXGI.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Mathematics">
<HintPath>..\..\..\..\Bin\Desktop\SharpDX.Mathematics.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\SharpDX.Samples.csproj">
<Project>{93716298-9FA4-4002-AE0B-4C9F4705CCEA}</Project>
<Name>SharpDX.Samples</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
100 changes: 100 additions & 0 deletions Desktop/Direct3D10/DisplayFontApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using SharpDX;
using SharpDX.Direct3D10;
using SharpDX.Samples;


namespace DisplayFontApp
{
/// <summary>
/// SharpDX Demo using D3D10 Font rendering.
/// Animates and draws a text, boucing on the screen limits.
/// </summary>
public class Program : Direct3D10DemoApp
{
private Font font;
private Rectangle fontDimension;
private float xDir, yDir;
private const string DisplayText = "SharpDX D3D10 Font";

protected override void Initialize(DemoConfiguration demoConfiguration)
{
base.Initialize(demoConfiguration);

// Initialize the Font
FontDescription fontDescription = new FontDescription()
{
Height = 72,
Italic = false,
CharacterSet = FontCharacterSet.Ansi,
FaceName = "Arial",
MipLevels = 0,
OutputPrecision = FontPrecision.TrueType,
PitchAndFamily = FontPitchAndFamily.Default,
Quality = FontQuality.ClearType,
Weight = FontWeight.Bold
};


font = new Font(Device, fontDescription);

// Measure the text to display
fontDimension = font.MeasureText(null, DisplayText, new Rectangle(0, 0, 800, 600), FontDrawFlags.Center | FontDrawFlags.VerticalCenter);

xDir = 1;
yDir = 1;
}

protected override void Draw(DemoTime time)
{
base.Draw(time);

Device.ClearRenderTargetView(BackBufferView, Color.White);

// Make the text boucing on the screen limits
if ((fontDimension.Right + xDir) > Config.Width)
xDir = -1;
else if ((fontDimension.Left + xDir) <= 0)
xDir = 1;

if ((fontDimension.Bottom + yDir) > Config.Height)
yDir = -1;
else if ((fontDimension.Top + yDir) <= 0)
yDir = 1;

fontDimension.Left += (int)xDir;
fontDimension.Top += (int)yDir;
fontDimension.Bottom += (int)yDir;
fontDimension.Right += (int)xDir;

// Draw the text
font.DrawText(null, DisplayText, fontDimension, FontDrawFlags.Center | FontDrawFlags.VerticalCenter, Color.Black);
}

[STAThread]
static void Main(string[] args)
{
Program program = new Program();
program.Run(new DemoConfiguration("SharpDX D3D10 Font Rendering Demo") { WaitVerticalBlanking = true });
}
}
}
36 changes: 36 additions & 0 deletions Desktop/Direct3D10/DisplayFontApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DisplayFontApp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("DisplayFontApp")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2f297cfc-8862-458a-97dd-a8bafdb6eb94")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
3 changes: 3 additions & 0 deletions Desktop/Direct3D10/DisplayFontApp/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>
Binary file added Desktop/Direct3D10/DisplayFontApp/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading