From 7b214503608550dc2853b9e01526723f8c65baf3 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 12 May 2020 14:14:06 +0200 Subject: Added mat4 in libftm, can rotate, scale and translate vector --- src/texture.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/texture.c (limited to 'src/texture.c') diff --git a/src/texture.c b/src/texture.c new file mode 100644 index 0000000..e499af6 --- /dev/null +++ b/src/texture.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* texture.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/11 14:27:34 by charles #+# #+# */ +/* Updated: 2020/05/11 16:19:56 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "scop.h" + +uint8_t *st_read_bmp(char *filepath, size_t *width, size_t *height) +{ + t_ftmem file; + + if (ft_getfile(open(filepath, O_RDONLY), &file) == -1) + return (NULL); + *width = 0; + *height = 0; + return (file.data); +} + +unsigned int texture_new(char *filepath) +{ + uint8_t *data; + unsigned int texture; + size_t width; + size_t height; + + if ((data = st_read_bmp(filepath, &width, &height)) == NULL) + return (0); + GL_CALL(glGenTextures(1, &texture)); + GL_CALL(glBindTexture(GL_TEXTURE_2D, texture)); + GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); + GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); + GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data)); + free(data); + return (texture); +} -- cgit