xgetshape

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