diff -r 3faef2f5128e -r 48dc4ae894b0 Shark.cpp --- a/Shark.cpp Wed Nov 29 01:11:19 2023 +0100 +++ b/Shark.cpp Wed Nov 29 01:21:17 2023 +0100 @@ -65,9 +65,13 @@ GLXContext glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); glXMakeCurrent(dpy, win, glc); + clear(); + glXSwapBuffers(dpy, win); + + // Load GLSL shaders: - GLuint shaderProgram = loadShaders(); - loadTextures(shaderProgram); + shaderProgram = loadShaders(); + loadTextures(); loadVertices(); auto toggleFullscreen = [&]() { @@ -95,7 +99,7 @@ } // rended the 3D scene even before the first event: - runShaders(shaderProgram); + runShaders(); glXSwapBuffers(dpy, win); for (XEvent xev; keepRunningX11;) { @@ -180,7 +184,7 @@ } if (redraw) { - runShaders(shaderProgram); + runShaders(); glXSwapBuffers(dpy, win); } } else if (epoll[epollEvent].data.fd == STDIN_FILENO) { @@ -215,18 +219,20 @@ XCloseDisplay(dpy); } -void Shark::runShaders(GLuint program) { - std::cerr << "GLSL: runShaders(" << program << ")" << std::endl; - std::cerr << "background color: " << cfg.backgroundColor << std::endl; - glUseProgram(program); - checkError(&std::cerr); - +void Shark::clear() { glClearColor( (cfg.backgroundColor >> 16 & 0xFF) / 256., (cfg.backgroundColor >> 8 & 0xFF) / 256., (cfg.backgroundColor & 0xFF) / 256., 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +void Shark::runShaders() { + glUseProgram(shaderProgram); + checkError(&std::cerr); + + clear(); GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); @@ -342,7 +348,7 @@ return tex; } -void Shark::loadTextures(GLuint shaderProgram) { +void Shark::loadTextures() { for (const Configuration::Texture& tex : cfg.textures) { textures.push_back(loadTexture(tex.fileName)); // TODO: review texture loading and binding