-
Notifications
You must be signed in to change notification settings - Fork 1
/
Skybox.cs
98 lines (86 loc) · 3.87 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Tao.OpenGl;
namespace GL_Depth
{
class Skybox
{
int[] skybox;
public void initBox()
{
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP);
}
public void renderBox(float angleX, float angleZ)
{
// Store the current matrix
Gl.glPushMatrix();
// Reset and transform the matrix.
Gl.glLoadIdentity();
Gl.glRotatef(angleX, 1, 0, 0);
Gl.glRotatef(angleZ, 0, 0, 1);
// Enable/Disable features
Gl.glPushAttrib(Gl.GL_ENABLE_BIT);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glDisable(Gl.GL_DEPTH_TEST);
Gl.glDisable(Gl.GL_LIGHTING);
Gl.glDisable(Gl.GL_BLEND);
// Just in case we set all vertices to white.
Gl.glColor4f(1, 1, 1, 1);
// Render the front quad
Gl.glBindTexture(Gl.GL_TEXTURE_2D, skybox[0]);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(0.5f, -0.5f, -0.5f);
Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-0.5f, -0.5f, -0.5f);
Gl.glTexCoord2f(1, 1); Gl.glVertex3f(-0.5f, 0.5f, -0.5f);
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(0.5f, 0.5f, -0.5f);
Gl.glEnd();
// Render the left quad
Gl.glBindTexture(Gl.GL_TEXTURE_2D, skybox[1]);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(0.5f, -0.5f, 0.5f);
Gl.glTexCoord2f(1, 0); Gl.glVertex3f(0.5f, -0.5f, -0.5f);
Gl.glTexCoord2f(1, 1); Gl.glVertex3f(0.5f, 0.5f, -0.5f);
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(0.5f, 0.5f, 0.5f);
Gl.glEnd();
// Render the back quad
Gl.glBindTexture(Gl.GL_TEXTURE_2D, skybox[2]);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-0.5f, -0.5f, 0.5f);
Gl.glTexCoord2f(1, 0); Gl.glVertex3f(0.5f, -0.5f, 0.5f);
Gl.glTexCoord2f(1, 1); Gl.glVertex3f(0.5f, 0.5f, 0.5f);
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-0.5f, 0.5f, 0.5f);
Gl.glEnd();
// Render the right quad
Gl.glBindTexture(Gl.GL_TEXTURE_2D, skybox[3]);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-0.5f, -0.5f, -0.5f);
Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-0.5f, -0.5f, 0.5f);
Gl.glTexCoord2f(1, 1); Gl.glVertex3f(-0.5f, 0.5f, 0.5f);
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-0.5f, 0.5f, -0.5f);
Gl.glEnd();
// Render the top quad
Gl.glBindTexture(Gl.GL_TEXTURE_2D, skybox[4]);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-0.5f, 0.5f, -0.5f);
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-0.5f, 0.5f, 0.5f);
Gl.glTexCoord2f(1, 0); Gl.glVertex3f(0.5f, 0.5f, 0.5f);
Gl.glTexCoord2f(1, 1); Gl.glVertex3f(0.5f, 0.5f, -0.5f);
Gl.glEnd();
// Render the bottom quad
Gl.glBindTexture(Gl.GL_TEXTURE_2D, skybox[5]);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-0.5f, -0.5f, -0.5f);
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-0.5f, -0.5f, 0.5f);
Gl.glTexCoord2f(1, 1); Gl.glVertex3f(0.5f, -0.5f, 0.5f);
Gl.glTexCoord2f(1, 0); Gl.glVertex3f(0.5f, -0.5f, -0.5f);
Gl.glEnd();
// Restore enable bits and matrix
Gl.glPopAttrib();
Gl.glPopMatrix();
}
}
}