xgetshape

view src/texture.c @ 1:9b560415bad4

blured shadow
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 03 Nov 2015 04:08:32 +0200
parents 2f02f100b20f
children
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 void destroy_texture(struct texture *tex)
26 {
27 glDeleteTextures(1, &tex->id);
28 tex->id = 0;
29 }
31 static int next_pow2(int x)
32 {
33 --x;
34 x |= x >> 1;
35 x |= x >> 2;
36 x |= x >> 4;
37 x |= x >> 8;
38 return x + 1;
39 }