xgetshape

view 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 source
1 #include <GL/gl.h>
2 #include "texture.h"
4 static int next_pow2(int x);
6 int image_texture(struct texture *tex, struct image *img)
7 {
8 glGenTextures(1, &tex->id);
9 glBindTexture(GL_TEXTURE_2D, tex->id);
10 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
11 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
13 tex->width = img->width;
14 tex->height = img->height;
15 tex->tex_width = next_pow2(tex->width);
16 tex->tex_height = next_pow2(tex->height);
18 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->tex_width, tex->tex_height, 0,
19 GL_RGBA, GL_UNSIGNED_BYTE, 0);
20 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex->width, tex->height,
21 GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
22 return 0;
23 }
25 static int next_pow2(int x)
26 {
27 --x;
28 x |= x >> 1;
29 x |= x >> 2;
30 x |= x >> 4;
31 x |= x >> 8;
32 return x + 1;
33 }