Files
voxel/Triangle.cs
2025-08-26 16:50:01 +02:00

49 lines
1.3 KiB
C#

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);
}
}
}