diff options
| author | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
|---|---|---|
| committer | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
| commit | 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 (patch) | |
| tree | 428986b49c32e21d3f7a3c2dfa41858ae0153209 /07-july/src/texture.c | |
Initial commit
Diffstat (limited to '07-july/src/texture.c')
| -rw-r--r-- | 07-july/src/texture.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/07-july/src/texture.c b/07-july/src/texture.c new file mode 100644 index 0000000..26fddde --- /dev/null +++ b/07-july/src/texture.c @@ -0,0 +1,47 @@ +#include "texture.h" +#include "util/util.h" + +#include <SDL2/SDL.h> +#include <SDL2/SDL_image.h> + +texture_t* Texture_Create( const char* path ) +{ + texture_t* texture = (texture_t*) malloc( sizeof(texture_t) ); + SDL_Surface* data = IMG_Load(path); + if(data == NULL) + Util_FatalError("Texture could not be found!\n"); + + glGenTextures(1, &texture->ID); + glBindTexture(GL_TEXTURE_2D, texture->ID); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data->w, data->h, GL_FALSE, GL_RGBA, GL_UNSIGNED_BYTE, data->pixels); + 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_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + + SDL_FreeSurface(data); + glBindTexture(GL_TEXTURE_2D, 0); + + texture->width = data->w; + texture->height = data->h; + + return texture; +} + +void Texture_Bind(texture_t* texture) +{ + glBindTexture(GL_TEXTURE_2D, texture->ID); +} + +void Texture_Unbind() +{ + glBindTexture(GL_TEXTURE_2D, 0); +} + +void Texture_Destroy(texture_t* texture) +{ + glDeleteTextures(1, &texture->ID); + free(texture); +} |
