Skip to content

Commit c2a9772

Browse files
committed
Add basic SDL example
1 parent d2d864a commit c2a9772

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

Silk.NET.sln

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenAL", "OpenAL", "{662A1A
118118
EndProject
119119
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tutorial001.HelloSound", "examples\CSharp\OpenAL\Tutorial001.HelloSound\Tutorial001.HelloSound.csproj", "{946C912C-5BBB-446A-A566-0D1696D19F59}"
120120
EndProject
121+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tutorial001.HelloWindow", "examples\CSharp\SDL\Tutorial001.HelloWindow\Tutorial001.HelloWindow.csproj", "{3444151F-2DE3-41BC-B5E0-EFBF0091C087}"
122+
EndProject
123+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SDL", "SDL", "{96567E92-4A89-4AC8-9F20-C2A3FE644D10}"
124+
EndProject
121125
Global
122126
GlobalSection(SolutionConfigurationPlatforms) = preSolution
123127
Debug|Any CPU = Debug|Any CPU
@@ -196,7 +200,11 @@ Global
196200
{946C912C-5BBB-446A-A566-0D1696D19F59}.Debug|Any CPU.Build.0 = Debug|Any CPU
197201
{946C912C-5BBB-446A-A566-0D1696D19F59}.Release|Any CPU.ActiveCfg = Release|Any CPU
198202
{946C912C-5BBB-446A-A566-0D1696D19F59}.Release|Any CPU.Build.0 = Release|Any CPU
199-
EndGlobalSection
203+
{3444151F-2DE3-41BC-B5E0-EFBF0091C087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
204+
{3444151F-2DE3-41BC-B5E0-EFBF0091C087}.Debug|Any CPU.Build.0 = Debug|Any CPU
205+
{3444151F-2DE3-41BC-B5E0-EFBF0091C087}.Release|Any CPU.ActiveCfg = Release|Any CPU
206+
{3444151F-2DE3-41BC-B5E0-EFBF0091C087}.Release|Any CPU.Build.0 = Release|Any CPU
207+
EndGlobalSection
200208
GlobalSection(SolutionProperties) = preSolution
201209
HideSolutionNode = FALSE
202210
EndGlobalSection
@@ -235,6 +243,8 @@ Global
235243
{946C912C-5BBB-446A-A566-0D1696D19F59} = {662A1AEC-91F2-48FA-AA29-6F27038D30F2}
236244
{5E20252F-E2A0-46C9-BBEF-4CE5C96D0E07} = {DD29EA8F-B1A6-45AA-8D2E-B38DA56D9EF6}
237245
{E5E8FFBF-1319-4D33-B084-E732656E8A04} = {5E20252F-E2A0-46C9-BBEF-4CE5C96D0E07}
246+
{96567E92-4A89-4AC8-9F20-C2A3FE644D10} = {12B4D1CB-8938-4EC4-8895-79C4E6ABD1E8}
247+
{3444151F-2DE3-41BC-B5E0-EFBF0091C087} = {96567E92-4A89-4AC8-9F20-C2A3FE644D10}
238248
EndGlobalSection
239249
GlobalSection(ExtensibilityGlobals) = postSolution
240250
SolutionGuid = {78D2CF6A-60A1-43E3-837B-00B73C9DA384}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Silk.NET.SDL;
5+
6+
if (!Sdl.Init(Sdl.InitVideo))
7+
{
8+
throw new Exception($"SDL failed to initialize: {Sdl.GetError().ReadToString()}");
9+
}
10+
11+
var window = Sdl.CreateWindow("Silk.NET.SDL - Hello Window", 800, 600, Sdl.WindowResizable);
12+
if (window == nullptr)
13+
{
14+
throw new Exception("Failed to create window");
15+
}
16+
17+
try
18+
{
19+
var renderer = Sdl.CreateRenderer(window, nullptr);
20+
{
21+
var shouldRun = true;
22+
while (shouldRun)
23+
{
24+
var e = default(Event);
25+
Sdl.PollEvent(e.AsRef());
26+
27+
if (e.Type == (uint)EventType.Quit)
28+
{
29+
shouldRun = false;
30+
}
31+
32+
Sdl.SetRenderDrawColor(renderer, 0, 255, 0, 255);
33+
Sdl.RenderClear(renderer);
34+
Sdl.RenderPresent(renderer);
35+
}
36+
}
37+
Sdl.DestroyWindow(window);
38+
}
39+
finally
40+
{
41+
Sdl.Quit();
42+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\..\..\sources\SDL\SDL\Silk.NET.SDL.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)