197e13de
Pavel Govyadinov
Added new class g...
|
1
2
3
4
|
#ifndef STIM_GL_TEXTURE_H
#define STIM_GL_TEXTURE_H
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
5
6
7
8
9
10
11
12
13
14
15
|
/*
includes not necessary (yet)
#include <iterator>
#include <algorithm>
*/
|
197e13de
Pavel Govyadinov
Added new class g...
|
16
17
|
#include <math.h>
#include <iostream>
|
197e13de
Pavel Govyadinov
Added new class g...
|
18
|
#include <vector>
|
197e13de
Pavel Govyadinov
Added new class g...
|
19
|
#include "../grids/image_stack.h"
|
846040be
Pavel Govyadinov
working version
|
20
21
|
#include <GL/glut.h>
//#include <GL/glext.h>
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
22
|
#include "./error.h"
|
197e13de
Pavel Govyadinov
Added new class g...
|
23
24
|
namespace stim{
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
25
26
27
28
29
|
/*
class gl_texture
Uses image_stack class in order to create a texture object.
*/
|
197e13de
Pavel Govyadinov
Added new class g...
|
30
|
template<typename T>
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
31
|
class gl_texture : public virtual image_stack<T>
|
197e13de
Pavel Govyadinov
Added new class g...
|
32
33
|
{
protected:
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
34
|
std::string path;
|
197e13de
Pavel Govyadinov
Added new class g...
|
35
|
GLuint texID;
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
36
37
38
|
using image_stack<T>::R;
using image_stack<T>::ptr;
using image_stack<T>::samples;
|
197e13de
Pavel Govyadinov
Added new class g...
|
39
40
41
|
public:
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
42
43
44
45
46
47
48
49
|
/*
Method: Basic Constructor
Inputs:
Outputs:
Creates an instance of the gl_texture object.
*/
gl_texture(){
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
50
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
51
52
53
54
55
56
57
58
|
/*
Method: Path Constructor
Inputs: string file_path
Outputs:
Creates an instance of the gl_texture object with a path to the data.
*/
gl_texture(std::string file_path)
{
|
197e13de
Pavel Govyadinov
Added new class g...
|
59
60
|
path = file_path;
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
61
62
63
64
65
66
67
68
69
|
/*
Method: setPath
Inputs:string file_Path
Outputs:
sets the protected path variable of an instance of the gl_texture class
to the method input.
*/
|
197e13de
Pavel Govyadinov
Added new class g...
|
70
71
72
73
74
75
|
void
setPath(std::string file_path)
{
path = file_path;
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
76
77
78
79
80
81
82
|
/*
Method: getPath
Inputs:
Outputs: string path
Returns the path associated with an instance of the gl_texture class.
*/
|
197e13de
Pavel Govyadinov
Added new class g...
|
83
84
85
86
87
|
std::string
getPath()
{
return path;
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
88
89
90
91
92
93
94
95
96
|
/*
Method: getTexture
Inputs:
Outputs: GLuint texID
Returns the id of the texture create by/associated with the
instance of the gl_texture class.
*/
|
197e13de
Pavel Govyadinov
Added new class g...
|
97
|
GLuint
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
98
|
getTexture()
|
197e13de
Pavel Govyadinov
Added new class g...
|
99
|
{
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
100
|
return texID;
|
197e13de
Pavel Govyadinov
Added new class g...
|
101
102
|
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
103
104
105
106
107
108
109
110
|
/*
Method: createTexture
Inputs:
Outputs:
Creates a texture and from the data located at <path> and
assigns that texture to texID
*/
//TO DO :::: Add handling for 2D and 1D textures
|
197e13de
Pavel Govyadinov
Added new class g...
|
111
112
113
|
void
createTexture()
{
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
114
115
116
|
image_stack<T>::load_images(path.append("/*.jpg"));
|
63fcb5c8
Pavel Govyadinov
added some tempor...
|
117
|
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
197e13de
Pavel Govyadinov
Added new class g...
|
118
|
glGenTextures(1, &texID);
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
119
|
CHECK_OPENGL_ERROR
|
197e13de
Pavel Govyadinov
Added new class g...
|
120
|
glBindTexture(GL_TEXTURE_3D, texID);
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
121
|
CHECK_OPENGL_ERROR
|
197e13de
Pavel Govyadinov
Added new class g...
|
122
123
124
125
126
127
128
|
glTexParameteri(GL_TEXTURE_3D,
GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D,
GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D,
GL_TEXTURE_WRAP_S, GL_REPEAT);
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
129
|
CHECK_OPENGL_ERROR
|
197e13de
Pavel Govyadinov
Added new class g...
|
130
131
132
133
134
135
|
glTexParameteri(GL_TEXTURE_3D,
GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D,
GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D,
GL_TEXTURE_WRAP_R, GL_REPEAT);
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
136
|
CHECK_OPENGL_ERROR
|
197e13de
Pavel Govyadinov
Added new class g...
|
137
138
|
glTexImage3D(GL_TEXTURE_3D,
0,
|
63fcb5c8
Pavel Govyadinov
added some tempor...
|
139
|
// GL_RGB16,
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
140
|
1,
|
197e13de
Pavel Govyadinov
Added new class g...
|
141
142
143
144
|
R[1],
R[2],
R[3],
0,
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
145
|
GL_LUMINANCE,
|
63fcb5c8
Pavel Govyadinov
added some tempor...
|
146
|
// GL_RGB,
|
197e13de
Pavel Govyadinov
Added new class g...
|
147
148
149
|
GL_UNSIGNED_BYTE,
ptr);
//GL_UNSIGNED_BYTE can be TYPES, convert to GL equivalents
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
150
|
CHECK_OPENGL_ERROR
|
63fcb5c8
Pavel Govyadinov
added some tempor...
|
151
|
glPixelStorei(GL_PACK_ALIGNMENT,1);
|
197e13de
Pavel Govyadinov
Added new class g...
|
152
153
154
155
156
157
158
|
}
//Binds the texture
void
Bind()
{
glBindTexture(GL_TEXTURE_3D, texID);
}
|
63fcb5c8
Pavel Govyadinov
added some tempor...
|
159
160
161
162
163
164
165
166
167
168
169
170
171
|
stim::vec<unsigned long,4>
getDims()
{
return R;
}
T*
getData()
{
return ptr;
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
172
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
173
|
//TO DO:::add methods for handling the cases of T and convert them to GL equivalent.
|
197e13de
Pavel Govyadinov
Added new class g...
|
174
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
175
|
};
|
197e13de
Pavel Govyadinov
Added new class g...
|
176
177
178
179
180
181
182
183
|
}
#endif
|