forked from ForsakenX/forsaken
/
texture_devil.c
70 lines (59 loc) · 1.4 KB
/
texture_devil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "main.h"
#include "texture.h"
#ifdef TEXTURE_DEVIL
#define IL_STATIC_LIB
#include "IL/il.h"
#include "IL/ilu.h"
#define IMAGE_COMPONENTS 4 // rgba
static int devil_initialized = 0;
static int image_count = 0;
void texture_init( void )
{
if(devil_initialized)
return;
ilInit();
devil_initialized = 1;
}
void destroy_image( texture_image_t * image )
{
ilDeleteImages(1, &image->id);
free(image->data);
}
int load_image( texture_image_t * image, int mipmaps ) //, float gamma )
{
int format = 0;
ILboolean rv;
texture_init();
ilGenImages(1, &image->id);
ilBindImage(image->id);
rv = ilLoadImage(image->path);
if (rv == IL_false)
return -1;
if(mipmaps==0)
{
rv = iluBuildMipmaps();
if (rv == IL_false)
return -1;
}
//else
//{
// // TODO - use iluScale to ensure power of two
//}
//rv = iluGammaCorrect( gamma );
//if (rv == IL_false)
// return -1;
image->w = ilGetInteger(IL_IMAGE_WIDTH);
image->h = ilGetInteger(IL_IMAGE_HEIGHT);
format = ilGetInteger(IL_IMAGE_FORMAT);
// by projectx convention
// textures that we want to color key are rbga
if(format == IL_RGBA)
image->colorkey = 1; // true
else
image->colorkey = 0; // false
image->size = image->w * image->h * IMAGE_COMPONENTS * sizeof(unsigned char);
image->data = (ILubyte *)malloc(image->size);
ilCopyPixels(0, 0, 0, image->w, image->h, 1, IL_RGBA, IL_UNSIGNED_BYTE, image->data);
return 0;
}
#endif