Improve Texture::genColor, Resource::loadResource

This commit is contained in:
MrLetsplay 2023-09-13 20:51:10 +02:00
parent 74367e5fb0
commit 21f3638c7d
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
2 changed files with 14 additions and 7 deletions

View File

@ -70,13 +70,20 @@ std::shared_ptr<Texture> Texture::load(std::string texturePath) {
} }
std::shared_ptr<Texture> Texture::generateColor(glm::vec3 color) { std::shared_ptr<Texture> Texture::generateColor(glm::vec3 color) {
unsigned char *data = (unsigned char *) malloc(3 * sizeof(unsigned char)); unsigned char data[3] = {
data[0] = (unsigned char) (color.x * 255); (unsigned char) (color.x * 255),
data[1] = (unsigned char) (color.y * 255); (unsigned char) (color.y * 255),
data[2] = (unsigned char) (color.z * 255); (unsigned char) (color.z * 255),
float borderColor[4] = {color.x, color.y, color.z, 1.0f}; };
float borderColor[4] = {
color.x,
color.y,
color.z,
1.0f,
};
GLuint tex = allocTexture(data, 1, 1, borderColor); GLuint tex = allocTexture(data, 1, 1, borderColor);
free(data);
return std::make_shared<Texture>(tex); return std::make_shared<Texture>(tex);
} }

View File

@ -43,7 +43,7 @@ MemoryBuffer *loadResource(std::string path) {
return nullptr; return nullptr;
} }
void *buf = malloc(h.size); void *buf = calloc(1, h.size);
r = mtar_read_data(&resources, buf, h.size); r = mtar_read_data(&resources, buf, h.size);
if(r != MTAR_ESUCCESS) { if(r != MTAR_ESUCCESS) {
std::cerr << "Failed to read resource '" << path << "': " << mtar_strerror(r) << std::endl; std::cerr << "Failed to read resource '" << path << "': " << mtar_strerror(r) << std::endl;