diff options
| author | Adrian Ulbrich <adrian.ulbrich.2003@gmail.com> | 2019-11-06 21:07:49 +0100 |
|---|---|---|
| committer | Adrian Ulbrich <adrian.ulbrich.2003@gmail.com> | 2019-11-06 21:07:49 +0100 |
| commit | e63155370c817a1d9c16ef798b0a55e6fe328941 (patch) | |
| tree | ab4a65ab60f2e547008eb6c1fe409633521bbf1f /Unicity.Renderer/GraphicsRenderer.cs | |
| parent | 5d4b4023bddd12e27c6756793aea2ff36d49e124 (diff) | |
| download | Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.tar.gz Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.tar.bz2 Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.zip | |
3d support
Diffstat (limited to 'Unicity.Renderer/GraphicsRenderer.cs')
| -rw-r--r-- | Unicity.Renderer/GraphicsRenderer.cs | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/Unicity.Renderer/GraphicsRenderer.cs b/Unicity.Renderer/GraphicsRenderer.cs index f417e14..6508a4c 100644 --- a/Unicity.Renderer/GraphicsRenderer.cs +++ b/Unicity.Renderer/GraphicsRenderer.cs @@ -1,20 +1,46 @@ -using GLFW; -using SharpGL; -using System; +using System; +using System.Text; +using OpenTK; +using OpenTK.Graphics.OpenGL4; using Unicity.Renderer.Shapes; -using static SharpGL.OpenGL; namespace Unicity.Renderer { public class GraphicsRenderer : IDisposable { - internal static OpenGL GL = new OpenGL(); - public RenderWindow window { get; } + public Camera camera = null; - public GraphicsRenderer(RenderWindow window) + Shader shader = null; + + public GraphicsRenderer(RenderWindow window, Camera camera) { this.window = window; + this.camera = camera; + + Console.WriteLine("Compiling GLSL shaders..."); + + string vertexShader = Encoding.UTF8.GetString(Properties.Resources.vertexShader); + string fragmentShader = Encoding.UTF8.GetString(Properties.Resources.fragmentShader); + shader = new Shader(vertexShader, fragmentShader); + shader.Use(); + + Console.WriteLine("Reticulating splines..."); + + GL.ClearDepth(1.0f); + GL.Enable(EnableCap.DepthTest); + GL.DepthFunc(DepthFunction.Lequal); + + camera.Initialize(); + window.Update += Window_Update; + + GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); + } + + private void Window_Update(object sender, EventArgs e) + { + camera.UpdateView(shader); + shader.Use(); } public void SetClearColor(float red, float green, float blue, float alpha) @@ -22,15 +48,28 @@ namespace Unicity.Renderer GL.ClearColor(red, green, blue, alpha); } - public void ClearScreen() + public void SetDrawColor(float red, float green, float blue) + { + shader.SetUniform("color", new Vector3(red, green, blue)); + } + + public void DrawShape(Shape shape) + { + shape.Draw(shader, this); + } + + public void DrawShapes(Shape[] shapes) { - Glfw.MakeContextCurrent(window.window); - GL.Clear(GL_COLOR_BUFFER_BIT); + foreach (Shape shape in shapes) + { + DrawShape(shape); + } } - public void RenderShape(Shape shape) + public void ClearScreen() { - shape.Render(); + window.window.MakeCurrent(); + GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); } bool disposed = false; @@ -49,6 +88,7 @@ namespace Unicity.Renderer // Dispose of any unmanaged resources window?.Dispose(); + shader.Delete(); // Set disposed flag to true disposed = true; |
