diff options
Diffstat (limited to 'Unicity.Renderer/GraphicsRenderer.cs')
| -rw-r--r-- | Unicity.Renderer/GraphicsRenderer.cs | 102 |
1 files changed, 22 insertions, 80 deletions
diff --git a/Unicity.Renderer/GraphicsRenderer.cs b/Unicity.Renderer/GraphicsRenderer.cs index 6508a4c..4a794c9 100644 --- a/Unicity.Renderer/GraphicsRenderer.cs +++ b/Unicity.Renderer/GraphicsRenderer.cs @@ -1,103 +1,45 @@ -using System; -using System.Text; -using OpenTK; +using System.IO; using OpenTK.Graphics.OpenGL4; -using Unicity.Renderer.Shapes; namespace Unicity.Renderer { - public class GraphicsRenderer : IDisposable + public class GraphicsRenderer { - public RenderWindow window { get; } - public Camera camera = null; + RenderWindow window = null; - 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) - { - GL.ClearColor(red, green, blue, alpha); - } - - public void SetDrawColor(float red, float green, float blue) + // Tests + float[] vertices = { - shader.SetUniform("color", new Vector3(red, green, blue)); - } + -0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 0.0f, + 0.0f, 0.5f, 0.0f + }; - public void DrawShape(Shape shape) - { - shape.Draw(shader, this); - } + Shader shader = null; - public void DrawShapes(Shape[] shapes) - { - foreach (Shape shape in shapes) - { - DrawShape(shape); - } - } + int VBO = 0; - public void ClearScreen() + public GraphicsRenderer(RenderWindow window) { - window.window.MakeCurrent(); - GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + this.window = window; } - bool disposed = false; - protected virtual void Dispose(bool disposing) + public void TestInit() { - // Return of already disposed - if (disposed) - { - return; - } + window.MakeCurrent(); - if (disposing) - { - // Free managed objects here - } + string vertexCode = File.ReadAllText("shaders/test.vert"); - // Dispose of any unmanaged resources - window?.Dispose(); - shader.Delete(); + shader = new Shader(vertexCode, ""); - // Set disposed flag to true - disposed = true; + VBO = GL.GenBuffer(); + GL.BindBuffer(BufferTarget.ArrayBuffer, VBO); + GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw); } - public void Dispose() + public void TestLoop() { - Dispose(true); - GC.SuppressFinalize(this); + window.MakeCurrent(); } } } |
