(#55) Customizable flashlight radius

pull/56/head
rexim 5 years ago
parent 3648c27f41
commit a0cd10aea3

@ -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)

@ -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);
}

Loading…
Cancel
Save