This commit is contained in:
2025-01-02 05:15:16 +03:00
parent 3c66a65b40
commit ac00eb18a9
96 changed files with 384134 additions and 230 deletions

View File

@@ -96,6 +96,21 @@ int findMostPerceptuallyAccurateColor(vec3 color) {
return bestMatchIndex;
}
//int findMostPerceptuallyAccurateColor(vec3 color) {
// int closestIndex = 0;
// float minDistance = distance(color, ConsoleColorVec3[0]);
//
// for (int i = 1; i < 16; i++) {
// float dist = distance(color, ConsoleColorVec3[i]);
// if (dist < minDistance) {
// minDistance = dist;
// closestIndex = i;
// }
// }
//
// return closestIndex;
//}
// Enhanced luminosity calculation considering human perception
float calculatePerceptualLuminance(vec3 color) {
// BT.709 luminance coefficients with slight adjustment
@@ -118,7 +133,7 @@ layout (location = 0) in vec2 iUV;
layout (location = 0) out vec4 FragColor;
void main() {
vec3 pixelColor = texture(uInputTexture, iUV).rgb;
vec3 pixelColor = texture(uInputTexture, iUV * 4).rgb;
// Find most perceptually accurate console color
int colorIndex = findMostPerceptuallyAccurateColor(pixelColor);

View File

@@ -1,9 +1,12 @@
using Engine.Input;
using OpenTK.Mathematics;
namespace PresenterConsole;
public class ConsoleInputHandler : IInputHandler
{
public Vector2 MousePosition => Vector2.Zero;
private readonly bool[] _currentKeys = new bool[256];
private readonly bool[] _previousKeys = new bool[256];

View File

@@ -1,22 +1,26 @@
using Engine.Asset;
using System.Text;
using Engine.Asset;
using Engine.Graphics;
using Engine.Graphics.Buffer;
using Engine.Graphics.Framebuffer;
using Engine.Graphics.Shader;
using Engine.Graphics.Texture;
using Engine.Resource;
using OpenTK.Graphics.OpenGL;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using PresenterConsole.Resource;
namespace PresenterConsole;
public class ConsolePresenter : IPresenter
{
public bool IsExiting => false;
public bool IsExiting { get; private set; }
public int Width { get; private set; } = 2;
public int Height { get; private set; } = 1;
public event Action<ResizeEventArgs>? Resize;
private readonly Engine.Engine _engine;
private readonly Framebuffer _framebuffer;
private readonly Engine.Graphics.Shader.Program _asciiProgram;
private Image<AsciiPixel>? _asciiImage;
@@ -28,9 +32,13 @@ public class ConsolePresenter : IPresenter
private readonly ConsoleFastOutput _consoleOutput;
private static readonly char[] LIGHTMAP = " .,:;=*#%@".Reverse().ToArray();
public ConsolePresenter()
public ConsolePresenter(Engine.Engine parEngine)
{
_asciiProgram = ProgramLoader.LoadFromSource(Resource.ShaderResource.Ascii);
_engine = parEngine;
((MemoryResourceStreamProvider)_engine.EngineResourceManager.StreamProvider).AddResource("shader/ascii",
Encoding.UTF8.GetBytes(ShaderResource.Ascii));
_asciiProgram = _engine.EngineResourceManager.Load<Engine.Graphics.Shader.Program>("shader/ascii");
_framebuffer = Framebuffer.Builder(Width / 2, Height)
.AddColorAttachment<AsciiPixel>()
@@ -55,6 +63,8 @@ public class ConsolePresenter : IPresenter
{
var openglTexture = (Texture)parTexture;
// GL.Viewport(0, 0, Width / 2, Height);
_framebuffer.Bind();
openglTexture.BindUnit();
@@ -67,6 +77,8 @@ public class ConsolePresenter : IPresenter
_framebuffer.Unbind();
// GL.Viewport(0, 0, Width / 2 * 4, Height * 4);
var asciiTexture = _framebuffer.TextureInternal;
if (asciiTexture == null)
throw new InvalidOperationException("Framebuffer texture is null");
@@ -75,10 +87,10 @@ public class ConsolePresenter : IPresenter
_asciiImage = new Image<AsciiPixel>(asciiTexture.Width, asciiTexture.Height);
asciiTexture.ReadPixels(_asciiImage);
Output(_asciiImage);
DrawImage(_asciiImage);
}
private void Output(Image<AsciiPixel> parImage)
private void DrawImage(Image<AsciiPixel> parImage)
{
for (var y = 0; y < parImage.Height; y++)
{
@@ -108,10 +120,15 @@ public class ConsolePresenter : IPresenter
Width = consoleWidth;
Height = consoleHeight;
Resize?.Invoke(new ResizeEventArgs(Width / 2, Height));
Resize?.Invoke(new ResizeEventArgs(Width / 2 * 4, Height * 4));
_framebuffer.Resize(Width / 2, Height);
_consoleOutput.Resize(Width, Height);
}
}
public void Exit()
{
IsExiting = true;
}
}

View File

@@ -10,8 +10,9 @@ internal static class Program
.Headless()
.LogToFile(true, "log.txt")
.LogLevel(LogEventLevel.Debug)
.Presenter(_ => new ConsolePresenter())
.Presenter(parEngine => new ConsolePresenter(parEngine))
.InputHandler(_ => new ConsoleInputHandler())
.AssetFolder(Path.GetFullPath("../DoomDeathmatch/asset"))
.Build();
DoomDeathmatch.DoomDeathmatch.Initialize(engine);