couch/core/Material.cpp

40 lines
981 B
C++
Raw Normal View History

#include "Material.h"
2021-01-30 15:34:27 -06:00
#include <string>
Texture::Texture() {}
Texture Texture::FromFile(const char *filename) {
Texture tex;
glGenTextures(1, &tex.id);
glBindTexture(GL_TEXTURE_2D, tex.id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
int nrChannels;
2021-01-20 12:50:59 -06:00
unsigned char* data = stbi_load(filename, &tex.width, &tex.height, &nrChannels, 4);
if (data) {
2021-01-20 12:50:59 -06:00
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
} else {
2021-01-30 15:34:27 -06:00
throw std::string() + "Error loading texture file: " + filename;
}
stbi_image_free(data);
return tex;
}
Material::Material() {
usesTex = false;
2021-01-22 18:44:43 -06:00
shininess = 8;
2021-01-20 20:49:12 -06:00
alphaScissor = 0.0f;
2021-01-21 15:26:39 -06:00
unshaded = false;
2021-01-22 15:27:32 -06:00
cullBack = true;
}