restructure v2
This commit is contained in:
parent
e01595e155
commit
dc5654ba9a
20 changed files with 910 additions and 791 deletions
47
engine/Backend/Texture.cpp
Normal file
47
engine/Backend/Texture.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
#include "Texture.h"
|
||||
#include <iostream>
|
||||
#include <glad/glad.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
Texture::Texture(const char* texturePath, bool flip)
|
||||
{
|
||||
// Create the Texture and set our ID
|
||||
glGenTextures(1, &ID);
|
||||
glBindTexture(GL_TEXTURE_2D, ID);
|
||||
|
||||
// set the texture wrapping/filtering options (on the currently bound texture object)
|
||||
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_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
// Grab the texture from our path
|
||||
if (flip)
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
|
||||
unsigned char *data = stbi_load(texturePath, &width, &height, &nrChannels, 0);
|
||||
if (data)
|
||||
{
|
||||
GLenum format = (nrChannels == 4) ? GL_RGBA : GL_RGB;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to load texture" << std::endl;
|
||||
}
|
||||
|
||||
if (flip)
|
||||
stbi_set_flip_vertically_on_load(false);
|
||||
|
||||
stbi_image_free(data);
|
||||
}
|
||||
|
||||
void Texture::Draw() const
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, ID);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue