Changed dependencies, added dependencies for TTF rendering.
This commit is contained in:
parent
0225f0821c
commit
364803bf6c
@ -1,38 +1,27 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SlatedGameToolkit.Framework.Exceptions;
|
||||
using System.IO;
|
||||
using SlatedGameToolkit.Framework.Graphics.OpenGL;
|
||||
using SlatedGameToolkit.Framework.Graphics.Textures;
|
||||
using StbImageSharp;
|
||||
|
||||
namespace SlatedGameToolkit.Commons.Loaders
|
||||
{
|
||||
public static class TextureLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads a texture using SDL2's image library.
|
||||
/// Therefore, technically, this function should be able to laod any format SDL2 Image can load.
|
||||
/// Loads a texture using StbImage library.
|
||||
/// Any format supported by StbImage is therefore supported.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the texture to load.</param>
|
||||
/// <param name="glContext">The OpenGL context the texture is to be associated with. May be null.</param>
|
||||
/// <returns>An OpenGL Texture associated with the given context.</returns>
|
||||
public static Texture LoadTexture(string path, GLContext glContext)
|
||||
/// <param name="glContext">The OpenGL context to associate the texture with.</param>
|
||||
/// <returns>A texture.</returns>
|
||||
public static Texture Load2DTexture(string path, GLContext glContext = null)
|
||||
{
|
||||
TextureData textureData;
|
||||
using (Image<Rgba32> image = Image.Load<Rgba32>(path))
|
||||
using (Stream stream = File.OpenRead(path))
|
||||
{
|
||||
byte[] pixelData;
|
||||
Span<Rgba32> pixelDataSpan;
|
||||
if (image.TryGetSinglePixelSpan(out pixelDataSpan)) {
|
||||
pixelData = MemoryMarshal.AsBytes(pixelDataSpan).ToArray();
|
||||
} else {
|
||||
throw new FrameworkUsageException("Image too large!");
|
||||
}
|
||||
textureData = new TextureData(image.Width, image.Height, pixelData);
|
||||
}
|
||||
|
||||
ImageResult image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
|
||||
TextureData textureData = new TextureData(image.Width, image.Height, image.Data);
|
||||
return new Texture(textureData, glContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-rc0003" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SlatedGameToolkit.Framework\SlatedGameToolkit.Framework.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StbImageSharp" Version="2.22.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -8,9 +8,17 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
/// A set of two buffers, one for the vertices, and one for the indices. Also defines an vertex array that defines the attributes of the buffers.
|
||||
/// </summary>
|
||||
public class VertexArrayBuffers : IDisposable {
|
||||
private uint vertexBufferLength, indexBufferLength;
|
||||
private GLContext glContext;
|
||||
private bool disposed;
|
||||
private uint vertexBufferHandle, vertexArrayHandle, indexBufferHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Create a vertex array, a elements buffer, and an vertice array buffer.
|
||||
///
|
||||
/// Automatically checks if resizing the buffers are nessecary.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public VertexArrayBuffers(GLContext context) {
|
||||
this.glContext = context ?? WindowContextsManager.CurrentGL;
|
||||
|
||||
@ -33,15 +41,27 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
|
||||
public unsafe void BufferVertices(float[] data, bool dynamic) {
|
||||
Use();
|
||||
uint requiredLength = (uint) (sizeof(float) * data.Length);
|
||||
fixed (void* pointer = &data[0]) {
|
||||
glContext.BufferData(OpenGL.BufferTargetARB.ArrayBuffer, (uint) (sizeof(float) * data.Length), new IntPtr(pointer), dynamic ? OpenGL.BufferUsageARB.DynamicDraw : OpenGL.BufferUsageARB.StaticDraw);
|
||||
if (requiredLength > vertexBufferLength) {
|
||||
glContext.BufferData(BufferTargetARB.ArrayBuffer, requiredLength, new IntPtr(pointer), dynamic ? OpenGL.BufferUsageARB.DynamicDraw : OpenGL.BufferUsageARB.StaticDraw);
|
||||
vertexBufferLength = requiredLength;
|
||||
} else {
|
||||
glContext.BufferSubData(BufferTargetARB.ArrayBuffer, IntPtr.Zero, new IntPtr(requiredLength), new IntPtr(pointer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void BufferIndices(uint[] data, bool dynamic) {
|
||||
Use();
|
||||
uint requiredLength = (uint) (sizeof(uint) * data.Length);
|
||||
fixed (void* pointer = &data[0]) {
|
||||
glContext.BufferData(OpenGL.BufferTargetARB.ElementArrayBuffer, (uint) (sizeof(uint) * data.Length), new IntPtr(pointer), dynamic ? OpenGL.BufferUsageARB.DynamicDraw : OpenGL.BufferUsageARB.StaticDraw);
|
||||
if (requiredLength > indexBufferLength) {
|
||||
glContext.BufferData(OpenGL.BufferTargetARB.ElementArrayBuffer, requiredLength, new IntPtr(pointer), dynamic ? OpenGL.BufferUsageARB.DynamicDraw : OpenGL.BufferUsageARB.StaticDraw);
|
||||
indexBufferLength = requiredLength;
|
||||
} else {
|
||||
glContext.BufferSubData(BufferTargetARB.ElementArrayBuffer, IntPtr.Zero, new IntPtr(requiredLength), new IntPtr(pointer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StbTrueTypeSharp" Version="1.24.6" />
|
||||
<PackageReference Include="Serilog" Version="2.9.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
|
||||
</ItemGroup>
|
||||
|
@ -51,7 +51,7 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
|
||||
camera = new Camera2D(2, 2);
|
||||
renderer = new MeshBatch(camera);
|
||||
|
||||
logoTexture = TextureLoader.LoadTexture("Resources/Playground/yhdnbgnc.png", null);
|
||||
logoTexture = TextureLoader.Load2DTexture("Resources/Playground/yhdnbgnc.png", null);
|
||||
logo = new RectangleMesh(logoTexture, Color.White);
|
||||
logo.Width = 0.5f;
|
||||
logo.Height = 0.5f;
|
||||
@ -59,7 +59,7 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
|
||||
logo.Y = -0.25f;
|
||||
|
||||
|
||||
fillerTexture = TextureLoader.LoadTexture("Resources/Playground/filler.png", null);
|
||||
fillerTexture = TextureLoader.Load2DTexture("Resources/Playground/filler.png", null);
|
||||
textureTester = new RectangleMesh(fillerTexture, Color.White);
|
||||
textureTester.Width = 0.15f;
|
||||
textureTester.Height = 0.15f;
|
||||
|
Loading…
Reference in New Issue
Block a user