1
0
Fork 0
blockofighter/src/material.cpp

53 lines
1 KiB
C++
Raw Normal View History

2014-02-16 14:32:28 +00:00
#include "main.h"
#include "material.h"
#include "glapi.h"
#include "graphics.h"
2015-06-03 12:29:34 +00:00
Material::Material(void) {
setColor(1, 1, 1, 1);
2014-02-16 14:32:28 +00:00
this->texture = new Texture;
}
2015-06-03 12:29:34 +00:00
bool Material::loadTexture(char *path) {
if (!this->texture) {
2014-02-16 14:32:28 +00:00
this->texture = new Texture;
}
2015-06-03 12:29:34 +00:00
if (this->texture->loadImage(path)) {
2014-02-16 14:32:28 +00:00
setColor(1, 1, 1, 1);
return true;
}
return false;
}
2015-06-03 12:29:34 +00:00
void Material::freeTexture(void) { this->texture->~Texture(); }
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void Material::setColor(float red, float green, float blue, float alpha) {
color[0] = red;
color[1] = green;
color[2] = blue;
color[3] = alpha;
2014-02-16 14:32:28 +00:00
}
2015-06-03 12:29:34 +00:00
const float *Material::getColor(void) { return color; }
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void Material::enable(void) {
2014-02-16 14:32:28 +00:00
enabled = true;
2015-06-03 12:29:34 +00:00
glColor4fv(color);
2014-02-16 14:32:28 +00:00
this->texture->enable();
}
2015-06-03 12:29:34 +00:00
void Material::disable(void) {
2014-02-16 14:32:28 +00:00
enabled = false;
this->texture->disable();
}
2015-06-03 12:29:34 +00:00
bool Material::isEnabled(void) { return enabled; }
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
Texture *Material::getTexture(void) { return this->texture; }
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void Material::setTexture(Texture *tex) {
// this->texture->~Texture;
2014-02-16 14:32:28 +00:00
this->texture = tex;
}