added texture class, changed shader extension names
This commit is contained in:
parent
95be5f081e
commit
6fb3ffcfed
5 changed files with 58 additions and 53 deletions
47
Engine/engine/texture.h
Normal file
47
Engine/engine/texture.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <stb_image/stb_image.h>
|
||||
|
||||
class Texture
|
||||
{
|
||||
public:
|
||||
unsigned int ID;
|
||||
int width, height, nrChannels;
|
||||
|
||||
Texture(const char* texturePath, bool flip = false)
|
||||
{
|
||||
// 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_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue