13 #define STB_IMAGE_IMPLEMENTATION 14 #include <stb_image.h> 22 void TextureManager::remove(std::string name) {
28 Manager::remove(name);
31 void TextureManager::clear() {
33 for (map<string, Texture*>::iterator it = objects.begin(); it != objects.end(); it++) {
42 Texture* TextureManager::load(std::string path, std::string name) {
44 stbi_set_flip_vertically_on_load(
true);
53 texture->setWrapS(TextureWrap::CLAMP_TO_BORDER);
54 texture->setWrapT(TextureWrap::CLAMP_TO_BORDER);
55 texture->setMinFilter(TextureFilter::LINEAR);
56 texture->setMagFilter(TextureFilter::LINEAR);
59 texture->uploadImage(image);
60 stbi_image_free(image.
pixels);
67 void ShaderManager::remove(std::string name) {
69 Shader* shader =
get(name);
73 Manager::remove(name);
76 void ShaderManager::clear() {
78 for (map<string, Shader*>::iterator it = objects.begin(); it != objects.end(); it++) {
79 Shader* shader = it->second;
87 Shader* ShaderManager::loadShader(std::string path, std::string name,
ShaderType type) {
89 ifstream fileStream(path);
90 if (fileStream.is_open()) {
93 while (fileStream.good()) {
95 getline(fileStream, line);
96 source.append(line +
"\n");
114 Logger::logError(
"Could not open file " + path);
119 ShaderProgram* ShaderManager::loadShaderProgram(std::string vertexPath, std::string fragmentPath, std::string vertexName, std::string fragmentName) {
121 Shader* vertexShader = loadShader(vertexPath, vertexName, ShaderType::VERTEX_SHADER);
122 Shader* fragmentShader = loadShader(fragmentPath, fragmentName, ShaderType::FRAGMENT_SHADER);
126 shaderProgram->
attach(vertexShader);
127 shaderProgram->
attach(fragmentShader);
128 shaderProgram->
link();
132 Logger::logError(shaderProgram->
getInfoLog());
136 return shaderProgram;
139 ShaderProgram* ShaderManager::createShaderProgram(std::string vertexName, std::string fragmentName) {
141 Shader* vertexShader =
get(vertexName);
142 Shader* fragmentShader =
get(fragmentName);
146 shaderProgram->
attach(vertexShader);
147 shaderProgram->
attach(fragmentShader);
148 shaderProgram->
link();
152 Logger::logError(shaderProgram->
getInfoLog());
156 return shaderProgram;
This structure stores texture image data.
This class wraps an OpenGL shader object.
unsigned char * pixels
The pixel data of the image.
ShaderType
This enum wraps the shader types.
int height
The height of the image.
void compile()
Compiles the shader object.
void source(std::string source)
Sets the source code of the shader object.
This class wraps an OpenGL shader program.
int components
The number of color channels.
Generic namespace for the SimpleGL framework.
This class wraps an OpenGL texture object.
void attach(Shader *shader)
Attaches a shader object to the shader program.
bool getLinkStatus()
Checks the link status of the shader program.
std::string getInfoLog()
Gets the info log of the shader program.
bool getCompileStatus()
Checks the compile status of the shader object.
std::string getInfoLog()
Gets the info log of the shader object.
void link()
Links the shader program.
int width
The width of the image.