From a0cd10aea3e86e3bec81d477e11f9d2f766cee96 Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 21 Nov 2019 00:25:18 +0700 Subject: [PATCH] (#55) Customizable flashlight radius --- src/boomer.nim | 16 ++++++++++++---- src/frag.glsl | 5 ++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/boomer.nim b/src/boomer.nim index b18e74f..c490822 100644 --- a/src/boomer.nim +++ b/src/boomer.nim @@ -78,7 +78,7 @@ proc newShaderProgram(vertex, fragment: Shader): GLuint = glUseProgram(result) proc draw(screenshot: Image, camera: var Camera, shader, vao, texture: GLuint, - windowSize: Vec2f, mouse: Mouse, flShadow: float32) = + windowSize: Vec2f, mouse: Mouse, flShadow: float32, flRadius: float32) = glClearColor(0.1, 0.1, 0.1, 1.0) glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) @@ -96,6 +96,7 @@ proc draw(screenshot: Image, camera: var Camera, shader, vao, texture: GLuint, mouse.curr.x.float32, mouse.curr.y.float32) glUniform1f(glGetUniformLocation(shader, "flShadow".cstring), flShadow) + glUniform1f(glGetUniformLocation(shader, "flRadius".cstring), flRadius) glBindVertexArray(vao) glDrawElements(GL_TRIANGLES, count = 6, GL_UNSIGNED_INT, indices = nil) @@ -271,6 +272,7 @@ proc main() = mouse: Mouse flashlight = false f = 0.0 + flRadius = 200.0 while not quitting: var wa: TXWindowAttributes @@ -336,10 +338,16 @@ proc main() = mouse.drag = true of Button4: - camera.deltaScale += config.scrollSpeed + if (xev.xkey.state and ControlMask) > 0.uint32 and flashlight: + flRadius += 10.0 + else: + camera.deltaScale += config.scrollSpeed of Button5: - camera.deltaScale -= config.scrollSpeed + if (xev.xkey.state and ControlMask) > 0.uint32 and flashlight: + flRadius = max(flRadius - 10.0, 0.0) + else: + camera.deltaScale -= config.scrollSpeed else: discard @@ -363,7 +371,7 @@ proc main() = screenshot.draw(camera, shaderProgram, vao, texture, vec2(wa.width.float32, wa.height.float32), - mouse, f) + mouse, f, flRadius) glXSwapBuffers(display, win) diff --git a/src/frag.glsl b/src/frag.glsl index 2ad4524..68c6e5a 100644 --- a/src/frag.glsl +++ b/src/frag.glsl @@ -5,13 +5,12 @@ uniform sampler2D tex; uniform vec2 cursorPos; uniform vec2 windowSize; uniform float flShadow; - -const float FLASHLIGHT_RADIUS = 200.0; +uniform float flRadius; void main() { vec4 cursor = vec4(cursorPos.x, windowSize.y - cursorPos.y, 0.0, 1.0); color = mix( texture(tex, texcoord), vec4(0.0, 0.0, 0.0, 0.0), - length(cursor - gl_FragCoord) < FLASHLIGHT_RADIUS ? 0.0 : flShadow); + length(cursor - gl_FragCoord) < flRadius ? 0.0 : flShadow); }