added new cmake setup, graphics, vendors, obj importer, etc.
This commit is contained in:
23
src/gfx/Texture.cpp
Normal file
23
src/gfx/Texture.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "Texture.h"
|
||||
#include <iostream>
|
||||
#include "loaders/stb_image.h"
|
||||
#include "glad/glad.h"
|
||||
|
||||
auto Texture::init(const char* source_path) -> void {
|
||||
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_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
int nr_channels;
|
||||
auto data = stbi_load(source_path, &width, &height, &nr_channels, 0);
|
||||
if (data) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, 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);
|
||||
}
|
||||
Reference in New Issue
Block a user