diff --git a/FModel/Extensions/ImGuiExtensions.cs b/FModel/Extensions/ImGuiExtensions.cs new file mode 100644 index 00000000..88f749d6 --- /dev/null +++ b/FModel/Extensions/ImGuiExtensions.cs @@ -0,0 +1,84 @@ +using System.Numerics; +using ImGuiNET; + +namespace FModel.Extensions; + +public static class ImGuiExtensions +{ + public const float PADDING = 5.0f; + public static ImGuiStylePtr STYLE = ImGui.GetStyle(); + + public static void DrawFPS() + { + const ImGuiWindowFlags flags = + ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.AlwaysAutoResize | + ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoFocusOnAppearing | + ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoNav; + var viewport = ImGui.GetMainViewport(); + var work_pos = viewport.WorkPos; + var work_size = viewport.WorkSize; + + ImGui.SetNextWindowPos(new Vector2(work_pos.X + PADDING, work_pos.Y + work_size.Y - PADDING), ImGuiCond.Always, new Vector2(0, 1)); + if (ImGui.Begin("FPS Overlay", flags)) + { + float framerate = ImGui.GetIO().Framerate; + ImGui.Text($"FPS: {framerate:0} ({1000.0f / framerate:0.##} ms)"); + } + ImGui.End(); + } + + public static void Theme() + { + STYLE.FrameRounding = 4.0f; + STYLE.GrabRounding = 4.0f; + + STYLE.Colors[(int) ImGuiCol.Text] = new Vector4(0.95f, 0.96f, 0.98f, 1.00f); + STYLE.Colors[(int) ImGuiCol.TextDisabled] = new Vector4(0.36f, 0.42f, 0.47f, 1.00f); + STYLE.Colors[(int) ImGuiCol.WindowBg] = new Vector4(0.11f, 0.15f, 0.17f, 0.35f); + STYLE.Colors[(int) ImGuiCol.ChildBg] = new Vector4(0.15f, 0.18f, 0.22f, 1.00f); + STYLE.Colors[(int) ImGuiCol.PopupBg] = new Vector4(0.08f, 0.08f, 0.08f, 0.94f); + STYLE.Colors[(int) ImGuiCol.Border] = new Vector4(0.08f, 0.10f, 0.12f, 1.00f); + STYLE.Colors[(int) ImGuiCol.BorderShadow] = new Vector4(0.00f, 0.00f, 0.00f, 0.00f); + STYLE.Colors[(int) ImGuiCol.FrameBg] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + STYLE.Colors[(int) ImGuiCol.FrameBgHovered] = new Vector4(0.12f, 0.20f, 0.28f, 1.00f); + STYLE.Colors[(int) ImGuiCol.FrameBgActive] = new Vector4(0.09f, 0.12f, 0.14f, 1.00f); + STYLE.Colors[(int) ImGuiCol.TitleBg] = new Vector4(0.09f, 0.12f, 0.14f, 0.65f); + STYLE.Colors[(int) ImGuiCol.TitleBgActive] = new Vector4(0.08f, 0.10f, 0.12f, 1.00f); + STYLE.Colors[(int) ImGuiCol.TitleBgCollapsed] = new Vector4(0.00f, 0.00f, 0.00f, 0.51f); + STYLE.Colors[(int) ImGuiCol.MenuBarBg] = new Vector4(0.15f, 0.18f, 0.22f, 1.00f); + STYLE.Colors[(int) ImGuiCol.ScrollbarBg] = new Vector4(0.02f, 0.02f, 0.02f, 0.39f); + STYLE.Colors[(int) ImGuiCol.ScrollbarGrab] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + STYLE.Colors[(int) ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.18f, 0.22f, 0.25f, 1.00f); + STYLE.Colors[(int) ImGuiCol.ScrollbarGrabActive] = new Vector4(0.09f, 0.21f, 0.31f, 1.00f); + STYLE.Colors[(int) ImGuiCol.CheckMark] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); + STYLE.Colors[(int) ImGuiCol.SliderGrab] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); + STYLE.Colors[(int) ImGuiCol.SliderGrabActive] = new Vector4(0.37f, 0.61f, 1.00f, 1.00f); + STYLE.Colors[(int) ImGuiCol.Button] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + STYLE.Colors[(int) ImGuiCol.ButtonHovered] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); + STYLE.Colors[(int) ImGuiCol.ButtonActive] = new Vector4(0.06f, 0.53f, 0.98f, 1.00f); + STYLE.Colors[(int) ImGuiCol.Header] = new Vector4(0.20f, 0.25f, 0.29f, 0.55f); + STYLE.Colors[(int) ImGuiCol.HeaderHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.80f); + STYLE.Colors[(int) ImGuiCol.HeaderActive] = new Vector4(0.26f, 0.59f, 0.98f, 1.00f); + STYLE.Colors[(int) ImGuiCol.Separator] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + STYLE.Colors[(int) ImGuiCol.SeparatorHovered] = new Vector4(0.10f, 0.40f, 0.75f, 0.78f); + STYLE.Colors[(int) ImGuiCol.SeparatorActive] = new Vector4(0.10f, 0.40f, 0.75f, 1.00f); + STYLE.Colors[(int) ImGuiCol.ResizeGrip] = new Vector4(0.26f, 0.59f, 0.98f, 0.25f); + STYLE.Colors[(int) ImGuiCol.ResizeGripHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.67f); + STYLE.Colors[(int) ImGuiCol.ResizeGripActive] = new Vector4(0.26f, 0.59f, 0.98f, 0.95f); + STYLE.Colors[(int) ImGuiCol.Tab] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); + STYLE.Colors[(int) ImGuiCol.TabHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.80f); + STYLE.Colors[(int) ImGuiCol.TabActive] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + STYLE.Colors[(int) ImGuiCol.TabUnfocused] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); + STYLE.Colors[(int) ImGuiCol.TabUnfocusedActive] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); + STYLE.Colors[(int) ImGuiCol.PlotLines] = new Vector4(0.61f, 0.61f, 0.61f, 1.00f); + STYLE.Colors[(int) ImGuiCol.PlotLinesHovered] = new Vector4(1.00f, 0.43f, 0.35f, 1.00f); + STYLE.Colors[(int) ImGuiCol.PlotHistogram] = new Vector4(0.90f, 0.70f, 0.00f, 1.00f); + STYLE.Colors[(int) ImGuiCol.PlotHistogramHovered] = new Vector4(1.00f, 0.60f, 0.00f, 1.00f); + STYLE.Colors[(int) ImGuiCol.TextSelectedBg] = new Vector4(0.26f, 0.59f, 0.98f, 0.35f); + STYLE.Colors[(int) ImGuiCol.DragDropTarget] = new Vector4(1.00f, 1.00f, 0.00f, 0.90f); + STYLE.Colors[(int) ImGuiCol.NavHighlight] = new Vector4(0.26f, 0.59f, 0.98f, 1.00f); + STYLE.Colors[(int) ImGuiCol.NavWindowingHighlight] = new Vector4(1.00f, 1.00f, 1.00f, 0.70f); + STYLE.Colors[(int) ImGuiCol.NavWindowingDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.20f); + STYLE.Colors[(int) ImGuiCol.ModalWindowDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.35f); + } +} diff --git a/FModel/FModel.csproj b/FModel/FModel.csproj index 9b6e0217..01d7d569 100644 --- a/FModel/FModel.csproj +++ b/FModel/FModel.csproj @@ -97,6 +97,8 @@ + + @@ -110,6 +112,8 @@ + + @@ -132,7 +136,6 @@ - @@ -202,6 +205,12 @@ + + + + + + diff --git a/FModel/Resources/grid.frag b/FModel/Resources/grid.frag index b981fa45..7fc9f0d2 100644 --- a/FModel/Resources/grid.frag +++ b/FModel/Resources/grid.frag @@ -23,7 +23,7 @@ vec4 grid(vec3 fragPos, float scale) { float line = min(grid.x, grid.y); float minimumz = min(derivative.y, 1) * 0.1; float minimumx = min(derivative.x, 1) * 0.1; - vec4 color = vec4(0.149, 0.149, 0.188, 1.0 - min(line, 1.0)); + vec4 color = vec4(0.102, 0.102, 0.129, 1.0 - min(line, 1.0)); if(abs(fragPos.x) < minimumx) color.z = 1.0; if(abs(fragPos.z) < minimumz) diff --git a/FModel/Resources/nx.png b/FModel/Resources/nx.png new file mode 100644 index 00000000..a6896403 Binary files /dev/null and b/FModel/Resources/nx.png differ diff --git a/FModel/Resources/ny.png b/FModel/Resources/ny.png new file mode 100644 index 00000000..73349e3c Binary files /dev/null and b/FModel/Resources/ny.png differ diff --git a/FModel/Resources/nz.png b/FModel/Resources/nz.png new file mode 100644 index 00000000..8e6b1015 Binary files /dev/null and b/FModel/Resources/nz.png differ diff --git a/FModel/Resources/px.png b/FModel/Resources/px.png new file mode 100644 index 00000000..74a6899d Binary files /dev/null and b/FModel/Resources/px.png differ diff --git a/FModel/Resources/py.png b/FModel/Resources/py.png new file mode 100644 index 00000000..c0a2d1f8 Binary files /dev/null and b/FModel/Resources/py.png differ diff --git a/FModel/Resources/pz.png b/FModel/Resources/pz.png new file mode 100644 index 00000000..7f825fbb Binary files /dev/null and b/FModel/Resources/pz.png differ diff --git a/FModel/Resources/skybox.frag b/FModel/Resources/skybox.frag new file mode 100644 index 00000000..e64c3942 --- /dev/null +++ b/FModel/Resources/skybox.frag @@ -0,0 +1,12 @@ +#version 330 core + +in vec3 fPos; + +uniform samplerCube cubemap; + +out vec4 FragColor; + +void main() +{ + FragColor = texture(cubemap, fPos); +} diff --git a/FModel/Resources/skybox.vert b/FModel/Resources/skybox.vert new file mode 100644 index 00000000..edb252b6 --- /dev/null +++ b/FModel/Resources/skybox.vert @@ -0,0 +1,16 @@ +#version 330 core + +layout (location = 0) in vec3 vPos; + +uniform mat4 uView; +uniform mat4 uProjection; + +out vec3 fPos; + +void main() +{ + fPos = vPos; + vec4 pos = uProjection * uView * vec4(vPos, 1.0); + + gl_Position = pos.xyww; +} diff --git a/FModel/Views/Snooper/Model.cs b/FModel/Views/Snooper/Model.cs index a342d817..ffa32773 100644 --- a/FModel/Views/Snooper/Model.cs +++ b/FModel/Views/Snooper/Model.cs @@ -22,10 +22,10 @@ public class Model : IDisposable private Shader _shader; - public string Name; - public uint[] Indices; - public float[] Vertices; - public Section[] Sections; + public readonly string Name; + public readonly uint[] Indices; + public readonly float[] Vertices; + public readonly Section[] Sections; public Model(string name, CBaseMeshLod lod, CMeshVertex[] vertices) { diff --git a/FModel/Views/Snooper/Section.cs b/FModel/Views/Snooper/Section.cs index b2806f6a..57991d88 100644 --- a/FModel/Views/Snooper/Section.cs +++ b/FModel/Views/Snooper/Section.cs @@ -20,11 +20,11 @@ public class Section : IDisposable // private Texture _metallicMap; private Texture _emissionMap; - public string Name; - public int Index; - public uint FacesCount; - public int FirstFaceIndex; - public CMaterialParams Parameters; + public readonly string Name; + public readonly int Index; + public readonly uint FacesCount; + public readonly int FirstFaceIndex; + public readonly CMaterialParams Parameters; public Section(string name, int index, uint facesCount, int firstFaceIndex, CMeshSection section) { diff --git a/FModel/Views/Snooper/Skybox.cs b/FModel/Views/Snooper/Skybox.cs new file mode 100644 index 00000000..73d56dc8 --- /dev/null +++ b/FModel/Views/Snooper/Skybox.cs @@ -0,0 +1,115 @@ +using System; +using Silk.NET.OpenGL; + +namespace FModel.Views.Snooper; + +public class Skybox : IDisposable +{ + private uint _handle; + private GL _gl; + + private BufferObject _ebo; + private BufferObject _vbo; + private VertexArrayObject _vao; + + private string[] _textures = { "nx", "ny", "nz", "px", "py", "pz" }; + + private Texture _cubeMap; + private Shader _shader; + + public readonly uint[] Indices = { 0, 1, 3, 1, 2, 3 }; + public readonly float[] Vertices = { + //X Y Z + -0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, + -0.5f, 0.5f, -0.5f, + -0.5f, -0.5f, -0.5f, + + -0.5f, -0.5f, 0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, 0.5f, + -0.5f, -0.5f, 0.5f, + + -0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, -0.5f, + -0.5f, -0.5f, -0.5f, + -0.5f, -0.5f, -0.5f, + -0.5f, -0.5f, 0.5f, + -0.5f, 0.5f, 0.5f, + + 0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + + -0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, -0.5f, 0.5f, + -0.5f, -0.5f, 0.5f, + -0.5f, -0.5f, -0.5f, + + -0.5f, 0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, + 0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, -0.5f + }; + + public Skybox() {} + + public void Setup(GL gl) + { + _gl = gl; + + _handle = _gl.CreateProgram(); + + _cubeMap = new Texture(_gl, _textures); + _shader = new Shader(_gl, "skybox.vert", "skybox.frag"); + + _ebo = new BufferObject(_gl, Indices, BufferTargetARB.ElementArrayBuffer); + _vbo = new BufferObject(_gl, Vertices, BufferTargetARB.ArrayBuffer); + _vao = new VertexArrayObject(_gl, _vbo, _ebo); + + _vao.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 3, 0); // position + } + + public void Bind(Camera camera) + { + _gl.DepthFunc(DepthFunction.Lequal); + + _vao.Bind(); + + _cubeMap.Bind(TextureUnit.Texture0); + _shader.Use(); + + var view = camera.GetViewMatrix(); + view.M41 = 0; + view.M42 = 0; + view.M43 = 0; + _shader.SetUniform("uView", view); + _shader.SetUniform("uProjection", camera.GetProjectionMatrix()); + + _shader.SetUniform("cubemap", 0); + + _gl.DrawArrays(PrimitiveType.Triangles, 0, 36); + + _gl.DepthFunc(DepthFunction.Less); + } + + public void Dispose() + { + _ebo.Dispose(); + _vbo.Dispose(); + _vao.Dispose(); + _shader.Dispose(); + _gl.DeleteProgram(_handle); + } +} diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index 50c83c07..1c18458f 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -5,6 +5,7 @@ using CUE4Parse.UE4.Assets.Exports.SkeletalMesh; using CUE4Parse.UE4.Assets.Exports.StaticMesh; using CUE4Parse.UE4.Objects.Core.Math; using CUE4Parse_Conversion.Meshes; +using FModel.Extensions; using ImGuiNET; using Silk.NET.Input; using Silk.NET.Maths; @@ -17,7 +18,6 @@ namespace FModel.Views.Snooper; public class Snooper { private IWindow _window; - private IInputContext _input; private ImGuiController _controller; private GL _gl; private Camera _camera; @@ -25,8 +25,9 @@ public class Snooper private IMouse _mouse; private Vector2 _previousMousePosition; - private Model[] _models; + // private Skybox _skybox; private Grid _grid; + private Model[] _models; public int Width { get; } public int Height { get; } @@ -42,8 +43,8 @@ public class Snooper var options = WindowOptions.Default; options.Size = new Vector2D(Width, Height); options.WindowBorder = WindowBorder.Hidden; - options.Position = new Vector2D(5, 5); // this doesn't fucking work WTF options.Title = "Snooper"; + options.Samples = 4; _window = Window.Create(options); _window.Load += OnLoad; @@ -52,6 +53,7 @@ public class Snooper _window.Closing += OnClose; _window.FramebufferResize += OnFramebufferResize; + // _skybox = new Skybox(); _grid = new Grid(); _models = new Model[1]; switch (export) @@ -88,10 +90,12 @@ public class Snooper private void OnLoad() { - _input = _window.CreateInput(); - _keyboard = _input.Keyboards[0]; + _window.Center(); + + var input = _window.CreateInput(); + _keyboard = input.Keyboards[0]; _keyboard.KeyDown += KeyDown; - _mouse = _input.Mice[0]; + _mouse = input.Mice[0]; _mouse.MouseDown += OnMouseDown; _mouse.MouseUp += OnMouseUp; _mouse.MouseMove += OnMouseMove; @@ -100,10 +104,12 @@ public class Snooper _gl = GL.GetApi(_window); _gl.Enable(EnableCap.Blend); _gl.Enable(EnableCap.DepthTest); + _gl.Enable(EnableCap.Multisample); _gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); - _controller = new ImGuiController(_gl, _window, _input); + _controller = new ImGuiController(_gl, _window, input); + // _skybox.Setup(_gl); _grid.Setup(_gl); foreach (var model in _models) @@ -121,27 +127,43 @@ public class Snooper { _controller.Update((float) deltaTime); - _gl.ClearColor(0.149f, 0.149f, 0.188f, 1.0f); + _gl.ClearColor(0.102f, 0.102f, 0.129f, 1.0f); _gl.Clear((uint) ClearBufferMask.ColorBufferBit | (uint) ClearBufferMask.DepthBufferBit); + // _skybox.Bind(_camera); _grid.Bind(_camera); - var padding = Theme(); - ImGui.Begin("ImGui.NET", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoBackground); - ImGui.SetWindowSize(new Vector2(Width / 4f, Height)); - ImGui.SetWindowPos(new Vector2(0)); + ImGuiExtensions.Theme(); + if (ImGui.BeginMainMenuBar()) + { + if (ImGui.BeginMenu("Edit")) + { + if (ImGui.MenuItem("Undo", "CTRL+Z")) {} + if (ImGui.MenuItem("Redo", "CTRL+Y", false, false)) {} // Disabled item + ImGui.Separator(); + if (ImGui.MenuItem("Cut", "CTRL+X")) {} + if (ImGui.MenuItem("Copy", "CTRL+C")) {} + if (ImGui.MenuItem("Paste", "CTRL+V")) {} + ImGui.EndMenu(); + } + + const string text = "ESC to Exit..."; + ImGui.SetCursorPosX(ImGui.GetWindowViewport().WorkSize.X - ImGui.CalcTextSize(text).X - 5); + ImGui.TextColored(ImGuiExtensions.STYLE.Colors[(int) ImGuiCol.TextDisabled], text); + + ImGui.EndMainMenuBar(); + } + + ImGui.Begin("ImGui.NET", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoSavedSettings); foreach (var model in _models) { model.Bind(_camera); } - - float framerate = ImGui.GetIO().Framerate; - string f = $"FPS: {framerate:0.#} ({1000.0f / framerate:0.##} ms)"; - ImGui.SetCursorPosY(ImGui.GetWindowHeight() - padding.Y - ImGui.CalcTextSize(f).Y); - ImGui.Text(f); ImGui.End(); + ImGuiExtensions.DrawFPS(); + _controller.Render(); } @@ -213,12 +235,13 @@ public class Snooper private void OnClose() { _grid.Dispose(); + // _skybox.Dispose(); foreach (var model in _models) { model.Dispose(); } - _input.Dispose(); _controller.Dispose(); + _window.Dispose(); _gl.Dispose(); } @@ -231,62 +254,4 @@ public class Snooper break; } } - - private Vector2 Theme() - { - var style = ImGui.GetStyle(); - style.FrameRounding = 4.0f; - style.GrabRounding = 4.0f; - - style.Colors[(int) ImGuiCol.Text] = new Vector4(0.95f, 0.96f, 0.98f, 1.00f); - style.Colors[(int) ImGuiCol.TextDisabled] = new Vector4(0.36f, 0.42f, 0.47f, 1.00f); - style.Colors[(int) ImGuiCol.WindowBg] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); - style.Colors[(int) ImGuiCol.ChildBg] = new Vector4(0.15f, 0.18f, 0.22f, 1.00f); - style.Colors[(int) ImGuiCol.PopupBg] = new Vector4(0.08f, 0.08f, 0.08f, 0.94f); - style.Colors[(int) ImGuiCol.Border] = new Vector4(0.08f, 0.10f, 0.12f, 1.00f); - style.Colors[(int) ImGuiCol.BorderShadow] = new Vector4(0.00f, 0.00f, 0.00f, 0.00f); - style.Colors[(int) ImGuiCol.FrameBg] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); - style.Colors[(int) ImGuiCol.FrameBgHovered] = new Vector4(0.12f, 0.20f, 0.28f, 1.00f); - style.Colors[(int) ImGuiCol.FrameBgActive] = new Vector4(0.09f, 0.12f, 0.14f, 1.00f); - style.Colors[(int) ImGuiCol.TitleBg] = new Vector4(0.09f, 0.12f, 0.14f, 0.65f); - style.Colors[(int) ImGuiCol.TitleBgActive] = new Vector4(0.08f, 0.10f, 0.12f, 1.00f); - style.Colors[(int) ImGuiCol.TitleBgCollapsed] = new Vector4(0.00f, 0.00f, 0.00f, 0.51f); - style.Colors[(int) ImGuiCol.MenuBarBg] = new Vector4(0.15f, 0.18f, 0.22f, 1.00f); - style.Colors[(int) ImGuiCol.ScrollbarBg] = new Vector4(0.02f, 0.02f, 0.02f, 0.39f); - style.Colors[(int) ImGuiCol.ScrollbarGrab] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); - style.Colors[(int) ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.18f, 0.22f, 0.25f, 1.00f); - style.Colors[(int) ImGuiCol.ScrollbarGrabActive] = new Vector4(0.09f, 0.21f, 0.31f, 1.00f); - style.Colors[(int) ImGuiCol.CheckMark] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); - style.Colors[(int) ImGuiCol.SliderGrab] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); - style.Colors[(int) ImGuiCol.SliderGrabActive] = new Vector4(0.37f, 0.61f, 1.00f, 1.00f); - style.Colors[(int) ImGuiCol.Button] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); - style.Colors[(int) ImGuiCol.ButtonHovered] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); - style.Colors[(int) ImGuiCol.ButtonActive] = new Vector4(0.06f, 0.53f, 0.98f, 1.00f); - style.Colors[(int) ImGuiCol.Header] = new Vector4(0.20f, 0.25f, 0.29f, 0.55f); - style.Colors[(int) ImGuiCol.HeaderHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.80f); - style.Colors[(int) ImGuiCol.HeaderActive] = new Vector4(0.26f, 0.59f, 0.98f, 1.00f); - style.Colors[(int) ImGuiCol.Separator] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); - style.Colors[(int) ImGuiCol.SeparatorHovered] = new Vector4(0.10f, 0.40f, 0.75f, 0.78f); - style.Colors[(int) ImGuiCol.SeparatorActive] = new Vector4(0.10f, 0.40f, 0.75f, 1.00f); - style.Colors[(int) ImGuiCol.ResizeGrip] = new Vector4(0.26f, 0.59f, 0.98f, 0.25f); - style.Colors[(int) ImGuiCol.ResizeGripHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.67f); - style.Colors[(int) ImGuiCol.ResizeGripActive] = new Vector4(0.26f, 0.59f, 0.98f, 0.95f); - style.Colors[(int) ImGuiCol.Tab] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); - style.Colors[(int) ImGuiCol.TabHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.80f); - style.Colors[(int) ImGuiCol.TabActive] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); - style.Colors[(int) ImGuiCol.TabUnfocused] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); - style.Colors[(int) ImGuiCol.TabUnfocusedActive] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); - style.Colors[(int) ImGuiCol.PlotLines] = new Vector4(0.61f, 0.61f, 0.61f, 1.00f); - style.Colors[(int) ImGuiCol.PlotLinesHovered] = new Vector4(1.00f, 0.43f, 0.35f, 1.00f); - style.Colors[(int) ImGuiCol.PlotHistogram] = new Vector4(0.90f, 0.70f, 0.00f, 1.00f); - style.Colors[(int) ImGuiCol.PlotHistogramHovered] = new Vector4(1.00f, 0.60f, 0.00f, 1.00f); - style.Colors[(int) ImGuiCol.TextSelectedBg] = new Vector4(0.26f, 0.59f, 0.98f, 0.35f); - style.Colors[(int) ImGuiCol.DragDropTarget] = new Vector4(1.00f, 1.00f, 0.00f, 0.90f); - style.Colors[(int) ImGuiCol.NavHighlight] = new Vector4(0.26f, 0.59f, 0.98f, 1.00f); - style.Colors[(int) ImGuiCol.NavWindowingHighlight] = new Vector4(1.00f, 1.00f, 1.00f, 0.70f); - style.Colors[(int) ImGuiCol.NavWindowingDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.20f); - style.Colors[(int) ImGuiCol.ModalWindowDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.35f); - - return style.WindowPadding; - } } diff --git a/FModel/Views/Snooper/Texture.cs b/FModel/Views/Snooper/Texture.cs index 7f9fd236..fc7c48e0 100644 --- a/FModel/Views/Snooper/Texture.cs +++ b/FModel/Views/Snooper/Texture.cs @@ -1,5 +1,7 @@ using Silk.NET.OpenGL; using System; +using System.IO; +using System.Windows; namespace FModel.Views.Snooper; @@ -8,33 +10,77 @@ public class Texture : IDisposable private uint _handle; private GL _gl; - public unsafe Texture(GL gl, byte[] data, uint width, uint height) + private TextureType _type; + + public Texture(GL gl, TextureType type) { _gl = gl; - _handle = _gl.GenTexture(); - Bind(TextureUnit.Texture0); + _type = type; + Bind(TextureUnit.Texture0); + } + + public unsafe Texture(GL gl, uint width, uint height) : this(gl, TextureType.Framebuffer) + { + _gl = gl; + _handle = _gl.GenTexture(); + + _gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgb, width, height, 0, PixelFormat.Rgb, PixelType.UnsignedByte, null); + + _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.Nearest); + _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Nearest); + _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) GLEnum.ClampToEdge); + _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) GLEnum.ClampToEdge); + + _gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, _handle, 0); + } + + public unsafe Texture(GL gl, byte[] data, uint width, uint height) : this(gl, TextureType.Normal) + { fixed (void* d = &data[0]) { _gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, d); - SetParameters(); + + _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.LinearMipmapLinear); + _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Linear); + _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0); + _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 8); + + _gl.GenerateMipmap(TextureTarget.Texture2D); } } - private void SetParameters() + public unsafe Texture(GL gl, string[] textures) : this(gl, TextureType.Cubemap) { - _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.LinearMipmapLinear); - _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Linear); - _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0); - _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 8); - _gl.GenerateMipmap(TextureTarget.Texture2D); + for (int t = 0; t < textures.Length; t++) + { + var info = Application.GetResourceStream(new Uri($"/FModel;component/Resources/{textures[t]}.png", UriKind.Relative)); + var stream = new MemoryStream(); + info.Stream.CopyTo(stream); + + fixed (void* d = &stream.ToArray()[0]) + { + _gl.TexImage2D(TextureTarget.TextureCubeMapPositiveX + t, 0, (int) InternalFormat.Rgb, 256, 256, 0, PixelFormat.Rgb, PixelType.UnsignedByte, d); + } + } + + _gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int) GLEnum.Linear); + _gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int) GLEnum.Linear); + _gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int) GLEnum.ClampToEdge); + _gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int) GLEnum.ClampToEdge); + _gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int) GLEnum.ClampToEdge); } public void Bind(TextureUnit textureSlot) { _gl.ActiveTexture(textureSlot); - _gl.BindTexture(TextureTarget.Texture2D, _handle); + var target = _type switch + { + TextureType.Cubemap => TextureTarget.TextureCubeMap, + _ => TextureTarget.Texture2D + }; + _gl.BindTexture(target, _handle); } public void Dispose() @@ -42,3 +88,10 @@ public class Texture : IDisposable _gl.DeleteTexture(_handle); } } + +public enum TextureType +{ + Normal, + Cubemap, + Framebuffer +}