1
+ #include < assert.h>
2
+ #include " ilcontainer.h"
3
+
4
+ bool ILContainer::Initialize (const char * file_name)
5
+ {
6
+ // We are asserting that we have not initialized this object before.
7
+ assert (this ->il_handle == BAD_IL_VALUE);
8
+
9
+ if ((this ->il_handle = ilGenImage ()) == BAD_IL_VALUE)
10
+ return false ;
11
+ ilBindImage (this ->il_handle );
12
+ if (!ilLoadImage (file_name))
13
+ return false ;
14
+
15
+ glGenTextures (1 , &this ->il_texture_handle );
16
+ glBindTexture (GL_TEXTURE_2D, this ->il_texture_handle );
17
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
18
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
19
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
20
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
21
+ glTexImage2D (GL_TEXTURE_2D, 0 , ilGetInteger (IL_IMAGE_BPP), this ->width = ilGetInteger (IL_IMAGE_WIDTH), this ->height = ilGetInteger (IL_IMAGE_HEIGHT), 0 , this ->format = ilGetInteger (IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, this ->data = ilGetData ());
22
+ return true ;
23
+ }
24
+
25
+ /* To use with a shader, the sampler uniform must be fed the
26
+ same paramter value as you call this function with.
27
+ */
28
+
29
+ void ILContainer::Bind (GLuint texture_unit)
30
+ {
31
+ // We are asserting that we have initialized this object before.
32
+ assert (this ->il_handle != BAD_IL_VALUE);
33
+
34
+ glActiveTexture (GL_TEXTURE0 + texture_unit);
35
+ glBindTexture (GL_TEXTURE_2D, this ->il_texture_handle );
36
+ }
37
+
38
+ /* This class assumes that the object will be dynamically created.
39
+ This assumption is demonstrated in the destructor which calls
40
+ OpenGL. If an object is declared in the global score, the
41
+ destructor will run after the OpenGL context is destroyed,
42
+ which would be an error.
43
+ */
44
+
45
+ ILContainer::~ILContainer ()
46
+ {
47
+ if (this ->il_texture_handle != BAD_GL_VALUE)
48
+ glDeleteTextures (1 , &this ->il_texture_handle );
49
+ if (this ->il_handle != BAD_IL_VALUE)
50
+ ilDeleteImage (this ->il_handle );
51
+
52
+ this ->il_handle = BAD_IL_VALUE;
53
+ this ->il_texture_handle = BAD_GL_VALUE;
54
+ }
55
+
56
+ /* Do not use
57
+
58
+ bool ILCubemapContainer::Initialize(const char * file_name, int width, int height, int offsetx, int offsety)
59
+ {
60
+ assert(this->il_handle == BAD_IL_VALUE);
61
+ if ((this->il_handle = ilGenImage()) == BAD_IL_VALUE)
62
+ return false;
63
+ ilBindImage(this->il_handle);
64
+ if (!ilLoadImage(file_name))
65
+ return false;
66
+
67
+ glGenTextures(7, this->il_texture_handle);
68
+ glBindTexture(GL_TEXTURE_2D, this->il_texture_handle[0]);
69
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
70
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
71
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
72
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
73
+ glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), this->width = ilGetInteger(IL_IMAGE_WIDTH), this->height = ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
74
+ return true;
75
+ }
76
+
77
+ void ILCubemapContainer::Bind(GLuint texture_unit)
78
+ {
79
+ glActiveTexture(GL_TEXTURE0 + texture_unit);
80
+ // glBindTexture(GL_TEXTURE_2D, this->il_texture_handle);
81
+ }
82
+
83
+ ILCubemapContainer::~ILCubemapContainer()
84
+ {
85
+ if (this->il_texture_handle[0] != BAD_GL_VALUE)
86
+ glDeleteTextures(7, this->il_texture_handle);
87
+ if (this->il_handle != BAD_IL_VALUE)
88
+ ilDeleteImage(this->il_handle);
89
+
90
+ this->il_handle = BAD_IL_VALUE;
91
+ this->il_texture_handle[0] = BAD_GL_VALUE;
92
+ }
93
+
94
+ */
0 commit comments