Archived
Private
Public Access
1
0

Initial commit

This commit is contained in:
2022-09-04 12:45:01 +02:00
commit f4a01d6a69
11601 changed files with 4206660 additions and 0 deletions

13
C#/GLEngine/.idea/.idea.GLEngine/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/modules.xml
/.idea.GLEngine.iml
/contentModel.xml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectDictionaryState">
<dictionary name="leon" />
</component>
</project>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="com.jetbrains.rider.android.RiderAndroidMiscFileCreationComponent">
<option name="ENSURE_MISC_FILE_EXISTS" value="true" />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GLEngine\GLEngine.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\bricks.png" />
<Content Include="Assets\logo.png" />
</ItemGroup>
<ItemGroup>
<Reference Include="GLFW.NET, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\GLFW.NET.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,3 @@
using EngineTester;
var game = new TestGame();

View File

@@ -0,0 +1,49 @@
using System.Numerics;
using GLEngine;
using GLEngine.Animations;
using GLEngine.Objects;
using GLEngine.Objects.Components;
using GLEngine.Rendering;
using GLEngine.Resources;
namespace EngineTester {
public class TestGame : Engine {
public TestGame() {
DEBUG_CopyFileToOutput(@"D:\Programmierstuff\C#\GLEngine\glfw.dll");
DEBUG_CopyFolderToOutput(@"D:\Programmierstuff\C#\GLEngine\EngineTester\Assets");
Start(800, 600, "TestGame", true);
}
protected override void Initialize() {}
protected override void InitResources() {
ResourceLoader.InitializeResource("tex_bricks", new Texture("Assets/bricks.png"));
ResourceLoader.InitializeResource("tex_logo", new Texture("Assets/logo.png"));
ResourceLoader.InitializeResource("tex_font", new Texture("Assets/font.png"));
}
protected override void AfterInit() {
Window.SetWindowIcon("Assets/logo.png");
GameObject test = new("test");
test.AddComponent(new MeshRenderer(texture: "tex_logo"));
test.AddComponent(new Animator(new[]{
new Animation("pulse", true, true, new[]{
new Keyframe<Vector3>(new Vector3( 0.3f), 1.0f, 0.0f, KeyframeType.Scale, AnimationFunctions.Smooth),
new Keyframe<Vector3>(new Vector3(-0.3f), 1.0f, 0.0f, KeyframeType.Scale, AnimationFunctions.Smooth)
}),
new Animation("pulseSprite", true, true, new [] {
new Keyframe<string>("tex_bricks", 1.0f, 0.0f, KeyframeType.Sprite, AnimationFunctions.Smooth),
new Keyframe<string>("tex_logo", 1.0f, 0.0f, KeyframeType.Sprite, AnimationFunctions.Smooth),
})
}));
Instantiate(test);
}
protected override void SetWindowHints() {}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@@ -0,0 +1,146 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v5.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v5.0": {
"EngineTester/1.0.0": {
"dependencies": {
"GLEngine": "1.0.0",
"GLFW.NET": "1.0.1.0"
},
"runtime": {
"EngineTester.dll": {}
}
},
"Microsoft.Win32.SystemEvents/6.0.0": {
"runtime": {
"lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
},
"runtimeTargets": {
"runtimes/win/lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"StbiSharp/1.2.1": {
"runtime": {
"lib/netcoreapp3.0/StbiSharp.dll": {
"assemblyVersion": "1.2.1.0",
"fileVersion": "1.2.1.0"
}
},
"runtimeTargets": {
"runtimes/linux-x64/native/libstbi.so": {
"rid": "linux-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/osx-x64/native/libstbi.dylib": {
"rid": "osx-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-x64/native/stbi.dll": {
"rid": "win-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-x64/native/stbi.lib": {
"rid": "win-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
}
}
},
"System.Drawing.Common/6.0.0": {
"dependencies": {
"Microsoft.Win32.SystemEvents": "6.0.0"
},
"runtime": {
"lib/netcoreapp3.1/System.Drawing.Common.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
},
"runtimeTargets": {
"runtimes/unix/lib/netcoreapp3.1/System.Drawing.Common.dll": {
"rid": "unix",
"assetType": "runtime",
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
},
"runtimes/win/lib/netcoreapp3.1/System.Drawing.Common.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"GLEngine/1.0.0": {
"dependencies": {
"StbiSharp": "1.2.1",
"System.Drawing.Common": "6.0.0"
},
"runtime": {
"GLEngine.dll": {}
}
},
"GLFW.NET/1.0.1.0": {
"runtime": {
"GLFW.NET.dll": {
"assemblyVersion": "1.0.1.0",
"fileVersion": "1.0.1.0"
}
}
}
}
},
"libraries": {
"EngineTester/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.Win32.SystemEvents/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-hqTM5628jSsQiv+HGpiq3WKBl2c8v1KZfby2J6Pr7pEPlK9waPdgEO6b8A/+/xn/yZ9ulv8HuqK71ONy2tg67A==",
"path": "microsoft.win32.systemevents/6.0.0",
"hashPath": "microsoft.win32.systemevents.6.0.0.nupkg.sha512"
},
"StbiSharp/1.2.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-jbi94g3UDVAC3vH6jKZmmADH4Z6tGqbcdlyGhT/WZN9UE8OjjvpGFE5zF+UCSmIdya6iJ+Zo5VvxdQywSKN0Uw==",
"path": "stbisharp/1.2.1",
"hashPath": "stbisharp.1.2.1.nupkg.sha512"
},
"System.Drawing.Common/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-NfuoKUiP2nUWwKZN6twGqXioIe1zVD0RIj2t976A+czLHr2nY454RwwXs6JU9Htc6mwqL6Dn/nEL3dpVf2jOhg==",
"path": "system.drawing.common/6.0.0",
"hashPath": "system.drawing.common.6.0.0.nupkg.sha512"
},
"GLEngine/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"GLFW.NET/1.0.1.0": {
"type": "reference",
"serviceable": false,
"sha512": ""
}
}
}

View File

@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\leon\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\leon\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
]
}
}

View File

@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v5.0", FrameworkDisplayName = "")]

View File

@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("EngineTester")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("EngineTester")]
[assembly: System.Reflection.AssemblyTitleAttribute("EngineTester")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Von der MSBuild WriteCodeFragment-Klasse generiert.

View File

@@ -0,0 +1 @@
a2b065fcbdcc4650ab91de8429060b8b73bdc329

View File

@@ -0,0 +1,10 @@
is_global = true
build_property.TargetFramework = net5.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = EngineTester
build_property.ProjectDir = D:\Programmierstuff\C#\GLEngine\EngineTester\

View File

@@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View File

@@ -0,0 +1 @@
e38591d4e0684448673b8b7c8fa003712fd1185e

View File

@@ -0,0 +1,30 @@
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.csproj.AssemblyReference.cache
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.GeneratedMSBuildEditorConfig.editorconfig
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.AssemblyInfoInputs.cache
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.AssemblyInfo.cs
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.csproj.CoreCompileInputs.cache
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\EngineTester.exe
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\EngineTester.deps.json
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\EngineTester.runtimeconfig.json
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\EngineTester.runtimeconfig.dev.json
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\EngineTester.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\EngineTester.pdb
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\StbiSharp.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\runtimes\linux-x64\native\libstbi.so
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\runtimes\osx-x64\native\libstbi.dylib
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\runtimes\win-x64\native\stbi.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\runtimes\win-x64\native\stbi.lib
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\GLEngine.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\GLFW.NET.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\GLEngine.pdb
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.csproj.CopyComplete
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\refint\EngineTester.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.pdb
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\EngineTester.genruntimeconfig.cache
D:\Programmierstuff\C#\GLEngine\EngineTester\obj\Debug\net5.0\ref\EngineTester.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\Microsoft.Win32.SystemEvents.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\System.Drawing.Common.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\runtimes\win\lib\netcoreapp3.1\Microsoft.Win32.SystemEvents.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\runtimes\unix\lib\netcoreapp3.1\System.Drawing.Common.dll
D:\Programmierstuff\C#\GLEngine\EngineTester\bin\Debug\net5.0\runtimes\win\lib\netcoreapp3.1\System.Drawing.Common.dll

View File

@@ -0,0 +1 @@
ad96a66d967d27f5a17efbb4a8848c40e161f575

Binary file not shown.

View File

@@ -0,0 +1,138 @@
{
"format": 1,
"restore": {
"D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj": {}
},
"projects": {
"D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj",
"projectName": "EngineTester",
"projectPath": "D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj",
"packagesPath": "C:\\Users\\leon\\.nuget\\packages\\",
"outputPath": "D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\leon\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net5.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"projectReferences": {
"D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj": {
"projectPath": "D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj"
}
}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.301\\RuntimeIdentifierGraph.json"
}
}
},
"D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj",
"projectName": "GLEngine",
"projectPath": "D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj",
"packagesPath": "C:\\Users\\leon\\.nuget\\packages\\",
"outputPath": "D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\leon\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net5.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"dependencies": {
"StbiSharp": {
"target": "Package",
"version": "[1.2.1, )"
},
"System.Drawing.Common": {
"target": "Package",
"version": "[6.0.0, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.301\\RuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\leon\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.2.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\leon\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@@ -0,0 +1,256 @@
{
"version": 3,
"targets": {
"net5.0": {
"Microsoft.Win32.SystemEvents/6.0.0": {
"type": "package",
"compile": {
"lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll": {}
},
"runtime": {
"lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
},
"runtimeTargets": {
"runtimes/win/lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
"StbiSharp/1.2.1": {
"type": "package",
"compile": {
"lib/netcoreapp3.0/StbiSharp.dll": {}
},
"runtime": {
"lib/netcoreapp3.0/StbiSharp.dll": {}
},
"runtimeTargets": {
"runtimes/linux-x64/native/libstbi.so": {
"assetType": "native",
"rid": "linux-x64"
},
"runtimes/osx-x64/native/libstbi.dylib": {
"assetType": "native",
"rid": "osx-x64"
},
"runtimes/win-x64/native/stbi.dll": {
"assetType": "native",
"rid": "win-x64"
},
"runtimes/win-x64/native/stbi.lib": {
"assetType": "native",
"rid": "win-x64"
}
}
},
"System.Drawing.Common/6.0.0": {
"type": "package",
"dependencies": {
"Microsoft.Win32.SystemEvents": "6.0.0"
},
"compile": {
"lib/netcoreapp3.1/System.Drawing.Common.dll": {}
},
"runtime": {
"lib/netcoreapp3.1/System.Drawing.Common.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
},
"runtimeTargets": {
"runtimes/unix/lib/netcoreapp3.1/System.Drawing.Common.dll": {
"assetType": "runtime",
"rid": "unix"
},
"runtimes/win/lib/netcoreapp3.1/System.Drawing.Common.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
"GLEngine/1.0.0": {
"type": "project",
"framework": ".NETCoreApp,Version=v5.0",
"dependencies": {
"StbiSharp": "1.2.1",
"System.Drawing.Common": "6.0.0"
},
"compile": {
"bin/placeholder/GLEngine.dll": {}
},
"runtime": {
"bin/placeholder/GLEngine.dll": {}
}
}
}
},
"libraries": {
"Microsoft.Win32.SystemEvents/6.0.0": {
"sha512": "hqTM5628jSsQiv+HGpiq3WKBl2c8v1KZfby2J6Pr7pEPlK9waPdgEO6b8A/+/xn/yZ9ulv8HuqK71ONy2tg67A==",
"type": "package",
"path": "microsoft.win32.systemevents/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/Microsoft.Win32.SystemEvents.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/net461/Microsoft.Win32.SystemEvents.dll",
"lib/net461/Microsoft.Win32.SystemEvents.xml",
"lib/net6.0/Microsoft.Win32.SystemEvents.dll",
"lib/net6.0/Microsoft.Win32.SystemEvents.xml",
"lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll",
"lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.xml",
"lib/netstandard2.0/Microsoft.Win32.SystemEvents.dll",
"lib/netstandard2.0/Microsoft.Win32.SystemEvents.xml",
"microsoft.win32.systemevents.6.0.0.nupkg.sha512",
"microsoft.win32.systemevents.nuspec",
"runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.dll",
"runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.xml",
"runtimes/win/lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll",
"runtimes/win/lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.xml",
"useSharedDesignerContext.txt"
]
},
"StbiSharp/1.2.1": {
"sha512": "jbi94g3UDVAC3vH6jKZmmADH4Z6tGqbcdlyGhT/WZN9UE8OjjvpGFE5zF+UCSmIdya6iJ+Zo5VvxdQywSKN0Uw==",
"type": "package",
"path": "stbisharp/1.2.1",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.txt",
"lib/netcoreapp2.0/StbiSharp.dll",
"lib/netcoreapp3.0/StbiSharp.dll",
"lib/netstandard2.0/StbiSharp.dll",
"runtimes/linux-x64/native/libstbi.so",
"runtimes/osx-x64/native/libstbi.dylib",
"runtimes/win-x64/native/stbi.dll",
"runtimes/win-x64/native/stbi.lib",
"stbisharp.1.2.1.nupkg.sha512",
"stbisharp.nuspec"
]
},
"System.Drawing.Common/6.0.0": {
"sha512": "NfuoKUiP2nUWwKZN6twGqXioIe1zVD0RIj2t976A+czLHr2nY454RwwXs6JU9Htc6mwqL6Dn/nEL3dpVf2jOhg==",
"type": "package",
"path": "system.drawing.common/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/System.Drawing.Common.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net461/System.Drawing.Common.dll",
"lib/net461/System.Drawing.Common.xml",
"lib/net6.0/System.Drawing.Common.dll",
"lib/net6.0/System.Drawing.Common.xml",
"lib/netcoreapp3.1/System.Drawing.Common.dll",
"lib/netcoreapp3.1/System.Drawing.Common.xml",
"lib/netstandard2.0/System.Drawing.Common.dll",
"lib/netstandard2.0/System.Drawing.Common.xml",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"runtimes/unix/lib/net6.0/System.Drawing.Common.dll",
"runtimes/unix/lib/net6.0/System.Drawing.Common.xml",
"runtimes/unix/lib/netcoreapp3.1/System.Drawing.Common.dll",
"runtimes/unix/lib/netcoreapp3.1/System.Drawing.Common.xml",
"runtimes/win/lib/net6.0/System.Drawing.Common.dll",
"runtimes/win/lib/net6.0/System.Drawing.Common.xml",
"runtimes/win/lib/netcoreapp3.1/System.Drawing.Common.dll",
"runtimes/win/lib/netcoreapp3.1/System.Drawing.Common.xml",
"system.drawing.common.6.0.0.nupkg.sha512",
"system.drawing.common.nuspec",
"useSharedDesignerContext.txt"
]
},
"GLEngine/1.0.0": {
"type": "project",
"path": "../GLEngine/GLEngine.csproj",
"msbuildProject": "../GLEngine/GLEngine.csproj"
}
},
"projectFileDependencyGroups": {
"net5.0": [
"GLEngine >= 1.0.0"
]
},
"packageFolders": {
"C:\\Users\\leon\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj",
"projectName": "EngineTester",
"projectPath": "D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj",
"packagesPath": "C:\\Users\\leon\\.nuget\\packages\\",
"outputPath": "D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\leon\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net5.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"projectReferences": {
"D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj": {
"projectPath": "D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj"
}
}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.301\\RuntimeIdentifierGraph.json"
}
}
}
}

View File

@@ -0,0 +1,12 @@
{
"version": 2,
"dgSpecHash": "ZNtO/KpyUzATBlbzlwhPu5nA8ZSiyU5tn5v5navOz32SpN0JEgy4maW/YA6xYKOvhLGEbPiy1dexdQaWI7SppQ==",
"success": true,
"projectFilePath": "D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj",
"expectedPackageFiles": [
"C:\\Users\\leon\\.nuget\\packages\\microsoft.win32.systemevents\\6.0.0\\microsoft.win32.systemevents.6.0.0.nupkg.sha512",
"C:\\Users\\leon\\.nuget\\packages\\stbisharp\\1.2.1\\stbisharp.1.2.1.nupkg.sha512",
"C:\\Users\\leon\\.nuget\\packages\\system.drawing.common\\6.0.0\\system.drawing.common.6.0.0.nupkg.sha512"
],
"logs": []
}

View File

@@ -0,0 +1 @@
"restore":{"projectUniqueName":"D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj","projectName":"EngineTester","projectPath":"D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\EngineTester.csproj","outputPath":"D:\\Programmierstuff\\C#\\GLEngine\\EngineTester\\obj\\","projectStyle":"PackageReference","fallbackFolders":["C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"],"originalTargetFrameworks":["net5.0"],"sources":{"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\":{},"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net5.0":{"targetAlias":"net5.0","projectReferences":{"D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj":{"projectPath":"D:\\Programmierstuff\\C#\\GLEngine\\GLEngine\\GLEngine.csproj"}}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net5.0":{"targetAlias":"net5.0","imports":["net461","net462","net47","net471","net472","net48"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"C:\\Program Files\\dotnet\\sdk\\6.0.301\\RuntimeIdentifierGraph.json"}}

View File

@@ -0,0 +1 @@
16557194729526870

22
C#/GLEngine/GLEngine.sln Normal file
View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GLEngine", "GLEngine\GLEngine.csproj", "{D793154D-9259-451A-AE84-2930383339CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EngineTester", "EngineTester\EngineTester.csproj", "{6983DB43-FA53-4691-A892-C28E7A434634}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D793154D-9259-451A-AE84-2930383339CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D793154D-9259-451A-AE84-2930383339CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D793154D-9259-451A-AE84-2930383339CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D793154D-9259-451A-AE84-2930383339CA}.Release|Any CPU.Build.0 = Release|Any CPU
{6983DB43-FA53-4691-A892-C28E7A434634}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6983DB43-FA53-4691-A892-C28E7A434634}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6983DB43-FA53-4691-A892-C28E7A434634}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6983DB43-FA53-4691-A892-C28E7A434634}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=D_003A_005CProgrammierstuff_005CC_0023_005CGLEngine_005CGLFW_002ENET_002Edll/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -0,0 +1,239 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using GLEngine.Extensions;
using GLEngine.Objects;
using GLEngine.Objects.Components;
using GLEngine.Rendering;
using GLEngine.Resources;
using OpenGL;
namespace GLEngine.Animations {
public class Animation {
public readonly string Name;
public readonly bool Autostart;
public bool Loop;
protected GameObject Object;
protected Animatable<Vector3> Position = new();
protected Animatable<Vector3> Scale = new();
protected Animatable<Vector3> Rotation = new();
protected Animatable<Texture> Sprite = new();
protected bool Started = false;
protected MeshRenderer Renderer;
protected Mesh Mesh;
public Animation(string name, bool loop, bool autostart, params Keyframe<Vector3>[] keyframes) {
List<Keyframe<Vector3>> vectors = new();
List<Keyframe<Vector3>> scales = new();
List<Keyframe<Vector3>> rots = new();
foreach (var keyframe in keyframes) {
switch (keyframe.Type) {
case KeyframeType.Position:
vectors.Add(keyframe);
break;
case KeyframeType.Scale:
scales.Add(keyframe);
break;
case KeyframeType.Rotation:
rots.Add(keyframe);
break;
default:
throw new ArgumentException(keyframe.Type + " is not animatable!");
}
}
Position.Keyframes = vectors.ToArray();
Scale.Keyframes = scales.ToArray();
Rotation.Keyframes = rots.ToArray();
Name = name;
Autostart = autostart;
Loop = loop;
}
public Animation(string name, bool loop, bool autostart, params Keyframe<Texture>[] keyframes) {
Sprite.Keyframes = keyframes;
Name = name;
Autostart = autostart;
Loop = loop;
}
public Animation(string name, bool loop, bool autostart, params Keyframe<string>[] keyframes) {
Keyframe<Texture>[] textures = new Keyframe<Texture>[keyframes.Length];
for (int i = 0; i < keyframes.Length; i++) {
Keyframe<string> keyframe = keyframes[i];
Texture texture = ResourceLoader.GetResource<Texture>(keyframe.Value);
textures[i] = new Keyframe<Texture>(texture, keyframe.Time, keyframe.Offset, keyframe.Type,
keyframe.AnimationFunction);
}
Sprite.Keyframes = textures;
Name = name;
Autostart = autostart;
Loop = loop;
}
public void Initialize(GameObject gameObject) {
Object = gameObject;
if (Autostart) Start();
}
public bool Running => Position.Running | Scale.Running | Rotation.Running | Sprite.Running;
public void Start() {
Stop();
Position.Reset(Object.Transform.Position.CreateCopy());
Scale.Reset(Object.Transform.Scale.CreateCopy());
Rotation.Reset(Object.Transform.Rotation.CreateCopy());
if (Sprite.Keyframes.Length != 0) {
if (!Object.HasComponent<MeshRenderer>())
throw new Exception($"Object {Object.Name} does not have a MeshRenderer but a Sprite animation attached!");
Renderer = Object.GetComponent<MeshRenderer>();
Mesh = new Mesh(DrawMode.Stream);
Mesh.Load();
foreach (var frame in Sprite.Keyframes) {
frame.Value.Load();
}
Sprite.Reset(Renderer.Texture);
}
Started = true;
}
public void Stop() {
Position.Running = false;
Scale.Running = false;
Rotation.Running = false;
if (Mesh != null) {
Mesh.Delete();
Mesh = null;
}
Started = false;
}
public void Update() {
if (Loop && Started && !Running) Start();
if (!Running && Started) Stop();
if (Position.Running)
Object.Transform.Position = UpdateAnimatableVector(Position, Object.Transform.Position);
if (Scale.Running)
Object.Transform.Scale = UpdateAnimatableVector(Scale, Object.Transform.Scale);
if (Rotation.Running)
Object.Transform.Rotation = UpdateAnimatableVector(Rotation, Object.Transform.Rotation);
}
public void Render() {
if (!Sprite.Running) return;
Keyframe<Texture> frame = Sprite.CurrentFrame;
float deltaTime = Time.ElapsedTime - Sprite.StartTime - frame.Offset;
if (deltaTime >= frame.Time) {
Sprite.CurrentFrameIndex++;
Sprite.Origin = frame.Value;
Sprite.StartTime = Time.ElapsedTime;
if (Sprite.CurrentFrameIndex >= Sprite.Keyframes.Length)
Sprite.Running = false;
Renderer.Texture = frame.Value;
if (frame.Time == 0) return;
}
if (deltaTime <= 0) return;
float progress = deltaTime / frame.Time;
float lerp = frame.AnimationFunction.GetProgres(progress);
Vector4 color = new Vector4(Vector3.One, lerp);
float[] meshVerts = Renderer.Mesh.Data;
float[] verts = new float[meshVerts.Length];
for (int i = 0; i < verts.Length; i += 9) {
verts[i] = meshVerts[i];
verts[i + 1] = meshVerts[i + 1];
verts[i + 2] = meshVerts[i + 2];
verts[i + 3] = color.X;
verts[i + 4] = color.Y;
verts[i + 5] = color.Z;
verts[i + 6] = color.W;
verts[i + 7] = meshVerts[i + 7];
verts[i + 8] = meshVerts[i + 8];
}
Mesh.UpdateMesh(verts);
GL.glEnable(GL.GL_BLEND);
GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
frame.Value.Bind();
Renderer.Shader.Bind();
Mesh.Render();
Renderer.Shader.Unbind();
frame.Value.Unbind();
}
protected Vector3 UpdateAnimatableVector(Animatable<Vector3> animatable, Vector3 origin) {
Keyframe<Vector3> frame = animatable.CurrentFrame;
float deltaTime = Time.ElapsedTime - animatable.StartTime - frame.Offset;
if (deltaTime >= frame.Time) {
animatable.CurrentFrameIndex++;
animatable.Origin = animatable.Origin + frame.Value;
animatable.StartTime = Time.ElapsedTime;
if (animatable.CurrentFrameIndex >= animatable.Keyframes.Length)
animatable.Running = false;
return animatable.Origin;
}
if (deltaTime <= 0) return origin;
Vector3 motion = frame.Value;
float progress = deltaTime / frame.Time;
motion *= frame.AnimationFunction.GetProgres(progress);
return animatable.Origin + motion;
}
protected class Animatable<T> {
public Keyframe<T>[] Keyframes { get; set; } = Array.Empty<Keyframe<T>>();
public bool Running { get; set; }
public int CurrentFrameIndex { get; set; }
public float StartTime { get; set; }
public T Origin { get; set; }
public Keyframe<T> CurrentFrame => Keyframes[CurrentFrameIndex];
public void Reset(T original) {
Running = Keyframes.Length != 0;
CurrentFrameIndex = 0;
StartTime = Time.ElapsedTime;
Origin = original;
}
}
}
}

View File

@@ -0,0 +1,14 @@
namespace GLEngine.Animations {
public class AnimationFunctions {
public static readonly IAnimationFunction Linear = new LinearAnimation();
public static readonly IAnimationFunction Smooth = new SmoothAnimation();
private class LinearAnimation : IAnimationFunction {
public float GetProgres(float state) => state;
}
private class SmoothAnimation : IAnimationFunction {
public float GetProgres(float state) => state * state * (3.0f - 2.0f * state);
}
}
}

View File

@@ -0,0 +1,5 @@
namespace GLEngine.Animations {
public interface IAnimationFunction {
public float GetProgres(float state);
}
}

View File

@@ -0,0 +1,28 @@
namespace GLEngine.Animations {
public readonly struct Keyframe<T> {
public readonly T Value;
public readonly float Time;
public readonly float Offset;
public readonly KeyframeType Type;
public readonly IAnimationFunction AnimationFunction;
public Keyframe(T value, float time, float offset, KeyframeType type, IAnimationFunction animationFunction = null) {
animationFunction ??= AnimationFunctions.Linear;
Value = value;
Time = time;
Offset = offset;
Type = type;
AnimationFunction = animationFunction;
}
}
public enum KeyframeType : byte {
Position = 0x00,
Scale = 0x01,
Rotation = 0x02,
Sprite = 0x03
}
}

View File

@@ -0,0 +1,162 @@
using System.Drawing;
using System.IO;
using System.Numerics;
using GLEngine.Extensions;
using GLEngine.Objects;
using GLEngine.Rendering;
using GLEngine.Resources;
using GLFW;
using static OpenGL.GL;
namespace GLEngine {
public abstract class Engine {
public static Engine Instance { get; private set; }
public GameWindow Window { get; private set; }
public Scene CurrentScene { get; private set; }
protected void Start(int width, int height, string title, bool vsync) {
Instance = this;
CurrentScene = new Scene();
Initialize();
Glfw.Init();
SetWindowHints();
Glfw.WindowHint(Hint.ContextVersionMajor, 3);
Glfw.WindowHint(Hint.ContextVersionMinor, 3);
Glfw.WindowHint(Hint.OpenglProfile, Profile.Core);
Window = new GameWindow(width, height, title, vsync);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
LoadDefaultResources();
InitResources();
AfterInit();
Awake();
while (!Window.IsClosing) {
Time.DeltaTime = (float)Glfw.Time - Time.ElapsedTime;
Time.ElapsedTime = (float)Glfw.Time;
Glfw.PollEvents();
Update();
Render();
}
Destroy();
ResourceLoader.DeleteAllResources();
Window.Close();
}
public void SwapScene(Scene newScene) {
CurrentScene.Destroy();
CurrentScene = newScene;
CurrentScene.Awake();
}
public GameObject Instantiate(GameObject gameObject) => CurrentScene.Instantiate(gameObject);
public void Destory(GameObject gameObject) => CurrentScene.Destory(gameObject);
protected abstract void Initialize();
protected abstract void InitResources();
protected abstract void AfterInit();
protected abstract void SetWindowHints();
private void Awake() => CurrentScene.Awake();
private void Update() => CurrentScene.Update();
private void Render() {
glClear(GL_COLOR_BUFFER_BIT);
CurrentScene.Render();
Window.SwapBuffers();
}
private void Destroy() => CurrentScene.Destroy();
private void LoadDefaultResources() {
ResourceLoader.InitializeResource(Shader.Default, new Shader(@"
#type vertex
#version 330 core
layout (location = 0) in vec2 aPosition;
layout (location = 1) in vec4 aColor;
layout (location = 2) in vec2 aUV;
out vec4 vertexColor;
out vec2 uv;
uniform mat4 projection;
uniform mat4 model;
void main() {
vertexColor = aColor;
uv = aUV;
gl_Position = projection * model * vec4(aPosition.xy, 0, 1.0);
}
#type fragment
#version 330 core
out vec4 FragColor;
in vec4 vertexColor;
in vec2 uv;
uniform sampler2D texture0;
void main() {
FragColor = texture(texture0, uv) * vertexColor;
}
", false));
ResourceLoader.InitializeResource(Mesh.Default, new Mesh {
Vertices = new [] {
new Vector3(-0.5f, 0.5f, 1.0f),
new Vector3( 0.5f, 0.5f, 1.0f),
new Vector3(-0.5f, -0.5f, 1.0f),
new Vector3( 0.5f, -0.5f, 1.0f)
},
Colors = new []{ Color.White },
UVs = new [] {
new Vector2(0.0f, 1.0f),
new Vector2(1.0f, 1.0f),
new Vector2(0.0f, 0.0f),
new Vector2(1.0f, 0.0f)
},
Triangles = new [] {
0, 1, 2,
1, 3, 2
}
});
ResourceLoader.InitializeResource(Texture.Default, new Texture(null));
}
protected void DEBUG_CopyFolderToOutput(string folder) {
#if DEBUG
var info = new DirectoryInfo(folder);
info.CopyTo(Directory.GetCurrentDirectory() + "/" + info.Name, true, true);
#endif
}
protected void DEBUG_CopyFileToOutput(string file) {
#if DEBUG
var info = new FileInfo(file);
info.CopyTo(Directory.GetCurrentDirectory() + "/" + info.Name, true);
#endif
}
}
public interface IGameEvents {
public void Awake();
public void Update();
public void Render();
public void Destroy();
}
}

View File

@@ -0,0 +1,26 @@
using System.Drawing;
namespace GLEngine.Extensions {
public static class ColorExtensions {
private static float Map(float value, float min, float max, float mMin, float mMax) {
float norm = (value - min) / (max - min);
return (mMax - mMin) * norm + mMin;
}
public static float GetRed(this Color color) {
return Map(color.R, 0, 255, 0, 1);
}
public static float GetGreen(this Color color) {
return Map(color.G, 0, 255, 0, 1);
}
public static float GetBlue(this Color color) {
return Map(color.B, 0, 255, 0, 1);
}
public static float GetAlpha(this Color color) {
return Map(color.A, 0, 255, 0, 1);
}
}
}

View File

@@ -0,0 +1,30 @@
using System.IO;
namespace GLEngine.Extensions {
public static class DirectoryInfoExtensions {
public static void CopyTo(this DirectoryInfo dir, string destinationDir, bool overwrite, bool recursive) {
if (overwrite && Directory.Exists(destinationDir))
Directory.Delete(destinationDir, true);
if (!dir.Exists)
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
DirectoryInfo[] dirs = dir.GetDirectories();
Directory.CreateDirectory(destinationDir);
foreach (FileInfo file in dir.GetFiles()) {
string targetFilePath = Path.Combine(destinationDir, file.Name);
file.CopyTo(targetFilePath);
}
if (recursive) {
foreach (DirectoryInfo subDir in dirs) {
string newDestinationDir = Path.Combine(destinationDir, subDir.Name);
CopyTo(subDir, newDestinationDir, true, overwrite);
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
using System.Numerics;
namespace GLEngine.Extensions {
public static class Vector3Extensions {
public static Vector3 CreateCopy(this Vector3 vector) {
return new Vector3(vector.X, vector.Y, vector.Z);
}
}
}

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="GLFW.NET, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\GLFW.NET.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StbiSharp" Version="1.2.1" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,52 @@
using System.Collections.Generic;
using GLEngine.Animations;
namespace GLEngine.Objects.Components {
public class Animator : ObjectComponent {
private readonly Dictionary<string, Animation> _animations = new();
private bool _initialized = false;
public Animator(params Animation[] animations) {
foreach (var animation in animations) {
_animations.Add(animation.Name, animation);
}
}
public override void Awake() {
foreach (var animation in _animations.Values) {
animation.Initialize(GameObject);
}
_initialized = true;
}
public override void Update() {
foreach (var animation in _animations.Values) {
animation.Update();
}
}
public override void Render() {
foreach (var animation in _animations.Values) {
animation.Render();
}
}
public override void Destroy() {
foreach (var animation in _animations.Values) {
animation.Stop();
}
}
public Animation this[string name] {
get => _animations[name];
set {
_animations.Remove(value.Name);
if (!_initialized)
value.Initialize(GameObject);
_animations.Add(value.Name, value);
}
}
}
}

View File

@@ -0,0 +1,44 @@
using GLEngine.Rendering;
using GLEngine.Resources;
namespace GLEngine.Objects.Components {
public class MeshRenderer : ObjectComponent {
public Shader Shader { get; set; }
public Texture Texture { get; set; }
public Mesh Mesh { get; set; }
public MeshRenderer(string mesh = Mesh.Default, string shader = Shader.Default, string texture = Texture.Default) {
Texture = ResourceLoader.GetResource<Texture>(texture);
Shader = ResourceLoader.GetResource<Shader>(shader);
Mesh = ResourceLoader.GetResource<Mesh>(mesh);
}
public override void Awake() {
Shader.Load();
Texture.Load();
Mesh.Load();
}
public override void Update() {}
public override void Render() {
Texture.Bind();
Shader.Bind();
Shader.SetMatrix4X4("model", GameObject.Model);
Shader.SetMatrix4X4("projection", GameObject.Scene.Camera.Projection);
Mesh.Render();
Shader.Unbind();
Texture.Unbind();
}
public override void Destroy() {
Texture.Delete();
Shader.Delete();
Mesh.Delete();
}
}
}

View File

@@ -0,0 +1,8 @@
namespace GLEngine.Objects.Components {
public abstract class MonoBehavior : ObjectComponent {
public override void Render() {}
public override void Awake() {}
public override void Update() {}
public override void Destroy() {}
}
}

View File

@@ -0,0 +1,252 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Numerics;
using System.Text;
using System.Text.Json;
using GLEngine.Rendering;
using GLEngine.Resources;
using static OpenGL.GL;
namespace GLEngine.Objects.Components {
public class TextRenderer : ObjectComponent {
public string Text { get; set; }
public TextAlign TextAlign { get; set; }
public Vector2 Size { get; private set; }
public Color TextColor { get; set; }
public MeshRenderer Renderer { get; }
private TextSettings Settings { get; }
private string CurrentText { get; set; }
public TextRenderer(string fontImage, string text, Color textColor, TextSettings settings = null, DrawMode renderingMode = DrawMode.Static) {
settings ??= new TextSettings();
Settings = settings;
TextColor = textColor;
Text = text;
TextAlign = TextAlign.Center;
string meshRes = "mesh_" + Guid.NewGuid();
ResourceLoader.InitializeResource(meshRes, new Mesh(renderingMode));
Renderer = new MeshRenderer(meshRes, Shader.Default, fontImage);
}
public override void Awake() {
Renderer.GameObject = GameObject;
Renderer.Awake();
}
public override void Update() {
if (CurrentText == Text) return;
CurrentText = Text;
float x = 0;
float y = 0;
float uW = Settings.GlyphWidth / (float)Renderer.Texture.Width;
float vH = Settings.GlyphHeight / (float)Renderer.Texture.Height;
float w = Settings.GlyphWidth / (float)Settings.GlyphHeight;
const float h = 1.0f;
//Calculate Size
for (int n = 0; n < Text.Length; n++) {
char idx = Text[n];
if (idx == '\n') {
y += 1;
x = 0;
continue;
}
if (idx == '\t') {
x += (w + Settings.CharXSpacing) * 4;
continue;
}
x += w + Settings.CharXSpacing;
}
Size = new Vector2(x, y + h);
//Apply TextAlign
switch (TextAlign) {
case TextAlign.Center:
x = -(Size.X / 2);
y = -(Size.Y / 2);
break;
case TextAlign.Left:
x = 0;
y = -(Size.Y / 2);
break;
case TextAlign.Right:
x = -Size.X;
y = -(Size.Y / 2);
break;
case TextAlign.Top:
x = -(Size.X / 2);
y = 0;
break;
case TextAlign.Bottom:
x = -(Size.X / 2);
y = -Size.Y;
break;
case TextAlign.TopLeft:
x = 0;
y = 0;
break;
case TextAlign.TopRight:
x = -Size.X;
y = 0;
break;
case TextAlign.BottomLeft:
x = 0;
y = -Size.Y;
break;
case TextAlign.BottomRight:
x = -Size.X;
y = -Size.Y;
break;
default:
throw new ArgumentException("The TextAlign " + TextAlign + " does not exist!");
}
//Generate Mesh
List<float> vertices = new();
for (int n = 0; n < Text.Length; n++) {
char idx = Text[n];
if (idx == '\n') {
y += 1;
x = 0;
continue;
}
if (idx == '\t') {
x += (w + Settings.CharXSpacing) * 4;
continue;
}
float u = (idx % Settings.GlyphsPerLine) * uW + Settings.TexCoordOffset;
float v = (idx / Settings.GlyphsPerLine) * vH + Settings.TexCoordOffset;
vertices.AddRange(new[] {
x, y + h, 1.0f, TextColor.R, TextColor.G, TextColor.B, TextColor.A, u, v + vH,
x + w, y + h, 1.0f, TextColor.R, TextColor.G, TextColor.B, TextColor.A, u + uW, v + vH,
x, y, 1.0f, TextColor.R, TextColor.G, TextColor.B, TextColor.A, u, v,
x + w, y, 1.0f, TextColor.R, TextColor.G, TextColor.B, TextColor.A, u + uW, v,
x + w, y + h, 1.0f, TextColor.R, TextColor.G, TextColor.B, TextColor.A, u + uW, v + vH,
x, y, 1.0f, TextColor.R, TextColor.G, TextColor.B, TextColor.A, u, v
});
x += w + Settings.CharXSpacing;
}
Renderer.Mesh.UpdateMesh(vertices.ToArray());
}
public override void Render() {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Renderer.Render();
}
public override void Destroy() {
Renderer.Destroy();
}
public static TextSettings CompileFont(string fontNameOrUrl, string output, TextSettings settings = null) {
#pragma warning disable CA1416
if (settings is null)
settings = new TextSettings();
int bitmapWidth = settings.GlyphsPerLine * settings.GlyphWidth;
int bitmapHeight = settings.GlyphLineCount * settings.GlyphHeight;
using Bitmap texture = new Bitmap(bitmapWidth, bitmapHeight, PixelFormat.Format32bppArgb);
Font font;
if (File.Exists(fontNameOrUrl))
{
var collection = new PrivateFontCollection();
collection.AddFontFile(fontNameOrUrl);
var fontFamily = new FontFamily(Path.GetFileNameWithoutExtension(fontNameOrUrl), collection);
font = new Font(fontFamily, settings.FontSize);
}
else {
font = new Font(new FontFamily(fontNameOrUrl), settings.FontSize);
}
using (var g = Graphics.FromImage(texture)) {
if (settings.BitmapFont) {
g.SmoothingMode = SmoothingMode.None;
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
}
else {
g.SmoothingMode = SmoothingMode.HighQuality;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
}
for (int p = 0; p < settings.GlyphLineCount; p++) {
for (int n = 0; n < settings.GlyphsPerLine; n++) {
char c = (char)(n + p * settings.GlyphsPerLine);
g.DrawString(c.ToString(), font, Brushes.White,
n * settings.GlyphWidth + settings.AtlasOffsetX,
p * settings.GlyphHeight + settings.AtlasOffsetY);
}
}
}
texture.Save(output);
return settings;
#pragma warning restore CA1416
}
}
[Serializable]
public class TextSettings {
public int GlyphsPerLine { get; set; } = 16;
public int GlyphLineCount { get; set; } = 16;
public int GlyphWidth { get; set; } = 30;
public int GlyphHeight { get; set; } = 48;
public float CharXSpacing { get; set; } = 0.0f;
// Used to offset rendering glyphs to bitmap
public int AtlasOffsetX { get; set; } = -3;
public int AtlasOffsetY { get; set; } = -1;
public int FontSize { get; set; } = 35;
public bool BitmapFont { get; set; } = false;
public float TexCoordOffset { get; set; } = 0.005f;
public void Save(string file) {
string json = JsonSerializer.Serialize(this, new JsonSerializerOptions {WriteIndented = true});
File.WriteAllText(file, json, Encoding.UTF8);
}
public static TextSettings Load(string file) {
string text = File.ReadAllText(file, Encoding.UTF8);
return JsonSerializer.Deserialize<TextSettings>(text);
}
}
public enum TextAlign : byte {
Center = 0x00,
Left = 0x01,
Right = 0x02,
Top = 0x03,
Bottom = 0x04,
TopLeft = 0x05,
TopRight = 0x06,
BottomLeft = 0x07,
BottomRight = 0x08
}
}

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using GLEngine.Objects.Components;
using GLEngine.Rendering;
namespace GLEngine.Objects {
public class GameObject : IGameEvents {
public string Name { get; }
public int Layer { get; set; }
public Transform Transform { get; }
public Scene Scene { get; set; }
private bool _loaded = false;
private List<ObjectComponent> Components { get; set; }
public Matrix4x4 Model { get; private set; }
public GameObject(string name, int layer = 0) {
Name = name;
Layer = layer;
Transform = new Transform {
Position = Vector3.Zero,
Scale = Vector3.One,
Rotation = Vector3.Zero
};
Components = new List<ObjectComponent>();
}
public void Awake() {
if (_loaded) return;
_loaded = true;
Components.ForEach(c => c.Awake());
}
public void Update() {
Matrix4x4 trans = Matrix4x4.CreateTranslation(Transform.Position.X, -Transform.Position.Y, Transform.Position.Z);
Matrix4x4 sca = Matrix4x4.CreateScale(Transform.Scale);
Matrix4x4 rotX = Matrix4x4.CreateRotationX(Transform.Rotation.X);
Matrix4x4 rotY = Matrix4x4.CreateRotationY(Transform.Rotation.Y);
Matrix4x4 rotZ = Matrix4x4.CreateRotationZ(Transform.Rotation.Z);
Model = sca * rotX * rotY * rotZ * trans;
Components = Components.OrderBy(c => c.Order).ToList();
Components.ForEach(c => c.Update());
}
public void Render() => Components.ForEach(c => c.Render());
public void Destroy() => Components.ForEach(c => c.Destroy());
public void AddComponent(ObjectComponent component) {
component.GameObject = this;
if (_loaded)
component.Awake();
Components.Add(component);
}
public T GetComponent<T>() where T : ObjectComponent {
foreach (var component in Components) {
if (component.GetType() == typeof(T))
return (T)component;
}
throw new NullReferenceException("Object does not contain a component of type " + typeof(T).Name);
}
public void RemoveComponent<T>() where T : ObjectComponent {
foreach (var component in Components) {
if (component.GetType() == typeof(T)) {
Components.Remove(component);
return;
}
}
throw new NullReferenceException("Object does not contain a component of type " + typeof(T).Name);
}
public bool HasComponent<T>() where T : ObjectComponent {
foreach (var component in Components) {
if (component.GetType() == typeof(T))
return true;
}
return false;
}
public static GameObject GetByName(string name) {
foreach (var o in Engine.Instance.CurrentScene.Objects) {
if (o.Name.Equals(name))
return o;
}
return null;
}
}
}

View File

@@ -0,0 +1,18 @@
namespace GLEngine.Objects.Components {
public abstract class ObjectComponent {
public int Order { get; set; }
public GameObject GameObject { get; set; }
protected Transform Transform => GameObject.Transform;
protected GameObject Instantiate(GameObject gameObject) => GameObject.Scene.Instantiate(gameObject);
protected void Destroy(GameObject gameObject) => GameObject.Scene.Destory(gameObject);
public abstract void Awake();
public abstract void Update();
public abstract void Render();
public abstract void Destroy();
}
}

View File

@@ -0,0 +1,60 @@
using System.Drawing;
using System.Numerics;
namespace GLEngine.Rendering {
public class Camera {
private const float GameScale = 100.0f;
public static Camera Main => Engine.Instance.CurrentScene.Camera;
public Transform Transform { get; }
public RenderingMode Mode { get; set; }
public float NearClip { get; set; }
public float FarClip { get; set; }
public Matrix4x4 Projection { get; private set; }
public Camera(RenderingMode mode = RenderingMode.Orthographic) {
Transform = new Transform {
Position = Vector3.Zero,
Scale = Vector3.One,
Rotation = Vector3.Zero
};
Mode = mode;
NearClip = 0.01f;
FarClip = 100.0f;
}
public void UpdateMatirx() {
Size windowSize = Engine.Instance.Window.Size;
float left = Transform.Position.X - windowSize.Width / 2.0f;
float right = Transform.Position.X + windowSize.Width / 2.0f;
float top = Transform.Position.Y - windowSize.Height / 2.0f;
float bottom =Transform.Position.Y + windowSize.Height / 2.0f;
Matrix4x4 matrix;
switch (Mode) {
case RenderingMode.Orthographic:
matrix = Matrix4x4.CreateOrthographicOffCenter(left, right, bottom, top, NearClip * GameScale, FarClip * GameScale);
break;
case RenderingMode.Perspective:
matrix = Matrix4x4.CreatePerspectiveOffCenter(left, right, bottom, top, NearClip * GameScale, FarClip * GameScale);
break;
default:
matrix = Matrix4x4.Identity;
break;
}
Matrix4x4 scale = Matrix4x4.CreateScale(GameScale * Transform.Scale.Z);
Matrix4x4 rot = Matrix4x4.Identity; //TODO: Implement Rotation
Projection = matrix * rot * scale;
}
}
public enum RenderingMode {
Orthographic,
Perspective
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,35 @@
using System;
using System.IO;
using GLFW;
using StbiSharp;
using static OpenGL.GL;
namespace GLEngine.Rendering {
public class GameWindow : NativeWindow {
public GameWindow(int width, int height, string title, bool vsync) : base(width, height, title) {
CenterOnScreen();
MakeCurrent();
Import(Glfw.GetProcAddress);
glViewport(0, 0, width, height);
Glfw.SwapInterval(vsync ? 1 : 0);
SizeChanged += OnResize;
}
private void OnResize(object sender, SizeChangeEventArgs e) {
glViewport(0, 0, Size.Width, Size.Height);
}
public unsafe void SetWindowIcon(string file) {
using var stream = File.OpenRead(file);
using var memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
StbiImage image = Stbi.LoadFromMemory(memoryStream, 0);
fixed (byte* data = &image.Data[0]) {
SetIcons(new Image(image.Width, image.Height, new IntPtr(data)));
}
}
}
}

View File

@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Numerics;
using GLEngine.Extensions;
using GLEngine.Resources;
using static OpenGL.GL;
namespace GLEngine.Rendering {
public class Mesh : IResource {
public const string Default = "mesh_default";
public Vector3[] Vertices { get; set; }
public Color[] Colors { get; set; }
public Vector2[] UVs { get; set; }
public int[] Triangles { get; set; }
public float[] Data { get; private set; }
public int Size { get; private set; }
private uint Address { get; set; }
private uint Vbo { get; set; }
private int Mode { get; }
private bool _loaded = false;
public Mesh(DrawMode mode = DrawMode.Static) {
Vertices = Array.Empty<Vector3>();
Colors = Array.Empty<Color>();
UVs = Array.Empty<Vector2>();
Triangles = Array.Empty<int>();
Mode = (int)mode;
}
public void Load() {
if (_loaded || Triangles.Length == 0) return;
UpdateMesh();
}
public void Delete() {
if (!_loaded) return;
Unbind();
glDeleteBuffer(Vbo);
glDeleteVertexArray(Address);
}
public void Bind() {
glBindBuffer(GL_ARRAY_BUFFER, Vbo);
glBindVertexArray(Address);
}
public void Unbind() {
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
public void Render(int renderMode = GL_TRIANGLES) {
Bind();
glDrawArrays(renderMode, 0, Size);
Unbind();
}
public void UpdateMesh() {
CompileMeshData();
UpdateMesh(Data);
}
public unsafe void UpdateMesh(float[] rawData) {
Data = rawData;
Size = rawData.Length / 9;
if (!_loaded) {
Address = glGenVertexArray();
Vbo = glGenBuffer();
}
Bind();
fixed (float* v = &Data[0]) {
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * Data.Length, v, Mode);
}
if (!_loaded) {
glVertexAttribPointer(0, 3, GL_FLOAT, false, 9 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 4, GL_FLOAT, false, 9 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, false, 9 * sizeof(float), (void*)(7 * sizeof(float)));
glEnableVertexAttribArray(2);
_loaded = true;
}
Unbind();
}
private void CompileMeshData() {
List<float> data = new();
for (int i = 0; i < Triangles.Length; i++) {
int index = Triangles[i];
Vector3 vertex = Vertices[index % Vertices.Length];
Color color = Colors[index % Colors.Length];
Vector2 uv = UVs[index % UVs.Length];
data.AddRange(new [] {
vertex.X,
vertex.Y,
vertex.Z,
color.GetRed(),
color.GetGreen(),
color.GetBlue(),
color.GetAlpha(),
uv.X,
uv.Y
});
}
Data = data.ToArray();
Size = Triangles.Length;
}
}
public enum DrawMode {
Static = GL_STATIC_DRAW,
Dynamic = GL_DYNAMIC_DRAW,
Stream = GL_STREAM_DRAW
}
}

View File

@@ -0,0 +1,52 @@
using System.Collections.Generic;
using System.Linq;
using GLEngine.Objects;
namespace GLEngine.Rendering {
public class Scene : IGameEvents {
public List<GameObject> Objects { get; private set; } = new();
public Camera Camera { get; set; } = new();
public ISceneEventListener EventListener { get; set; }
public void Awake() {
EventListener?.Awake();
Objects.ForEach(o => o.Awake());
}
public void Update() {
Camera.UpdateMatirx();
Objects = Objects.OrderBy(o => o.Layer).ToList();
EventListener?.Update();
Objects.ForEach(o => o.Update());
}
public void Render() {
Objects.ForEach(o => o.Render());
EventListener?.Render();
}
public void Destroy() {
Objects.ForEach(o => o.Destroy());
EventListener?.Destroy();
}
public GameObject Instantiate(GameObject gameObject) {
gameObject.Scene = this;
if (Engine.Instance.CurrentScene == this)
gameObject.Awake();
Objects.Add(gameObject);
return gameObject;
}
public void Destory(GameObject gameObject) {
if (gameObject.Scene != this) return;
Objects.Remove(gameObject);
gameObject.Destroy();
}
}
public interface ISceneEventListener : IGameEvents { }
}

View File

@@ -0,0 +1,110 @@
using System.IO;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using GLEngine.Resources;
using GLFW;
using static OpenGL.GL;
namespace GLEngine.Rendering {
public class Shader : IResource {
public const string Default = "shader_default";
private readonly string _vertexCode;
private readonly string _fragmentCode;
private bool _loaded = false;
public uint Program { get; private set; }
public Shader(string vertexPath, string fragmentPath) {
using (var vertexReader = new StreamReader(vertexPath, Encoding.UTF8))
_vertexCode = vertexReader.ReadToEnd();
using (var fragmentReader = new StreamReader(fragmentPath, Encoding.UTF8))
_fragmentCode = fragmentReader.ReadToEnd();
}
public Shader(string shader, bool isFile = true) {
using var reader = isFile ? new StreamReader(shader, Encoding.UTF8) : null;
string source = isFile ? reader.ReadToEnd() : shader;
string[] splitString = Regex.Split(source, "(#type [a-zA-Z]+)");
string firstPattern = splitString[1].Replace("#type ", "").Trim();
string secondPattern = splitString[3].Replace("#type ", "").Trim();
if (firstPattern.ToLower().Equals("vertex"))
_vertexCode = splitString[2];
else if (firstPattern.ToLower().Equals("fragment"))
_fragmentCode = splitString[2];
else throw new IOException("Unexpected token '" + firstPattern + "' in '" + shader + "'");
if (secondPattern.ToLower().Equals("vertex"))
_vertexCode = splitString[4];
else if (secondPattern.ToLower().Equals("fragment"))
_fragmentCode = splitString[4];
else throw new IOException("Unexpected token '" + secondPattern + "' in '" + shader + "'");
}
public void Load() {
if (_loaded) return;
_loaded = true;
uint vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, _vertexCode);
glCompileShader(vs);
int[] status = glGetShaderiv(vs, GL_COMPILE_STATUS, 1);
if (status[0] == 0) {
string error = glGetShaderInfoLog(vs);
throw new Exception("Error compiling vertex shader:\n" + error);
}
uint fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fs, _fragmentCode);
glCompileShader(fs);
status = glGetShaderiv(fs, GL_COMPILE_STATUS, 1);
if (status[0] == 0) {
string error = glGetShaderInfoLog(fs);
throw new Exception("Error compiling fragment shader:\n" + error);
}
Program = glCreateProgram();
glAttachShader(Program, vs);
glAttachShader(Program, fs);
glLinkProgram(Program);
glDetachShader(Program, vs);
glDetachShader(Program, fs);
glDeleteShader(vs);
glDeleteShader(fs);
}
public void Bind() {
glUseProgram(Program);
}
public void Unbind() {
glUseProgram(0);
}
public void Delete() {
Unbind();
glDeleteProgram(Program);
}
public void SetMatrix4X4(string uniformName, Matrix4x4 matrix) {
int location = glGetUniformLocation(Program, uniformName);
glUniformMatrix4fv(location, 1, false, GetMatrix4X4Values(matrix));
}
private float[] GetMatrix4X4Values(Matrix4x4 m) {
return new [] {
m.M11, m.M12, m.M13, m.M14,
m.M21, m.M22, m.M23, m.M24,
m.M31, m.M32, m.M33, m.M34,
m.M41, m.M42, m.M43, m.M44
};
}
}
}

View File

@@ -0,0 +1,76 @@
using System.IO;
using GLEngine.Resources;
using StbiSharp;
using static OpenGL.GL;
namespace GLEngine.Rendering {
public class Texture : IResource {
public const string Default = "tex_default";
public int Width { get; private set; }
public int Height { get; private set; }
private uint Address { get; set; }
private string Path { get; }
private bool _loaded = false;
public Texture(string path) {
Path = path;
}
public unsafe void Load() {
if (_loaded) return;
_loaded = true;
Address = glGenTexture();
Bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (string.IsNullOrEmpty(Path)) {
LoadEmpty();
return;
}
using var stream = File.OpenRead(Path);
using var memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
StbiImage image = Stbi.LoadFromMemory(memoryStream, 0);
int format = image.NumChannels == 3 ? GL_RGB : GL_RGBA;
fixed(byte* data = &image.Data[0])
glTexImage2D(GL_TEXTURE_2D, 0, format, image.Width, image.Height, 0, format, GL_UNSIGNED_BYTE, data);
Width = image.Width;
Height = image.Height;
Unbind();
}
public void Bind() {
glBindTexture(GL_TEXTURE_2D, Address);
}
public void Unbind() {
glBindTexture(GL_TEXTURE_2D, 0);
}
public void Delete() {
Unbind();
glDeleteTexture(Address);
}
private unsafe void LoadEmpty() {
byte[] pixels = {0xFF, 0xFF, 0xFF, 0xFF};
fixed (byte* data = &pixels[0]) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
}
Width = 1;
Height = 1;
glBindTexture(GL_TEXTURE_2D, 0);
}
}
}

View File

@@ -0,0 +1,11 @@
namespace GLEngine.Resources {
public interface IResource {
public void Load();
public void Delete();
public void Bind();
public void Unbind();
}
}

View File

@@ -0,0 +1,46 @@
using System.Collections.Generic;
namespace GLEngine.Resources {
public class ResourceLoader {
private static Dictionary<string, IResource> LoadedResources { get; } = new();
public static T InitializeResource<T>(in string name, in T resource) where T : IResource {
LoadedResources.Add(name, resource);
return resource;
}
public static T LoadResource<T>(in string name) where T : IResource {
IResource resource = LoadedResources[name];
resource.Load();
return (T)resource;
}
public static T GetResource<T>(in string name) where T : IResource {
return (T)LoadedResources[name];
}
public static string GetResourceName(in IResource resource) {
foreach (var res in LoadedResources) {
if (res.Value == resource)
return res.Key;
}
return null;
}
public static void DeleteResource(in string name) {
IResource resource = LoadedResources[name];
resource.Delete();
LoadedResources.Remove(name);
}
public static void DeleteAllResources() {
foreach (var resource in LoadedResources.Values) {
resource.Delete();
}
LoadedResources.Clear();
}
}
}

View File

@@ -0,0 +1,8 @@
namespace GLEngine {
public class Time {
public static float DeltaTime { get; set; }
public static float ElapsedTime { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
using System.Numerics;
namespace GLEngine {
public class Transform {
public Vector3 Position { get; set; }
public Vector3 Scale { get; set; }
public Vector3 Rotation { get; set; }
}
}

View File

@@ -0,0 +1,133 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v5.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v5.0": {
"GLEngine/1.0.0": {
"dependencies": {
"StbiSharp": "1.2.1",
"System.Drawing.Common": "6.0.0",
"GLFW.NET": "1.0.1.0"
},
"runtime": {
"GLEngine.dll": {}
}
},
"Microsoft.Win32.SystemEvents/6.0.0": {
"runtime": {
"lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
},
"runtimeTargets": {
"runtimes/win/lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"StbiSharp/1.2.1": {
"runtime": {
"lib/netcoreapp3.0/StbiSharp.dll": {
"assemblyVersion": "1.2.1.0",
"fileVersion": "1.2.1.0"
}
},
"runtimeTargets": {
"runtimes/linux-x64/native/libstbi.so": {
"rid": "linux-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/osx-x64/native/libstbi.dylib": {
"rid": "osx-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-x64/native/stbi.dll": {
"rid": "win-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-x64/native/stbi.lib": {
"rid": "win-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
}
}
},
"System.Drawing.Common/6.0.0": {
"dependencies": {
"Microsoft.Win32.SystemEvents": "6.0.0"
},
"runtime": {
"lib/netcoreapp3.1/System.Drawing.Common.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
},
"runtimeTargets": {
"runtimes/unix/lib/netcoreapp3.1/System.Drawing.Common.dll": {
"rid": "unix",
"assetType": "runtime",
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
},
"runtimes/win/lib/netcoreapp3.1/System.Drawing.Common.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"GLFW.NET/1.0.1.0": {
"runtime": {
"GLFW.NET.dll": {
"assemblyVersion": "1.0.1.0",
"fileVersion": "1.0.1.0"
}
}
}
}
},
"libraries": {
"GLEngine/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.Win32.SystemEvents/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-hqTM5628jSsQiv+HGpiq3WKBl2c8v1KZfby2J6Pr7pEPlK9waPdgEO6b8A/+/xn/yZ9ulv8HuqK71ONy2tg67A==",
"path": "microsoft.win32.systemevents/6.0.0",
"hashPath": "microsoft.win32.systemevents.6.0.0.nupkg.sha512"
},
"StbiSharp/1.2.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-jbi94g3UDVAC3vH6jKZmmADH4Z6tGqbcdlyGhT/WZN9UE8OjjvpGFE5zF+UCSmIdya6iJ+Zo5VvxdQywSKN0Uw==",
"path": "stbisharp/1.2.1",
"hashPath": "stbisharp.1.2.1.nupkg.sha512"
},
"System.Drawing.Common/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-NfuoKUiP2nUWwKZN6twGqXioIe1zVD0RIj2t976A+czLHr2nY454RwwXs6JU9Htc6mwqL6Dn/nEL3dpVf2jOhg==",
"path": "system.drawing.common/6.0.0",
"hashPath": "system.drawing.common.6.0.0.nupkg.sha512"
},
"GLFW.NET/1.0.1.0": {
"type": "reference",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v5.0", FrameworkDisplayName = "")]

View File

@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("GLEngine")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("GLEngine")]
[assembly: System.Reflection.AssemblyTitleAttribute("GLEngine")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Von der MSBuild WriteCodeFragment-Klasse generiert.

View File

@@ -0,0 +1 @@
7029cc5eef62f0501933027b44c8b6497b73674b

View File

@@ -0,0 +1,10 @@
is_global = true
build_property.TargetFramework = net5.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = GLEngine
build_property.ProjectDir = D:\Programmierstuff\C#\GLEngine\GLEngine\

View File

@@ -0,0 +1 @@
59290718bc06d0bc73f2fc89e1c911f40a791e26

View File

@@ -0,0 +1,14 @@
D:\Programmierstuff\C#\GLEngine\GLEngine\bin\Debug\net5.0\GLEngine.deps.json
D:\Programmierstuff\C#\GLEngine\GLEngine\bin\Debug\net5.0\GLEngine.dll
D:\Programmierstuff\C#\GLEngine\GLEngine\bin\Debug\net5.0\GLEngine.pdb
D:\Programmierstuff\C#\GLEngine\GLEngine\bin\Debug\net5.0\GLFW.NET.dll
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\GLEngine.csproj.AssemblyReference.cache
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\GLEngine.GeneratedMSBuildEditorConfig.editorconfig
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\GLEngine.AssemblyInfoInputs.cache
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\GLEngine.AssemblyInfo.cs
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\GLEngine.csproj.CoreCompileInputs.cache
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\GLEngine.csproj.CopyComplete
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\GLEngine.dll
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\refint\GLEngine.dll
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\GLEngine.pdb
D:\Programmierstuff\C#\GLEngine\GLEngine\obj\Debug\net5.0\ref\GLEngine.dll

Some files were not shown because too many files have changed in this diff Show More