-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScene.cpp
More file actions
145 lines (101 loc) · 3.93 KB
/
Copy pathScene.cpp
File metadata and controls
145 lines (101 loc) · 3.93 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
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
#include "Scene.h"
#include "Window.h"
Scene::Scene()
{
world = new World();
shader = new Shader("Shaders/Voxel.vert", "Shaders/Voxel.frag", "Shaders/Voxel.geom");
std::vector<TileImage> tiles;
tiles.push_back(TileImage("Images/Cobble/cobblestone.png", "Images/Cobble/cobblestone_n.png", "Images/Cobble/cobblestone_s.png"));//0
tiles.push_back(TileImage("Images/Dirt/dirt.png", "Images/Dirt/dirt_n.png", "Images/Dirt/dirt_s.png"));//1
tiles.push_back(TileImage("Images/Grass/grass_block_side.png", "Images/Grass/grass_block_side_n.png", "Images/Grass/grass_block_side_s.png"));//2
tiles.push_back(TileImage("Images/Grass/grass_block_top_greened.png", "Images/Grass/grass_block_top_n.png", "Images/Grass/grass_block_top_s.png"));//3
tiles.push_back(TileImage("Images/Stone/stone.png", "Images/Stone/stone_n.png", "Images/Stone/stone_s.png"));//4
tiles.push_back(TileImage("Images/Diamond/diamond_ore.png", "Images/Diamond/diamond_ore_n.png", "Images/Diamond/diamond_ore_s.png"));//5
tiles.push_back(TileImage("Images/Light/Light_Surface.png", "Images/Light/Light_Surface_n.png", "Images/Light/Light_Surface.png"));//6
textureAtlas = new TextureAtlas(256, 0, tiles);
textureAtlas->Build();
LightHandler::Init();
}
Scene::~Scene()
{
}
void Scene::RenderUI()
{
glUseProgram(0);
// Display parameters
glColor3f(1,1,1);
glWindowPos2i(5,5);
Print("Block to place: %s", world->GetPlacementBlockName().c_str());
}
void Scene::Render(glm::mat4 projection)
{
CheckForBlockChange();
world->Update(projection);
if(Input::GetKeyPressed(KeyCode::B))
{
firstAmbient = !firstAmbient;
}
LightHandler::BuildShadows(this);
//main rendering
textureAtlas->Load(GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2);
glViewport(0, 0, Window::GetWidth(), Window::GetHeight());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
LightHandler::RenderLights(projection, Camera::GetView());
shader->use();
//shader->setInt("tiles", textureAtlas->GetID());
//setup texture positions
shader->setInt("tiles", 0);
shader->setInt("normals", 1);
shader->setInt("speculars", 2);
shader->setInt("depthArrayMap", 3);
shader->setInt("directionalDepthMap", 4);
if(firstAmbient)
{
//first ambient value
shader->setFloat("ambient", 0.05f);
}
else
{
//second ambient value
shader->setFloat("ambient", 0.25f);
}
//glBindVertexArray(VAO); // seeing as we only have a single VAO there's no need to bind it every time, but we'll do so to keep things a bit more organized
//glDrawArrays(GL_TRIANGLES, 0, 6);
shader->setVec3("viewPos", Camera::GetPosition());
LightHandler::SetUpLights(shader);
RenderScene(shader, projection, Camera::GetView());
}
void Scene::RenderScene(Shader* shader, glm::mat4 projection, glm::mat4 view)
{
//model = glm::translate(model, glm::vec3(5, 0, 0));
shader->setInt("totalImages", textureAtlas->GetTotalImages());
shader->setInt("imgSize", textureAtlas->GetImageSizes());
shader->setInt("spacing", textureAtlas->GetSpacing());
//shader->setMat4("projection", projection);
//shader->setMat4("view", view);
shader->setMat4("projectionView", projection * view);
world->Render(shader);
}
void Scene::CheckForBlockChange()
{
if(Input::GetKeyPressed(KeyCode::ALPHA_1))
{
world->ChangePlacementBlock(BlockType::cobble);
}
if(Input::GetKeyPressed(KeyCode::ALPHA_2))
{
world->ChangePlacementBlock(BlockType::light);
}
if(Input::GetKeyPressed(KeyCode::ALPHA_3))
{
world->ChangePlacementBlock(BlockType::grass);
}
if(Input::GetKeyPressed(KeyCode::ALPHA_4))
{
world->ChangePlacementBlock(BlockType::diamond);
}
if(Input::GetKeyPressed(KeyCode::ALPHA_5))
{
world->ChangePlacementBlock(BlockType::stone);
}
}