-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
171 lines (133 loc) · 5.05 KB
/
Game.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using RubiksChallenge.Entities.CubeStructure;
using RubiksChallenge.Environment;
using RubiksChallenge.Properties;
using RubiksChallenge.Textures;
using RubiksChallenge.UserInput;
using Tao.OpenGl;
namespace RubiksChallenge
{
public class Game
{
#region Constructor
public Game()
{
this.BackgroundTexture = TextureLoader.GetTextureLoader().LoadTexture(Resources.Background);
}
#endregion
#region Attributes and Properties
public Texture BackgroundTexture { get; private set; }
#endregion
#region Private Methods
private void DrawBackground()
{
var width = Scene.GetScene().Width;
var height = Scene.GetScene().Height;
this.EnterOrtho();
this.BackgroundTexture.Bind();
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0);
Gl.glVertex2i(0, 0);
Gl.glTexCoord2f(0, 1);
Gl.glVertex2i(0, height);
Gl.glTexCoord2f(1, 1);
Gl.glVertex2i(width, height);
Gl.glTexCoord2f(1, 0);
Gl.glVertex2i(width, 0);
Gl.glEnd();
this.LeaveOrtho();
}
private void DrawAnaglyphStereoscopyBackground()
{
var width = Scene.GetScene().Width;
var height = Scene.GetScene().Height;
this.EnterOrtho();
this.BackgroundTexture.Bind();
Gl.glColorMask(Gl.GL_FALSE, Gl.GL_FALSE, Gl.GL_TRUE, Gl.GL_TRUE);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0);
Gl.glVertex2i(0, 0);
Gl.glTexCoord2f(0, 1);
Gl.glVertex2i(0, height);
Gl.glTexCoord2f(1, 1);
Gl.glVertex2i(width, height);
Gl.glTexCoord2f(1, 0);
Gl.glVertex2i(width, 0);
Gl.glEnd();
Gl.glColorMask(Gl.GL_TRUE, Gl.GL_FALSE, Gl.GL_FALSE, Gl.GL_TRUE);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0);
Gl.glVertex2i(0, 0);
Gl.glTexCoord2f(0, 1);
Gl.glVertex2i(0, height);
Gl.glTexCoord2f(1, 1);
Gl.glVertex2i(width, height);
Gl.glTexCoord2f(1, 0);
Gl.glVertex2i(width, 0);
Gl.glEnd();
this.LeaveOrtho();
}
private void EnterOrtho()
{
var width = Scene.GetScene().Width;
var height = Scene.GetScene().Height;
Gl.glPushAttrib(Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_ENABLE_BIT);
Gl.glPushMatrix();
Gl.glLoadIdentity();
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glPushMatrix();
Gl.glLoadIdentity();
Glu.gluOrtho2D(0, width, 0, height);
Gl.glDisable(Gl.GL_DEPTH_TEST);
Gl.glDisable(Gl.GL_LIGHTING);
}
private void LeaveOrtho()
{
Gl.glPopMatrix();
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glEnable(Gl.GL_DEPTH_TEST);
Gl.glEnable(Gl.GL_LIGHTING);
Gl.glPopMatrix();
Gl.glPopAttrib();
}
#endregion
#region Public Methods
public void Render()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glClearColor(.3f, .3f, .3f, 1f);
this.DrawBackground();
Gl.glLoadIdentity();
Glu.gluLookAt(0f, 0f, 7f, 0f, 0f, -1f, 0f, 1f, 0f);
RubiksCube.GetRubiksCube().Render();
}
public void RenderAnaglyphStereoscopy()
{
var anag = AnaglyphStereoscopy.GetAnaglyphStereoscopy();
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
this.DrawAnaglyphStereoscopyBackground();
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Glu.gluLookAt(0 - anag.EyeSeparation, 0, 7 + anag.EyeDistance,
0, 0, -1,
0, 1, 0);
Gl.glColorMask(Gl.GL_FALSE, Gl.GL_FALSE, Gl.GL_TRUE, Gl.GL_TRUE);
RubiksCube.GetRubiksCube().Render();
Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Glu.gluLookAt(0 + anag.EyeSeparation, 0, 7 + anag.EyeDistance,
0, 0, -1,
0, 1, 0);
Gl.glColorMask(Gl.GL_TRUE, Gl.GL_FALSE, Gl.GL_FALSE, Gl.GL_TRUE);
RubiksCube.GetRubiksCube().Render();
Gl.glColorMask(Gl.GL_TRUE, Gl.GL_TRUE, Gl.GL_TRUE, Gl.GL_TRUE);
}
public void Update()
{
RubiksCube.GetRubiksCube().Update();
if (AnaglyphStereoscopy.GetAnaglyphStereoscopy().Active)
UserInputManager.GetManager().HandleAnaglyphStereoscopy();
}
#endregion
}
}