-
Notifications
You must be signed in to change notification settings - Fork 0
/
Skybox.cs
84 lines (70 loc) · 2.14 KB
/
Skybox.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace WaterSimulation
{
public class Skybox : RenderedEntity
{
public int cubeScale;
int texID;
float[] verts = new float[72]{
1, -1, 1,
1, 1, 1,
1, 1, -1,
1, -1, -1,
-1, -1, -1,
-1, 1, -1,
-1, 1, 1,
-1, -1, 1,
-1, 1, -1,
1, 1, -1,
1, 1, 1,
-1, 1, 1,
-1, -1, 1,
1, -1, 1,
1, -1, -1,
-1, -1, -1,
1, -1, 1,
-1, -1, 1,
-1, 1, 1,
1, 1, 1,
-1, -1, -1,
1, -1, -1,
1, 1, -1,
-1, 1, -1
};
int vaoID;
int vbo;
public Skybox(int scale, int texID) : base(Vector3.Zero, Vector3.Zero, Vector3.Zero, null, "Skybox", null, null)
{
this.cubeScale = scale;
this.texID = texID;
GL.GenVertexArrays(1, out vaoID);
GL.BindVertexArray(vaoID);
GL.GenBuffers(1, out vbo);
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Length * sizeof(float)), verts, BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 3, 0);
GL.EnableVertexAttribArray(0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.BindVertexArray(0);
}
public override void Draw()
{
GL.Disable(EnableCap.CullFace);
GL.BindVertexArray(vaoID);
GetShader().currentObject = this;
GetShader().Start();
GL.ActiveTexture(TextureUnit.Texture0);
GL.BindTexture(TextureTarget.TextureCubeMap, texID);
GL.DrawArrays(PrimitiveType.Quads, 0, 24);
GetShader().Stop();
GL.BindVertexArray(0);
GL.Enable(EnableCap.CullFace);
}
}
}