Add project files.
This commit is contained in:
48
Triangle.cs
Normal file
48
Triangle.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Voxel
|
||||
{
|
||||
|
||||
public class Triangle
|
||||
{
|
||||
private int _vao;
|
||||
private Shader _shader;
|
||||
|
||||
public Triangle()
|
||||
{
|
||||
string vertexPath = "Shaders/shader.vert";
|
||||
string fragmentPath = "Shaders/shader.frag";
|
||||
_shader = new Shader(vertexPath, fragmentPath);
|
||||
|
||||
float[] vertices =
|
||||
{
|
||||
-0.5f, -0.5f, 0.0f, //top
|
||||
0.5f, -0.5f, 0.0f, // bottom right
|
||||
0.0f, 0.5f, 0.0f // bottom left
|
||||
};
|
||||
|
||||
_vao = GL.GenVertexArray();
|
||||
GL.BindVertexArray(_vao);
|
||||
|
||||
int vbo = GL.GenBuffer();
|
||||
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);
|
||||
|
||||
_shader.Use();
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
GL.BindVertexArray(_vao);
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user