-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
351 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#version 330 core | ||
|
||
in vec3 fPos; | ||
|
||
uniform samplerCube cubemap; | ||
|
||
out vec4 FragColor; | ||
|
||
void main() | ||
{ | ||
FragColor = texture(cubemap, fPos); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.