File t.c added (mode: 100644) (index 0000000..5fa1eb7) |
|
1 |
|
#include <OpenImageIO/imageio.h> |
|
2 |
|
#include <OpenImageIO/imagebuf.h> |
|
3 |
|
#include <OpenImageIO/imagebufalgo.h> |
|
4 |
|
|
|
5 |
|
|
|
6 |
|
#include <epoxy/gl.h> |
|
7 |
|
#include <gtk/gtk.h> |
|
8 |
|
#include <glm/glm.hpp> |
|
9 |
|
#include <glm/gtc/matrix_transform.hpp> |
|
10 |
|
#include <glm/gtc/type_ptr.hpp> |
|
11 |
|
OIIO_NAMESPACE_USING |
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
const GLchar *vert_src ="\n" \ |
|
18 |
|
"#version 330 \n" \ |
|
19 |
|
" #extension GL_ARB_explicit_uniform_location : enable \n" \ |
|
20 |
|
" out vec2 kn; \n" \ |
|
21 |
|
" \n" \ |
|
22 |
|
" out vec4 knn; \n" \ |
|
23 |
|
" layout(location = 1) in vec2 in_p; \n" \ |
|
24 |
|
" layout(location = 0) in vec4 in_position; \n" \ |
|
25 |
|
" layout(location =10)uniform mat4 projection; \n" \ |
|
26 |
|
"void main() \n" \ |
|
27 |
|
"{ \n" \ |
|
28 |
|
" gl_Position = projection*in_position; \n" \ |
|
29 |
|
"knn=in_position ; \n" \ |
|
30 |
|
"kn=in_p ; \n" \ |
|
31 |
|
"// gl_Position = in_position; \n" \ |
|
32 |
|
"} \n" ; |
|
33 |
|
const GLchar *frag_src ="\n" \ |
|
34 |
|
"#version 330 \n" \ |
|
35 |
|
" #extension GL_ARB_explicit_uniform_location : enable \n" \ |
|
36 |
|
"layout(location =11)uniform sampler2D t; \n" \ |
|
37 |
|
" vec4 b; \n" \ |
|
38 |
|
" in vec4 knn; \n" \ |
|
39 |
|
" in vec2 kn; \n" \ |
|
40 |
|
"void main (void) \n" \ |
|
41 |
|
"{ \n" \ |
|
42 |
|
"// if(gl_FrontFacing){ \n" \ |
|
43 |
|
|
|
44 |
|
"// b= vec4(gl_FragCoord.x/10.0,gl_FragCoord.y/357.0,gl_FragCoord.z* 0.5,1.0); \n" \ |
|
45 |
|
"// gl_FragColor = vec4(0.021,abs(knn.x-0.3)*0.5+abs(knn.z-0.7)*0.353+abs(0.583*knn.y-0.1)-0.2 ,1.215*knn.z+0.583*knn.y +.0357*knn.x, 1.0); \n" \ |
|
46 |
|
" // } \n" \ |
|
47 |
|
" if(gl_FrontFacing) \n" \ |
|
48 |
|
" gl_FragColor = texture( t, kn); \n" \ |
|
49 |
|
"else discard; \n" \ |
|
50 |
|
"} \n"; |
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
glm::mat4 yt,b; |
|
56 |
|
ImageSpec c; |
|
57 |
|
GLushort trr[1024*1024*4]; |
|
58 |
|
|
|
59 |
|
|
|
60 |
|
GLuint gl_vao, gl_buffer, gl_program; |
|
61 |
|
GLuint vertexT,tpr,tpra; |
|
62 |
|
static gboolean realise(GtkGLArea *area, GdkGLContext *context) |
|
63 |
|
{ |
|
64 |
|
|
|
65 |
|
|
|
66 |
|
gtk_gl_area_make_current(GTK_GL_AREA(area)); |
|
67 |
|
if (gtk_gl_area_get_error (GTK_GL_AREA(area)) != NULL) |
|
68 |
|
{ |
|
69 |
|
printf("failed to initialiize buffers\n"); |
|
70 |
|
return false; |
|
71 |
|
} |
|
72 |
|
|
|
73 |
|
GLfloat t[] = |
|
74 |
|
{ |
|
75 |
|
|
|
76 |
|
0.0,1.0, |
|
77 |
|
0.0,0.0, |
|
78 |
|
1.0,1.0, |
|
79 |
|
|
|
80 |
|
0.0,1.0, |
|
81 |
|
1.0,1.0, |
|
82 |
|
1.0,0.0, |
|
83 |
|
|
|
84 |
|
|
|
85 |
|
0.0,1.0, |
|
86 |
|
0.0,0.0, |
|
87 |
|
1.0,1.0, |
|
88 |
|
|
|
89 |
|
0.0,1.0, |
|
90 |
|
1.0,1.0, |
|
91 |
|
1.0,0.0, |
|
92 |
|
|
|
93 |
|
|
|
94 |
|
0.0,1.0, |
|
95 |
|
0.0,0.0, |
|
96 |
|
1.0,1.0, |
|
97 |
|
|
|
98 |
|
0.0,1.0, |
|
99 |
|
1.0,1.0, |
|
100 |
|
1.0,0.0, |
|
101 |
|
|
|
102 |
|
|
|
103 |
|
0.0,1.0, |
|
104 |
|
0.0,0.0, |
|
105 |
|
1.0,1.0, |
|
106 |
|
|
|
107 |
|
0.0,1.0, |
|
108 |
|
1.0,1.0, |
|
109 |
|
1.0,0.0, |
|
110 |
|
|
|
111 |
|
|
|
112 |
|
0.0,1.0, |
|
113 |
|
0.0,0.0, |
|
114 |
|
1.0,1.0, |
|
115 |
|
|
|
116 |
|
0.0,1.0, |
|
117 |
|
1.0,1.0, |
|
118 |
|
1.0,0.0, |
|
119 |
|
0.0,1.0, |
|
120 |
|
0.0,0.0, |
|
121 |
|
1.0,1.0, |
|
122 |
|
|
|
123 |
|
0.0,1.0, |
|
124 |
|
1.0,1.0, |
|
125 |
|
1.0,0.0 |
|
126 |
|
}; |
|
127 |
|
|
|
128 |
|
|
|
129 |
|
GLfloat verts[] = |
|
130 |
|
{ |
|
131 |
|
+0.7,+0.7,+0.7, |
|
132 |
|
-0.7,0.7, 0.7, |
|
133 |
|
-0.7,+0.7, -0.7, |
|
134 |
|
|
|
135 |
|
0.7,+0.7, -0.7, |
|
136 |
|
+0.7,+0.7,+0.7, |
|
137 |
|
-0.7,+0.7, -0.7, |
|
138 |
|
|
|
139 |
|
-0.7,-0.7, +0.7, |
|
140 |
|
+0.7,+0.7,+0.7, |
|
141 |
|
-0.7,0.7, 0.7, |
|
142 |
|
|
|
143 |
|
+0.7,+0.7,+0.7, |
|
144 |
|
-0.7,-0.7, +0.7, |
|
145 |
|
0.7,-0.7, 0.7, |
|
146 |
|
|
|
147 |
|
+0.7,-0.7,-0.7, |
|
148 |
|
-0.7,-0.7,-0.7, |
|
149 |
|
0.7,+0.7, -0.7, |
|
150 |
|
|
|
151 |
|
-0.7,+0.7, -0.7, |
|
152 |
|
0.7,+0.7, -0.7, |
|
153 |
|
-0.7,-0.7, -0.7, |
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
-0.7,-0.7, +0.7, |
|
158 |
|
-0.7,-0.7, -0.7, |
|
159 |
|
0.7,-0.7, 0.7, |
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
+0.7,-0.7, -0.7, |
|
164 |
|
|
|
165 |
|
0.7,-0.7, 0.7, |
|
166 |
|
|
|
167 |
|
-0.7,-0.7, -0.7, |
|
168 |
|
|
|
169 |
|
0.7,+0.7, -0.7, |
|
170 |
|
+0.7,+0.7,+0.7, |
|
171 |
|
+0.7,-0.7, -0.7, |
|
172 |
|
|
|
173 |
|
0.7,-0.7, -0.7, |
|
174 |
|
+0.7,+0.7,+0.7, |
|
175 |
|
|
|
176 |
|
|
|
177 |
|
0.7,-0.7, 0.7, |
|
178 |
|
|
|
179 |
|
|
|
180 |
|
-0.7,-0.7, -0.7, |
|
181 |
|
-0.7,0.7, 0.7, |
|
182 |
|
-0.7,+0.7, -0.7, |
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
-0.7,-0.7, +0.7, |
|
187 |
|
-0.7,0.7, 0.7, |
|
188 |
|
-0.7,-0.7, -0.7 |
|
189 |
|
|
|
190 |
|
}; |
|
191 |
|
b=glm::lookAt(glm::vec3(1.75,-2.38,1.4444), glm::vec3( 0., 0., 0.),glm::vec3( 0.,0.2,-00.)); |
|
192 |
|
yt=glm::perspective(45., 1., 1.2, 300.); |
|
193 |
|
b=yt*b*glm::mat4(1.); |
|
194 |
|
|
|
195 |
|
//b=glm::lookAt(glm::vec3(0., 0.,-1.),glm::vec3( 0., 0., 0.),glm::vec3( 0.,025.,-1.)); |
|
196 |
|
//yt=yt*b; |
|
197 |
|
|
|
198 |
|
|
|
199 |
|
c.width=1024;; |
|
200 |
|
c.height=1024;; |
|
201 |
|
|
|
202 |
|
c.nchannels=4; |
|
203 |
|
c.x=0; |
|
204 |
|
c.y=0; |
|
205 |
|
c.format=TypeDesc::UINT8; |
|
206 |
|
|
|
207 |
|
ImageBuf k(c,trr); |
|
208 |
|
ImageBuf h("161208ap5410_fpx.jpg"); |
|
209 |
|
h.read(); |
|
210 |
|
k.copy_pixels(h); |
|
211 |
|
h.clear (); |
|
212 |
|
//ImageBufAlgo::noise(k,"gaussian"); |
|
213 |
|
|
|
214 |
|
|
|
215 |
|
GLuint frag_shader, vert_shader; |
|
216 |
|
frag_shader = glCreateShader(GL_FRAGMENT_SHADER); |
|
217 |
|
vert_shader = glCreateShader(GL_VERTEX_SHADER); |
|
218 |
|
|
|
219 |
|
|
|
220 |
|
glShaderSource(frag_shader, 1, &frag_src, NULL); |
|
221 |
|
glShaderSource(vert_shader, 1, &vert_src, NULL); |
|
222 |
|
|
|
223 |
|
glCompileShader(frag_shader); |
|
224 |
|
glCompileShader(vert_shader); |
|
225 |
|
|
|
226 |
|
gl_program = glCreateProgram(); |
|
227 |
|
glAttachShader(gl_program, frag_shader); |
|
228 |
|
glAttachShader(gl_program, vert_shader); |
|
229 |
|
glLinkProgram(gl_program); |
|
230 |
|
|
|
231 |
|
// glUniformMatrix4fv(1, 1, 0, glm::value_ptr(b)); |
|
232 |
|
|
|
233 |
|
glGenVertexArrays(1, &gl_vao); |
|
234 |
|
|
|
235 |
|
glBindVertexArray(gl_vao); |
|
236 |
|
|
|
237 |
|
glGenBuffers(1, &gl_buffer); |
|
238 |
|
glBindBuffer(GL_ARRAY_BUFFER, gl_buffer); |
|
239 |
|
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW); |
|
240 |
|
|
|
241 |
|
glEnableVertexAttribArray(0); |
|
242 |
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); |
|
243 |
|
|
|
244 |
|
|
|
245 |
|
glGenBuffers(1, &tpr); |
|
246 |
|
glBindBuffer(GL_ARRAY_BUFFER,tpr ); |
|
247 |
|
|
|
248 |
|
glBufferData(GL_ARRAY_BUFFER, sizeof(t), t, GL_STATIC_DRAW); |
|
249 |
|
glEnableVertexAttribArray(1); |
|
250 |
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); |
|
251 |
|
|
|
252 |
|
glBindVertexArray(0); |
|
253 |
|
|
|
254 |
|
//glGenTextures(1, &vertexT); |
|
255 |
|
//glBindBuffer(GL_ARRAY_BUFFER, vertexT); |
|
256 |
|
// glActiveTexture(GL_TEXTURE0); |
|
257 |
|
// glBindTexture(GL_TEXTURE_2D, vertexT); |
|
258 |
|
|
|
259 |
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
260 |
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
261 |
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE,trr); |
|
262 |
|
|
|
263 |
|
return TRUE; |
|
264 |
|
} |
|
265 |
|
|
|
266 |
|
static gboolean render(GtkGLArea *area, GdkGLContext *context) |
|
267 |
|
{ |
|
268 |
|
|
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
|
glUseProgram(gl_program); |
|
276 |
|
glUniformMatrix4fv(10, 1, 0, &b[0][0]); |
|
277 |
|
glUniform1i(11, 0); |
|
278 |
|
|
|
279 |
|
glBindVertexArray(gl_vao); |
|
280 |
|
|
|
281 |
|
|
|
282 |
|
glDrawArrays(GL_TRIANGLES,0,36 ); |
|
283 |
|
|
|
284 |
|
glBindVertexArray (0); |
|
285 |
|
glUseProgram (0); |
|
286 |
|
|
|
287 |
|
|
|
288 |
|
glFlush(); |
|
289 |
|
|
|
290 |
|
return TRUE; |
|
291 |
|
} |
|
292 |
|
|
|
293 |
|
int main(int argc, char** argv) |
|
294 |
|
{ |
|
295 |
|
gtk_init(&argc, &argv); |
|
296 |
|
|
|
297 |
|
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL), |
|
298 |
|
*gl_area = gtk_gl_area_new(); |
|
299 |
|
|
|
300 |
|
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL); |
|
301 |
|
g_signal_connect(gl_area, "realize", G_CALLBACK(realise), NULL); |
|
302 |
|
g_signal_connect(gl_area, "render", G_CALLBACK(render), NULL); |
|
303 |
|
|
|
304 |
|
gtk_container_add(GTK_CONTAINER(window), gl_area); |
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
|
gtk_widget_show_all(window); |
|
309 |
|
|
|
310 |
|
gtk_main(); |
|
311 |
|
|
|
312 |
|
return 0; |
|
313 |
|
} |
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|