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/Shapes | |
| parent | 5d4b4023bddd12e27c6756793aea2ff36d49e124 (diff) | |
| download | Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.tar.gz Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.tar.bz2 Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.zip | |
3d support
Diffstat (limited to 'Unicity.Renderer/Shapes')
| -rw-r--r-- | Unicity.Renderer/Shapes/Rectangle.cs | 26 | ||||
| -rw-r--r-- | Unicity.Renderer/Shapes/Shape.cs | 12 | ||||
| -rw-r--r-- | Unicity.Renderer/Shapes/Triangle.cs | 59 |
3 files changed, 65 insertions, 32 deletions
diff --git a/Unicity.Renderer/Shapes/Rectangle.cs b/Unicity.Renderer/Shapes/Rectangle.cs new file mode 100644 index 0000000..2239426 --- /dev/null +++ b/Unicity.Renderer/Shapes/Rectangle.cs @@ -0,0 +1,26 @@ +namespace Unicity.Renderer.Shapes +{ + public class Rectangle : Shape + { + Triangle rect1 = null; + Triangle rect2 = null; + + public Rectangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4) + { + rect1 = new Triangle(x1, y1, z1, x2, y2, z2, x3, y3, z3); + rect2 = new Triangle(x3, y3, z3, x2, y2, z2, x4, y4, z4); + } + + internal override void Draw(Shader shader, GraphicsRenderer renderer) + { + rect1.Draw(shader, renderer); + rect2.Draw(shader, renderer); + } + + public override void Dispose() + { + rect1.Dispose(); + rect2.Dispose(); + } + } +} diff --git a/Unicity.Renderer/Shapes/Shape.cs b/Unicity.Renderer/Shapes/Shape.cs index b051a89..8e6e322 100644 --- a/Unicity.Renderer/Shapes/Shape.cs +++ b/Unicity.Renderer/Shapes/Shape.cs @@ -1,17 +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() + internal virtual void Draw(Shader shader, GraphicsRenderer renderer) { - GL.DeleteBuffers(1, buffers); + } - internal virtual void Render() { } + public virtual void Dispose() + { + + } } } diff --git a/Unicity.Renderer/Shapes/Triangle.cs b/Unicity.Renderer/Shapes/Triangle.cs index 2aec109..7ab94e2 100644 --- a/Unicity.Renderer/Shapes/Triangle.cs +++ b/Unicity.Renderer/Shapes/Triangle.cs @@ -1,43 +1,50 @@ -using System; -using System.Drawing; -using static Unicity.Renderer.GraphicsRenderer; -using static SharpGL.OpenGL; +using OpenTK.Graphics.OpenGL4; 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); - } + int vao = 0; + int vbo = 0; - public Triangle(float x1, float y1, float x2, float y2, float x3, float y3) - { - Init(x1, y1, x2, y2, x3, y3); - } + float[] vertices = null; - private void Init(float x1, float y1, float x2, float y2, float x3, float y3) + public Triangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) { - float[] data = + vertices = new float[] { - x1, y1, - x2, y2, - x3, y3 + x1, y1, z1, + x2, y2, z2, + x3, y3, z3 }; - GL.GenBuffers(1, buffers); - GL.BindBuffer(GL_ARRAY_BUFFER, buffers[0]); - GL.BufferData(GL_ARRAY_BUFFER, data, GL_STATIC_DRAW); + vao = GL.GenVertexArray(); + vbo = GL.GenBuffer(); + + GL.BindVertexArray(vao); + GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); + + GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw); + + GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0); + GL.EnableVertexAttribArray(0); + } - internal override void Render() + internal override void Draw(Shader shader, GraphicsRenderer renderer) { - 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); + GL.BindVertexArray(vao); + GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); + + float[] newVertices = new float[vertices.Length]; + + GL.DrawArrays(PrimitiveType.Triangles, 0, 3); + } + + public override void Dispose() + { + GL.BindBuffer(BufferTarget.ArrayBuffer, 0); + GL.DeleteBuffer(vbo); } } } |
