-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResource.cpp
129 lines (122 loc) · 4.34 KB
/
Resource.cpp
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
#include "Resource.h"
#include "SimpleIlluminationModelShaderProgram.h"
#include "TextureShaderProgram.h"
#include "NormalMappingProgram.h"
#include "ParallaxOcclusionProgram.h"
#include "MovingTexShader.h"
#include <GL/SOIL.h>
Texture * createTextureFromFile(const std::string & fileName) {
std::string path = "resources/" + fileName;
Texture * tex = new Texture(SOIL_load_OGL_texture(
path.c_str(),
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y
));
return tex;
}
Vector3f sun = { 50, 100, 50 };
namespace Resource {
std::map<Meshes::Id, Mesh *> meshes;
std::map<ShaderPrograms::Id, ShaderProgram *> shaderPrograms;
std::map<Textures::Id, Texture *> textures;
void init() {
meshes[Meshes::Plane] = new Mesh(Mesh::createFromDatFile("resources/plane.dat"));
meshes[Meshes::Blockside] = new Mesh(Mesh::createFromDatFile("resources/plane.dat"));
meshes[Meshes::Arrow] = new Mesh(Mesh::createFromDatFile("resources/arrow.dat"));
meshes[Meshes::Particle] = new Mesh(Mesh::createFromDatFile("resources/particle.dat"));
meshes[Meshes::Skybox] = new Mesh(Mesh::createFromDatFile("resources/skybox.dat"));
textures[Textures::Metal] = createTextureFromFile("metalDif.jpg");
textures[Textures::MetalNormal] = createTextureFromFile("metalNorm.jpg");
textures[Textures::MetalHeight] = createTextureFromFile("metalHeight.jpg");
textures[Textures::WaterNormal] = createTextureFromFile("water_normal.png");
textures[Textures::Cobble] = createTextureFromFile("cobble.png");
textures[Textures::CobbleNormal] = createTextureFromFile("cobble_normal.png");
textures[Textures::CobbleHeight] = createTextureFromFile("cobble_height.png");
textures[Textures::CobbleSpecular] = createTextureFromFile("cobble_specular.png");
textures[Textures::AlphaCircle] = createTextureFromFile("alphacircle.png");
textures[Textures::Skybox] = new Texture(Texture::loadTextureFromFile("resources/bluecloud.jpg"));
shaderPrograms[ShaderPrograms::Phong] = new SimpleIlluminationModelShaderProgram(
SimpleIlluminationModelShaderProgram::createPhong()
.setLightVector(sun)
.enableLightVectorAsPosition(true)
);
shaderPrograms[ShaderPrograms::SimpleTexture] = new TextureShaderProgram(
static_cast<TextureShaderProgram &>(
TextureShaderProgram::create()
.setLightVector(sun)
.enableLightVectorAsPosition(true)
.setSpecularRatio(10)
)
);
shaderPrograms[ShaderPrograms::MetalNormal] = new NormalMappingProgram(
static_cast<NormalMappingProgram&>(
NormalMappingProgram::create()
.setAmbientRatio(0.3f)
.setDiffusionRatio(0.7f)
.setSpecularRatio(0.5f)
.setLightVector(sun)
.enableLightVectorAsPosition(true)
)
);
shaderPrograms[ShaderPrograms::MetalParallax] = new ParallaxOcclusionProgram(
static_cast<ParallaxOcclusionProgram&>(
ParallaxOcclusionProgram::create()
.setAmbientRatio(0.3f)
.setDiffusionRatio(0.6f)
.setSpecularRatio(0.5f)
.setLightVector(sun)
.enableLightVectorAsPosition(true)
)
);
shaderPrograms[ShaderPrograms::Water] = new MovingTexShader(
static_cast<MovingTexShader&>(
MovingTexShader::create()
.setAmbientRatio(0.2f)
.setDiffusionRatio(0.4f)
.setSpecularRatio(0.8f)
.setShiness(16)
.setLightVector(sun)
.enableLightVectorAsPosition(true)
)
);
shaderPrograms[ShaderPrograms::Sea] = new MovingTexShader(
static_cast<MovingTexShader&>(
MovingTexShader::create()
.setAmbientRatio(0.4f)
.setDiffusionRatio(0.4f)
.setSpecularRatio(0.8f)
.setShiness(16)
.setLightVector(sun)
.enableLightVectorAsPosition(true)
)
);
shaderPrograms[ShaderPrograms::Skybox] = new TextureShaderProgram(
static_cast<TextureShaderProgram &>(
TextureShaderProgram::create()
.setAmbientRatio(1.0f)
.setDiffusionRatio(0.0f)
.setSpecularRatio(0.0f)
)
);
shaderPrograms[ShaderPrograms::Cobble] = new ParallaxOcclusionProgram(
static_cast<ParallaxOcclusionProgram &>(
ParallaxOcclusionProgram::create()
.setAmbientRatio(0.4f)
.setDiffusionRatio(0.6f)
.setSpecularRatio(0.5f)
.setShiness(32)
.setLightVector(sun)
.enableLightVectorAsPosition(true)
)
);
}
void uninit() {
for (const std::pair<Meshes::Id, Mesh *> & pair : meshes) {
delete pair.second;
}
for (const std::pair<ShaderPrograms::Id, ShaderProgram *> & pair : shaderPrograms) {
delete pair.second;
}
}
}