Skip to content

Commit

Permalink
Correct 10_Text example.
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkoleci committed Feb 5, 2024
1 parent 5109da8 commit dc38925
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ dotnet_code_quality.CA1822.api_surface = private, internal
dotnet_code_quality.CA2208.api_surface = public

# License header
file_header_template = Copyright © Amer Koleci and Contributors.\nLicensed under the MIT License (MIT). See LICENSE in the repository root for more information.
file_header_template = Copyright (c) Amer Koleci and contributors.\nLicensed under the MIT License (MIT). See LICENSE in the repository root for more information.

# C++ Files
[*.{cpp,h,in}]
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="8.2.2" />
<PackageVersion Include="Alimer.Bindings.SDL" Version="3.4.7" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta" />

<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.4.231219000" />
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2022 Amer Koleci
Copyright (c) Amer Koleci and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/01_HelloWindow/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using Vortice.Direct3D11;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/02_DrawTriangle/TriangleApp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Numerics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/03_DrawQuad/DrawQuadApp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Numerics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/04_BufferOffsets/BufferOffsetsApp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Numerics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/04_BufferOffsets/VertexPosition2DColor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Numerics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/05_Cube/CubeApp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Diagnostics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/06_CubeAlphaBlend/CubeAlphaBlendApp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Diagnostics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/07_TexturedCube/TexturedCubeApp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

#nullable disable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Diagnostics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D11/09_Mipmapping/MipmappingApp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Diagnostics;
Expand Down
4 changes: 1 addition & 3 deletions src/Direct3D11/10_Text/10_Text.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>Text</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
</PropertyGroup>

<ItemGroup>
Expand Down
33 changes: 13 additions & 20 deletions src/Direct3D11/10_Text/DrawTextApp.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

//using System.Drawing;
using System.Drawing;
using System.Numerics;
using Vortice.Direct2D1;
using Vortice.Direct3D;
Expand All @@ -12,8 +10,6 @@
using Vortice.Framework;
using Vortice.Mathematics;

namespace Text;

internal class DrawTextApp : D3D11Application
{
private ID3D11Buffer _vertexBuffer;
Expand All @@ -27,23 +23,21 @@ internal class DrawTextApp : D3D11Application
private ID3D11SamplerState _textureSampler;

// text related objects
static ID2D1Device _device2d;
static IDWriteFactory _directWriteFactory;
static IDWriteTextFormat _textFormat;
static ID2D1Factory7 _direct2dFactory;
static ID2D1HwndRenderTarget _renderTarget2dHwnd;
static ID2D1SolidColorBrush _brush;
static ID2D1RenderTarget _renderTarget2d;
private IDWriteFactory _directWriteFactory;
private IDWriteTextFormat _textFormat;
private ID2D1Factory _direct2dFactory;
private ID2D1SolidColorBrush _brush;
private ID2D1RenderTarget _renderTarget2d;

protected override void Initialize()
{
ReadOnlySpan<VertexPositionTexture> source =
[
new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0.0f), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0.0f), new Vector2(1, 0)),
new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0.0f), new Vector2(1, 1)),
new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0.0f), new Vector2(0, 1))
];
[
new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0.0f), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0.0f), new Vector2(1, 0)),
new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0.0f), new Vector2(1, 1)),
new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0.0f), new Vector2(0, 1))
];

_vertexBuffer = Device.CreateBuffer(source, BindFlags.VertexBuffer);

Expand Down Expand Up @@ -112,7 +106,6 @@ protected override void Dispose(bool dispose)
_texture.Dispose();
_textureSampler.Dispose();
_textFormat.Dispose();
_renderTarget2dHwnd?.Dispose();
_brush?.Dispose();
_direct2dFactory.Dispose();
_directWriteFactory.Dispose();
Expand Down Expand Up @@ -142,7 +135,7 @@ protected override void OnRender()

private void DrawText(string text, ID3D11Texture2D target)
{
IDXGISurface1 dxgiSurface = ID3D11Texture2D.QueryInterface<IDXGISurface1>(target);
using IDXGISurface1 dxgiSurface = target.QueryInterface<IDXGISurface1>();
RenderTargetProperties rtvProps = new()
{
DpiX = 0,
Expand Down
37 changes: 18 additions & 19 deletions src/Direct3D11/VideoProcessor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using SharpGen.Runtime;
Expand All @@ -9,25 +9,23 @@
using static System.Console;
using static Vortice.Direct3D11.D3D11;

FeatureLevel[] featureLevels;
List<FeatureLevel> featureLevelsWin10 = new()
{
FeatureLevel[] featureLevelsWin10 =
[
FeatureLevel.Level_12_1,
FeatureLevel.Level_12_0
};
];

List<FeatureLevel> featureLevelsWin8 = new()
{
FeatureLevel[] featureLevelsWin8 =
[
FeatureLevel.Level_11_1
};
];

List<FeatureLevel> featureLevelsWin7 = new()
{
FeatureLevel[] featureLevelsWin7 =
[
FeatureLevel.Level_11_0,
FeatureLevel.Level_10_1,
FeatureLevel.Level_10_0
};

];

VideoProcessorContentDescription videoProcessorContentDescription = new VideoProcessorContentDescription()
{
Expand All @@ -40,23 +38,24 @@

ID3D11VideoProcessor videoProcessor;

List<FeatureLevel> featureLevels = new();
if (OperatingSystem.IsWindowsVersionAtLeast(10))
{
featureLevelsWin10.AddRange(featureLevelsWin8);
featureLevelsWin10.AddRange(featureLevelsWin7);
featureLevels = featureLevelsWin10.ToArray();
featureLevels.AddRange(featureLevelsWin10);
featureLevels.AddRange(featureLevelsWin8);
featureLevels.AddRange(featureLevelsWin7);
}
else if (OperatingSystem.IsWindowsVersionAtLeast(8))
{
featureLevelsWin8.AddRange(featureLevelsWin7);
featureLevels = featureLevelsWin8.ToArray();
featureLevels.AddRange(featureLevelsWin8);
featureLevels.AddRange(featureLevelsWin7);
}
else
{
featureLevels = featureLevelsWin7.ToArray();
featureLevels.AddRange(featureLevelsWin7);
}

Result result = D3D11CreateDevice(null, DriverType.Hardware, DeviceCreationFlags.VideoSupport, featureLevels, out ID3D11Device? device);
Result result = D3D11CreateDevice(null, DriverType.Hardware, DeviceCreationFlags.VideoSupport, featureLevels.ToArray(), out ID3D11Device? device);
if (!result.Success)
{
WriteLine("Failed to create D3D11 Device");
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D12/HelloConstBuffers/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Numerics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D12/HelloTexture/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D12/HelloTriangle/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Numerics;
Expand Down
2 changes: 1 addition & 1 deletion src/Direct3D12/HelloWindow/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using Vortice.Direct3D12;
Expand Down
24 changes: 12 additions & 12 deletions src/MediaFoundation/MediaEngineApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using static Vortice.MediaFoundation.MediaFactory;

static class Program
{
private static IMFMediaEngineEx mediaEngineEx;
private static readonly ManualResetEvent eventReadyToPlay = new(false);
private static bool isMusicStopped;
private static IMFMediaEngineEx? s_mediaEngineEx;
private static readonly ManualResetEvent s_eventReadyToPlay = new(false);
private static bool s_isMusicStopped;

private static void OnPlaybackCallback(MediaEngineEvent playEvent, nuint param1, int param2)
{
Console.Write("PlayBack Event received: {0}", playEvent);
switch (playEvent)
{
case MediaEngineEvent.CanPlay:
eventReadyToPlay.Set();
s_eventReadyToPlay.Set();
break;
case MediaEngineEvent.TimeUpdate:
Console.Write(" {0}", TimeSpan.FromSeconds(mediaEngineEx.CurrentTime));
Console.Write(" {0}", TimeSpan.FromSeconds(s_mediaEngineEx.CurrentTime));

Check warning on line 21 in src/MediaFoundation/MediaEngineApp/Program.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
break;
case MediaEngineEvent.Error:
case MediaEngineEvent.Abort:
case MediaEngineEvent.Ended:
isMusicStopped = true;
s_isMusicStopped = true;
break;
}

Expand All @@ -49,25 +49,25 @@ static void Main()
MediaEngineCreateFlags.AudioOnly, attributes, OnPlaybackCallback);

// Query for MediaEngineEx interface
mediaEngineEx = mediaEngine.QueryInterface<IMFMediaEngineEx>();
s_mediaEngineEx = mediaEngine.QueryInterface<IMFMediaEngineEx>();

string fileName = Path.Combine(AppContext.BaseDirectory, "ergon.wav");
using (MFByteStream mfStream = new(fileName))
{
// Set the source stream
mediaEngineEx.SetSourceFromByteStream(mfStream, fileName);
s_mediaEngineEx.SetSourceFromByteStream(mfStream, fileName);

// Wait for MediaEngine to be ready
if (!eventReadyToPlay.WaitOne(1000))
if (!s_eventReadyToPlay.WaitOne(1000))
{
Console.WriteLine("Unexpected error: Unable to play this file");
}

// Play the music
mediaEngineEx.Play();
s_mediaEngineEx.Play();

// Wait until music is stopped.
while (!isMusicStopped)
while (!s_isMusicStopped)
{
Thread.Sleep(10);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Vortice.Framework/D3D11Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace Vortice.Framework;
/// </summary>
public abstract class D3D11Application : Application
{
private static readonly FeatureLevel[] s_featureLevels = new[]
{
private static readonly FeatureLevel[] s_featureLevels =
[
FeatureLevel.Level_11_1,
FeatureLevel.Level_11_0,
FeatureLevel.Level_10_1,
FeatureLevel.Level_10_0
};
];

private readonly Format _colorFormat;
private readonly Format _depthStencilFormat;
Expand Down
2 changes: 1 addition & 1 deletion src/XAudio2/PlaySound/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Amer Koleci and Contributors.
// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System;
Expand Down

0 comments on commit dc38925

Please sign in to comment.