xgetshape
diff src/texture.c @ 0:2f02f100b20f
getting the window shape of another window
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 03 Nov 2015 00:42:08 +0200 |
parents | |
children | 9b560415bad4 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/texture.c Tue Nov 03 00:42:08 2015 +0200 1.3 @@ -0,0 +1,33 @@ 1.4 +#include <GL/gl.h> 1.5 +#include "texture.h" 1.6 + 1.7 +static int next_pow2(int x); 1.8 + 1.9 +int image_texture(struct texture *tex, struct image *img) 1.10 +{ 1.11 + glGenTextures(1, &tex->id); 1.12 + glBindTexture(GL_TEXTURE_2D, tex->id); 1.13 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.14 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.15 + 1.16 + tex->width = img->width; 1.17 + tex->height = img->height; 1.18 + tex->tex_width = next_pow2(tex->width); 1.19 + tex->tex_height = next_pow2(tex->height); 1.20 + 1.21 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->tex_width, tex->tex_height, 0, 1.22 + GL_RGBA, GL_UNSIGNED_BYTE, 0); 1.23 + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex->width, tex->height, 1.24 + GL_RGBA, GL_UNSIGNED_BYTE, img->pixels); 1.25 + return 0; 1.26 +} 1.27 + 1.28 +static int next_pow2(int x) 1.29 +{ 1.30 + --x; 1.31 + x |= x >> 1; 1.32 + x |= x >> 2; 1.33 + x |= x >> 4; 1.34 + x |= x >> 8; 1.35 + return x + 1; 1.36 +}