fuck you skybox

This commit is contained in:
4sval 2022-08-29 19:48:31 +02:00
parent b2002121ab
commit 0c5ede60af
16 changed files with 352 additions and 98 deletions

View File

@ -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);
}
}

View File

@ -97,6 +97,8 @@
<None Remove="Resources\shader.vert" />
<None Remove="Resources\grid.frag" />
<None Remove="Resources\grid.vert" />
<None Remove="Resources\skybox.frag" />
<None Remove="Resources\skybox.vert" />
</ItemGroup>
<ItemGroup>
@ -110,6 +112,8 @@
<EmbeddedResource Include="Resources\shader.vert" />
<EmbeddedResource Include="Resources\grid.frag" />
<EmbeddedResource Include="Resources\grid.vert" />
<EmbeddedResource Include="Resources\skybox.frag" />
<EmbeddedResource Include="Resources\skybox.vert" />
</ItemGroup>
<ItemGroup>
@ -132,7 +136,6 @@
<PackageReference Include="Silk.NET.Input" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.16.0" />
<PackageReference Include="Silk.NET.Windowing" Version="2.16.0" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.0" />
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
</ItemGroup>
@ -202,6 +205,12 @@
<Resource Include="Resources\go_to_directory.png" />
<Resource Include="Resources\approaching_storm_cubemap.dds" />
<Resource Include="Resources\npcleftside.png" />
<Resource Include="Resources\nx.png" />
<Resource Include="Resources\ny.png" />
<Resource Include="Resources\nz.png" />
<Resource Include="Resources\px.png" />
<Resource Include="Resources\py.png" />
<Resource Include="Resources\pz.png" />
</ItemGroup>
<ItemGroup>

View File

@ -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)

BIN
FModel/Resources/nx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
FModel/Resources/ny.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
FModel/Resources/nz.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
FModel/Resources/px.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
FModel/Resources/py.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
FModel/Resources/pz.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,12 @@
#version 330 core
in vec3 fPos;
uniform samplerCube cubemap;
out vec4 FragColor;
void main()
{
FragColor = texture(cubemap, fPos);
}

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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<uint> _ebo;
private BufferObject<float> _vbo;
private VertexArrayObject<float, uint> _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<uint>(_gl, Indices, BufferTargetARB.ElementArrayBuffer);
_vbo = new BufferObject<float>(_gl, Vertices, BufferTargetARB.ArrayBuffer);
_vao = new VertexArrayObject<float, uint>(_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);
}
}

View File

@ -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<int>(Width, Height);
options.WindowBorder = WindowBorder.Hidden;
options.Position = new Vector2D<int>(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;
}
}

View File

@ -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
}