aboutsummaryrefslogtreecommitdiff
path: root/Unicity.Renderer/Shapes
diff options
context:
space:
mode:
authorAdrian Ulbrich <adrian.ulbrich.2003@gmail.com>2019-11-04 00:36:44 +0100
committerAdrian Ulbrich <adrian.ulbrich.2003@gmail.com>2019-11-04 00:36:44 +0100
commit5d4b4023bddd12e27c6756793aea2ff36d49e124 (patch)
tree7d66eac7b7b2d7ffe647aa8a34bc544fd770a23b /Unicity.Renderer/Shapes
parent0fec6725547868de242aaf9035eedf99f7be3233 (diff)
downloadUnicity-5d4b4023bddd12e27c6756793aea2ff36d49e124.tar.gz
Unicity-5d4b4023bddd12e27c6756793aea2ff36d49e124.tar.bz2
Unicity-5d4b4023bddd12e27c6756793aea2ff36d49e124.zip
Upload code
Diffstat (limited to 'Unicity.Renderer/Shapes')
-rw-r--r--Unicity.Renderer/Shapes/Shape.cs17
-rw-r--r--Unicity.Renderer/Shapes/Triangle.cs43
2 files changed, 60 insertions, 0 deletions
diff --git a/Unicity.Renderer/Shapes/Shape.cs b/Unicity.Renderer/Shapes/Shape.cs
new file mode 100644
index 0000000..b051a89
--- /dev/null
+++ b/Unicity.Renderer/Shapes/Shape.cs
@@ -0,0 +1,17 @@
+using System;
+using static Unicity.Renderer.GraphicsRenderer;
+
+namespace Unicity.Renderer.Shapes
+{
+ public class Shape : IDisposable
+ {
+ protected uint[] buffers = new uint[1];
+
+ public void Dispose()
+ {
+ GL.DeleteBuffers(1, buffers);
+ }
+
+ internal virtual void Render() { }
+ }
+}
diff --git a/Unicity.Renderer/Shapes/Triangle.cs b/Unicity.Renderer/Shapes/Triangle.cs
new file mode 100644
index 0000000..2aec109
--- /dev/null
+++ b/Unicity.Renderer/Shapes/Triangle.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Drawing;
+using static Unicity.Renderer.GraphicsRenderer;
+using static SharpGL.OpenGL;
+
+namespace Unicity.Renderer.Shapes
+{
+ public class Triangle : Shape
+ {
+ public Triangle(PointF pos1, PointF pos2, PointF pos3)
+ {
+ Init(pos1.X, pos1.Y, pos2.X, pos2.Y, pos3.X, pos3.Y);
+ }
+
+ public Triangle(float x1, float y1, float x2, float y2, float x3, float y3)
+ {
+ Init(x1, y1, x2, y2, x3, y3);
+ }
+
+ private void Init(float x1, float y1, float x2, float y2, float x3, float y3)
+ {
+ float[] data =
+ {
+ x1, y1,
+ x2, y2,
+ x3, y3
+ };
+
+ GL.GenBuffers(1, buffers);
+ GL.BindBuffer(GL_ARRAY_BUFFER, buffers[0]);
+ GL.BufferData(GL_ARRAY_BUFFER, data, GL_STATIC_DRAW);
+ }
+
+ internal override void Render()
+ {
+ GL.EnableVertexAttribArray(0);
+ GL.BindBuffer(GL_ARRAY_BUFFER, buffers[0]);
+ GL.VertexAttribPointer(0, 2, GL_FLOAT, false, 0, IntPtr.Zero);
+ GL.DrawArrays(GL_TRIANGLES, 0, 3);
+ GL.DisableVertexAttribArray(0);
+ }
+ }
+}