-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGraphics.cpp
More file actions
110 lines (92 loc) · 2.11 KB
/
Graphics.cpp
File metadata and controls
110 lines (92 loc) · 2.11 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
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
#include "stdafx.h"
#include "Graphics.h"
#include "System.h"
#include "OpenGLClass.h"
#include "guitext.h"
Graphics::Graphics()
{
openglclass = nullptr;
guitext = nullptr;
}
Graphics::Graphics(const Graphics&)
{
}
Graphics* Graphics::createInstance()
{
static bool exists = false;
if (!exists)
{
exists = true;
return new Graphics();
}
else
{
Error("Can not create multiple instances of System.");
return nullptr;
}
}
bool Graphics::initialise()
{
openglclass = new OpenGLClass();
guitext = new GuiText();
if (openglclass == nullptr || guitext == nullptr) return false;
if (!openglclass->initialise() || !guitext->initialise()) return false;
initialiseScreenQuad();
return true;
}
void Graphics::shutdown()
{
if (openglclass)
{
openglclass->shutdown();
delete openglclass;
}
if (guitext)
{
guitext->shutdown();
delete guitext;
}
}
void Graphics::beginScene()
{
openglclass->beginScene();
}
void Graphics::endScene()
{
openglclass->lightPass(systemptr->gamestate.m_world->m_lights);
guiPass();
openglclass->present();
openglclass->clear(true, true, true);
}
void Graphics::resize(int width, int height, GameState* state)
{
systemptr->displaySet.screenWidth = width;
systemptr->displaySet.screenHeight = height;
state->updateProjectionMatrixAspect(float(width), float(height),
systemptr->cameraSet.fov, systemptr->cameraSet.cameraZNear, systemptr->cameraSet.cameraZFar);
openglclass->resize(width, height);
}
void Graphics::prepareGeomPass()
{
openglclass->prepareGeomPass();
}
void Graphics::prepareShadowPass()
{
openglclass->prepareShadowPass();
}
void Graphics::guiPass()
{
guitext->draw();
}
void Graphics::initialiseScreenQuad()
{
screenQuad.quad[0] = Vertex2D(-1.f, -1.f, 0.f, 0.f);
screenQuad.quad[1] = Vertex2D(1.f, -1.f, 1.f, 0.f);
screenQuad.quad[2] = Vertex2D(-1.f, 1.f, 0.f, 1.f);
screenQuad.quad[3] = Vertex2D(-1.f, 1.f, 0.f, 1.f),
screenQuad.quad[4] = Vertex2D(1.f, -1.f, 1.f, 0.f);
screenQuad.quad[5] = Vertex2D(1.f, 1.f, 1.f, 1.f);
screenQuad.VAO = ~0u;
screenQuad.VBO = ~0u;
openglclass->initialiseScreenQuad(screenQuad.quad, screenQuad.VBO, screenQuad.VAO);
}