annotate 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 |
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@0
|
25 static int next_pow2(int x)
|
nuclear@0
|
26 {
|
nuclear@0
|
27 --x;
|
nuclear@0
|
28 x |= x >> 1;
|
nuclear@0
|
29 x |= x >> 2;
|
nuclear@0
|
30 x |= x >> 4;
|
nuclear@0
|
31 x |= x >> 8;
|
nuclear@0
|
32 return x + 1;
|
nuclear@0
|
33 }
|