Basic Entity Components implementation
This commit is contained in:
40
BarinkEngine/src/Graphics/Primitives/Texture.cpp
Normal file
40
BarinkEngine/src/Graphics/Primitives/Texture.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "Texture.h"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "../stb_image.h"
|
||||
#include <iostream>
|
||||
|
||||
Texture::Texture(const std::string texturePath) {
|
||||
|
||||
int width, height, channels;
|
||||
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
||||
std::cout << channels << std::endl;
|
||||
|
||||
if (data) {
|
||||
glGenTextures(1, &Id);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, Id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
else {
|
||||
spdlog::error("Failed to load image (%s)", texturePath );
|
||||
}
|
||||
stbi_image_free(data);
|
||||
|
||||
}
|
||||
|
||||
void Texture::Bind() {
|
||||
glBindTexture(GL_TEXTURE_2D, Id);
|
||||
}
|
||||
|
||||
void Texture::Unbind() {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
Reference in New Issue
Block a user