aboutsummaryrefslogtreecommitdiff
path: root/Unicity.Renderer/GraphicsRenderer.cs
diff options
context:
space:
mode:
authorAdrian Ulbrich <adrian.ulbrich.2003@gmail.com>2019-11-08 23:56:17 +0100
committerAdrian Ulbrich <adrian.ulbrich.2003@gmail.com>2019-11-08 23:56:17 +0100
commit3b214e75effaca1ba67daaf29d0a94e5b0129386 (patch)
treeee0ccd43f193f2bdaedd36dcdc944f01a75e37e3 /Unicity.Renderer/GraphicsRenderer.cs
parente63155370c817a1d9c16ef798b0a55e6fe328941 (diff)
downloadUnicity-3b214e75effaca1ba67daaf29d0a94e5b0129386.tar.gz
Unicity-3b214e75effaca1ba67daaf29d0a94e5b0129386.tar.bz2
Unicity-3b214e75effaca1ba67daaf29d0a94e5b0129386.zip
Started work on actual engine
Diffstat (limited to 'Unicity.Renderer/GraphicsRenderer.cs')
-rw-r--r--Unicity.Renderer/GraphicsRenderer.cs102
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();
}
}
}