first commit
This commit is contained in:
31
textureManager/texture.cpp
Normal file
31
textureManager/texture.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
|
||||
Texture::Texture()
|
||||
: Width(0), Height(0), Internal_Format(GL_RGBA), Image_Format(GL_RGBA), Wrap_S(GL_REPEAT), Wrap_T(GL_REPEAT), Filter_Min(GL_LINEAR), Filter_Mag(GL_NEAREST)
|
||||
{
|
||||
glGenTextures(1, &this->ID);
|
||||
}
|
||||
|
||||
void Texture::generate(GLuint width, GLuint height, unsigned char* data)
|
||||
{
|
||||
this->Width = width;
|
||||
this->Height = height;
|
||||
// Create Texture
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, this->Internal_Format, width, height, 0, this->Image_Format, GL_UNSIGNED_BYTE, data);
|
||||
// Set Texture wrap and filter modes
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, this->Wrap_S);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, this->Wrap_T);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, this->Filter_Min);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, this->Filter_Mag);
|
||||
// Unbind texture
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void Texture::bind() const
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
}
|
||||
27
textureManager/texture.h
Normal file
27
textureManager/texture.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
// Texture2D is able to store and configure a texture in OpenGL.
|
||||
// It also hosts utility functions for easy management.
|
||||
#include <GLAD/glad.h>
|
||||
|
||||
class Texture
|
||||
{
|
||||
public:
|
||||
// Holds the ID of the texture object, used for all texture operations to reference to this particlar texture
|
||||
GLuint ID;
|
||||
// Texture image dimensions
|
||||
GLuint Width, Height; // Width and height of loaded image in pixels
|
||||
// Texture Format
|
||||
GLuint Internal_Format; // Format of texture object
|
||||
GLuint Image_Format; // Format of loaded image
|
||||
// Texture configuration
|
||||
GLuint Wrap_S; // Wrapping mode on S axis
|
||||
GLuint Wrap_T; // Wrapping mode on T axis
|
||||
GLuint Filter_Min; // Filtering mode if texture pixels < screen pixels
|
||||
GLuint Filter_Mag; // Filtering mode if texture pixels > screen pixels
|
||||
// Constructor (sets default texture modes)
|
||||
Texture();
|
||||
// Generates texture from image data
|
||||
void generate(GLuint width, GLuint height, unsigned char* data);
|
||||
// Binds the texture as the current active GL_TEXTURE_2D texture object
|
||||
void bind() const;
|
||||
};
|
||||
Reference in New Issue
Block a user