63 // XSetWindowBackground(dpy, win, 0) vs. glClearColor() |
63 // XSetWindowBackground(dpy, win, 0) vs. glClearColor() |
64 |
64 |
65 GLXContext glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); |
65 GLXContext glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); |
66 glXMakeCurrent(dpy, win, glc); |
66 glXMakeCurrent(dpy, win, glc); |
67 |
67 |
|
68 clear(); |
|
69 glXSwapBuffers(dpy, win); |
|
70 |
|
71 |
68 // Load GLSL shaders: |
72 // Load GLSL shaders: |
69 GLuint shaderProgram = loadShaders(); |
73 shaderProgram = loadShaders(); |
70 loadTextures(shaderProgram); |
74 loadTextures(); |
71 loadVertices(); |
75 loadVertices(); |
72 |
76 |
73 auto toggleFullscreen = [&]() { |
77 auto toggleFullscreen = [&]() { |
74 full = setFullscreen(dpy, win, !full); |
78 full = setFullscreen(dpy, win, !full); |
75 }; |
79 }; |
93 } catch (const EPoll::Exception& e) { |
97 } catch (const EPoll::Exception& e) { |
94 logOutput << "Will not monitor events on STDIN: " << e.what() << "\n"; |
98 logOutput << "Will not monitor events on STDIN: " << e.what() << "\n"; |
95 } |
99 } |
96 |
100 |
97 // rended the 3D scene even before the first event: |
101 // rended the 3D scene even before the first event: |
98 runShaders(shaderProgram); |
102 runShaders(); |
99 glXSwapBuffers(dpy, win); |
103 glXSwapBuffers(dpy, win); |
100 |
104 |
101 for (XEvent xev; keepRunningX11;) { |
105 for (XEvent xev; keepRunningX11;) { |
102 int epollEventCount = epoll.wait(); |
106 int epollEventCount = epoll.wait(); |
103 //std::cout << "trace: epoll.wait() = " << epollEventCount << std::endl; |
107 //std::cout << "trace: epoll.wait() = " << epollEventCount << std::endl; |
178 } else { |
182 } else { |
179 std::cout << "XEvent: type=" << xev.type << std::endl; |
183 std::cout << "XEvent: type=" << xev.type << std::endl; |
180 } |
184 } |
181 |
185 |
182 if (redraw) { |
186 if (redraw) { |
183 runShaders(shaderProgram); |
187 runShaders(); |
184 glXSwapBuffers(dpy, win); |
188 glXSwapBuffers(dpy, win); |
185 } |
189 } |
186 } else if (epoll[epollEvent].data.fd == STDIN_FILENO) { |
190 } else if (epoll[epollEvent].data.fd == STDIN_FILENO) { |
187 int epollFD = epoll[epollEvent].data.fd; |
191 int epollFD = epoll[epollEvent].data.fd; |
188 logOutput << "other event: fd=" << epollFD << " data="; |
192 logOutput << "other event: fd=" << epollFD << " data="; |
213 glXDestroyContext(dpy, glc); |
217 glXDestroyContext(dpy, glc); |
214 XDestroyWindow(dpy, win); |
218 XDestroyWindow(dpy, win); |
215 XCloseDisplay(dpy); |
219 XCloseDisplay(dpy); |
216 } |
220 } |
217 |
221 |
218 void Shark::runShaders(GLuint program) { |
222 void Shark::clear() { |
219 std::cerr << "GLSL: runShaders(" << program << ")" << std::endl; |
|
220 std::cerr << "background color: " << cfg.backgroundColor << std::endl; |
|
221 glUseProgram(program); |
|
222 checkError(&std::cerr); |
|
223 |
|
224 glClearColor( |
223 glClearColor( |
225 (cfg.backgroundColor >> 16 & 0xFF) / 256., |
224 (cfg.backgroundColor >> 16 & 0xFF) / 256., |
226 (cfg.backgroundColor >> 8 & 0xFF) / 256., |
225 (cfg.backgroundColor >> 8 & 0xFF) / 256., |
227 (cfg.backgroundColor & 0xFF) / 256., |
226 (cfg.backgroundColor & 0xFF) / 256., |
228 1.0); |
227 1.0); |
229 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
228 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
229 } |
|
230 |
|
231 void Shark::runShaders() { |
|
232 glUseProgram(shaderProgram); |
|
233 checkError(&std::cerr); |
|
234 |
|
235 clear(); |
230 |
236 |
231 GLint viewport[4]; |
237 GLint viewport[4]; |
232 glGetIntegerv(GL_VIEWPORT, viewport); |
238 glGetIntegerv(GL_VIEWPORT, viewport); |
233 GLfloat width = viewport[2]; |
239 GLfloat width = viewport[2]; |
234 GLfloat height = viewport[3]; |
240 GLfloat height = viewport[3]; |
340 << tex.width << ", " << tex.height << ") = " << tex.id << std::endl; |
346 << tex.width << ", " << tex.height << ") = " << tex.id << std::endl; |
341 checkError(&std::cerr); |
347 checkError(&std::cerr); |
342 return tex; |
348 return tex; |
343 } |
349 } |
344 |
350 |
345 void Shark::loadTextures(GLuint shaderProgram) { |
351 void Shark::loadTextures() { |
346 for (const Configuration::Texture& tex : cfg.textures) { |
352 for (const Configuration::Texture& tex : cfg.textures) { |
347 textures.push_back(loadTexture(tex.fileName)); |
353 textures.push_back(loadTexture(tex.fileName)); |
348 // TODO: review texture loading and binding |
354 // TODO: review texture loading and binding |
349 // works even without this - default texture |
355 // works even without this - default texture |
350 // glUniform1i(ProgAttr.jazz, jazz); |
356 // glUniform1i(ProgAttr.jazz, jazz); |