update
This commit is contained in:
@@ -3,21 +3,24 @@
|
||||
#include "../lib/loaders/stb_image.h"
|
||||
#include "../lib/glad/glad.h"
|
||||
|
||||
void Texture::init(const char* source_path) {
|
||||
glGenTextures(1, &tex_id);
|
||||
glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||
Texture createTexture(const char* source_path) {
|
||||
Texture result = {0};
|
||||
glGenTextures(1, &result.tex_id);
|
||||
glBindTexture(GL_TEXTURE_2D, result.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_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
int nr_channels;
|
||||
stbi_uc *data = stbi_load(source_path, &width, &height, &nr_channels, 0);
|
||||
stbi_uc *data = stbi_load(source_path, &result.width, &result.height, &nr_channels, 0);
|
||||
if (data) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, result.width, result.height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
} else {
|
||||
std::cout << "Failed to load texture." << std::endl;
|
||||
}
|
||||
stbi_image_free(data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user