mirror of
https://github.com/tsoding/boomer
synced 2024-11-16 12:12:47 +00:00
(#55) Make the flashlight effect togglable
This commit is contained in:
parent
467c23b771
commit
68b0f54414
@ -78,7 +78,7 @@ proc newShaderProgram(vertex, fragment: Shader): GLuint =
|
|||||||
glUseProgram(result)
|
glUseProgram(result)
|
||||||
|
|
||||||
proc draw(screenshot: Image, camera: var Camera, shader, vao, texture: GLuint,
|
proc draw(screenshot: Image, camera: var Camera, shader, vao, texture: GLuint,
|
||||||
windowSize: Vec2f, mouse: Mouse) =
|
windowSize: Vec2f, mouse: Mouse, flShadow: float32) =
|
||||||
glClearColor(0.1, 0.1, 0.1, 1.0)
|
glClearColor(0.1, 0.1, 0.1, 1.0)
|
||||||
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
|
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
|
||||||
|
|
||||||
@ -95,6 +95,7 @@ proc draw(screenshot: Image, camera: var Camera, shader, vao, texture: GLuint,
|
|||||||
glUniform2f(glGetUniformLocation(shader, "cursorPos".cstring),
|
glUniform2f(glGetUniformLocation(shader, "cursorPos".cstring),
|
||||||
mouse.curr.x.float32,
|
mouse.curr.x.float32,
|
||||||
mouse.curr.y.float32)
|
mouse.curr.y.float32)
|
||||||
|
glUniform1f(glGetUniformLocation(shader, "flShadow".cstring), flShadow)
|
||||||
|
|
||||||
glBindVertexArray(vao)
|
glBindVertexArray(vao)
|
||||||
glDrawElements(GL_TRIANGLES, count = 6, GL_UNSIGNED_INT, indices = nil)
|
glDrawElements(GL_TRIANGLES, count = 6, GL_UNSIGNED_INT, indices = nil)
|
||||||
@ -268,6 +269,7 @@ proc main() =
|
|||||||
quitting = false
|
quitting = false
|
||||||
camera = Camera(scale: 1.0)
|
camera = Camera(scale: 1.0)
|
||||||
mouse: Mouse
|
mouse: Mouse
|
||||||
|
flashlight = false
|
||||||
|
|
||||||
while not quitting:
|
while not quitting:
|
||||||
var wa: TXWindowAttributes
|
var wa: TXWindowAttributes
|
||||||
@ -320,6 +322,9 @@ proc main() =
|
|||||||
shaderProgram = newShaderProgram(vertexShader, fragmentShader)
|
shaderProgram = newShaderProgram(vertexShader, fragmentShader)
|
||||||
echo "Shader program ID: ", shaderProgram
|
echo "Shader program ID: ", shaderProgram
|
||||||
echo "------------------------------"
|
echo "------------------------------"
|
||||||
|
|
||||||
|
of XK_f:
|
||||||
|
flashlight = not flashlight
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
@ -351,7 +356,7 @@ proc main() =
|
|||||||
|
|
||||||
screenshot.draw(camera, shaderProgram, vao, texture,
|
screenshot.draw(camera, shaderProgram, vao, texture,
|
||||||
vec2(wa.width.float32, wa.height.float32),
|
vec2(wa.width.float32, wa.height.float32),
|
||||||
mouse)
|
mouse, if flashlight: 0.8 else: 0.0)
|
||||||
|
|
||||||
glXSwapBuffers(display, win)
|
glXSwapBuffers(display, win)
|
||||||
|
|
||||||
|
@ -4,16 +4,16 @@ in mediump vec2 texcoord;
|
|||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
uniform vec2 cursorPos;
|
uniform vec2 cursorPos;
|
||||||
uniform vec2 windowSize;
|
uniform vec2 windowSize;
|
||||||
|
uniform float flShadow;
|
||||||
|
|
||||||
const float FLASHLIGHT_RADIUS = 200.0;
|
const float FLASHLIGHT_RADIUS = 200.0;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 cursor = vec4(cursorPos.x, windowSize.y - cursorPos.y, 0.0, 1.0);
|
vec4 cursor = vec4(cursorPos.x, windowSize.y - cursorPos.y, 0.0, 1.0);
|
||||||
float f = 0.8;
|
|
||||||
if (length(cursor - gl_FragCoord) < FLASHLIGHT_RADIUS) {
|
if (length(cursor - gl_FragCoord) < FLASHLIGHT_RADIUS) {
|
||||||
color = texture(tex, texcoord);
|
color = texture(tex, texcoord);
|
||||||
} else {
|
} else {
|
||||||
color = texture(tex, texcoord) - vec4(f, f, f, 0.0);
|
color = texture(tex, texcoord) - vec4(flShadow, flShadow, flShadow, 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user