-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphics.cs
More file actions
44 lines (36 loc) · 1.57 KB
/
Graphics.cs
File metadata and controls
44 lines (36 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using OpenTK.Graphics.OpenGL;
using System;
using System.IO;
namespace SuperJet
{
public class Graphics
{
public static int LoadTexture(string filePath)
{
if (string.IsNullOrEmpty(filePath))
throw new ArgumentException("File path cannot be null or empty.", nameof(filePath));
if (!File.Exists(filePath))
throw new FileNotFoundException("The image file was not found.", filePath);
if (!File.Exists(filePath))
throw new FileNotFoundException("The model file is missing. Double check it if it still exists, and try again.", filePath);
int vertexArrayObject;
GL.GenVertexArrays(1, out vertexArrayObject);
GL.BindVertexArray(vertexArrayObject);
int vertexBufferObject;
GL.GenBuffers(1, out vertexBufferObject);
GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferObject);
float[] vertices =
{
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);
int positionLocation = 0;
GL.VertexAttribPointer(positionLocation, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
GL.EnableVertexAttribArray(positionLocation);
GL.BindVertexArray(0);
return vertexArrayObject;
}
}
}