Add files via upload

This commit is contained in:
MihailRis 2021-04-25 16:08:48 +03:00 • committed by GitHub
commit e1cdcf01e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 2866 additions and 0 deletions

31
src/graphics/Texture.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "Texture.h"
#include <GL/glew.h>
Texture::Texture(unsigned int id, int width, int height) : id(id), width(width), height(height) {
}
Texture::Texture(unsigned char* data, int width, int height) : width(width), height(height) {
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
}
Texture::~Texture() {
glDeleteTextures(1, &id);
}
void Texture::bind(){
glBindTexture(GL_TEXTURE_2D, id);
}
void Texture::reload(unsigned char* data){
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data);
glBindTexture(GL_TEXTURE_2D, 0);
}