Skip to content

Instantly share code, notes, and snippets.

View zacharycarter's full-sized avatar
👀
Looking for work!

Tail Wag Games zacharycarter

👀
Looking for work!
View GitHub Profile
let animationFrame = getFrame(idleAnimation, zengine.clock.timeElapsed, 0.2)
# Draw object with solid color into render target
beginDrawing()
begin2dMode(camera)
clearBackground(TRANSPARENT)
beginTextureMode(target)
beginShaderMode(solidColorShader)
drawTexture(textureAtlas.texture, animationFrame.u, animationFrame.v, animationFrame.u2, animationFrame.v2, Rectangle(x: ((20 - 2) * 32) - 32, y: ((20 + 2) * 16) - 64, width: animationFrame.width, height: animationFrame.height), vec2f(0), 0.0, RED)
endShaderMode()
More or less you draw the object to the stencil buffer, then you draw the object with the color glow you want into a separate buffer. You then run a Gaussian blur on the separate buffer. Finally you render the blurred buffer onto the screen, restricted by the stencil buffer.
render the objects to be outlined so that they set a flag in the stencil buffer, fill the stencilled areas with the outline color in the offscreen buffer, do your blurring and add the results to the screen buffer.
1. Render all of your selected units into a render target the size of the screen using a shader just fills the unit with their selection color. This’ll let you do different selection colors for different types of units.
2. Render your scene normally into the back buffer.
3. Render all of your selected units into the stencil buffer without rendering into the color channels.
4. Render your selection image into the stenciled back buffer with a shader that performs a gaussian filter over the image. This’ll get you your blurry sten
# Draw object with solid color into render target
beginDrawing()
begin2dMode(camera)
clearBackground(TRANSPARENT)
let animationFrame = getFrame(idleAnimation, zengine.clock.timeElapsed, 0.2)
beginTextureMode(target)
beginShaderMode(solidColorShader)
drawTexture(textureAtlas.texture, animationFrame.u, animationFrame.v, animationFrame.u2, animationFrame.v2, Rectangle(x: ((20 - 2) * 32) - 32, y: ((20 + 2) * 16) - 64, width: animationFrame.width, height: animationFrame.height), vec2f(0), 0.0, RED)
endShaderMode()
endTextureMode()
beginDrawing()
begin2dMode(camera)
clearBackground(TRANSPARENT)
let animationFrame = getFrame(idleAnimation, zengine.clock.timeElapsed, 0.2)
beginTextureMode(target) # Create render target
beginShaderMode(solidColorShader) # Turn on solid color shader
# Draw texture to render target
drawTexture(textureAtlas.texture, animationFrame.u, animationFrame.v, animationFrame.u2, animationFrame.v2, Rectangle(x: ((20 - 2) * 32) - 32, y: ((20 + 2) * 16) - 64, width: animationFrame.width, height: animationFrame.height), vec2f(0), 0.0, RED)
endShaderMode()
zglEnableStencilTest()
glDepthMask(GL_FALSE)
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE)
var stencilBuffer: array[960 * 540, cuchar]
glStencilFunc(GL_EQUAL, 0, 1)
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
glStencilMask(1)
glClearStencil(1)
glClear(GL_STENCIL_BUFFER_BIT)
import math
const
even = 1
odd = -1
hexDirections = @[(1, 0, -1), (1, -1, 0), (0, -1, 1), (-1, 0, 1), (-1, 1, 0), (0, 1, -1)]
hexDiagonals = @[(2, -1, -1), (1, -2, 1), (-1, -1, 2), (-2, 1, 1), (-1, 2, -1), (1, 1, -2)]
type
Point = tuple[x,y: float]
let doc = """
RTS.
Usage:
rts <hostname> <port>
"""
const
ScreenWidth = 960
ScreenHeight = 540
let doc = """
RTS.
Usage:
rts <hostname> <port>
"""
import asyncdispatch, zengine, sdl2, opengl, random, glm, strutils, docopt, websocket, logging, message, json
let args = docopt(doc, version = "RTS 0.1.0")
let doc = """
RTS.
Usage:
rts <hostname> <port>
"""
import asyncdispatch, zengine, sdl2, opengl, random, glm, strutils, docopt, websocket, logging, message, json
let args = docopt(doc, version = "RTS 0.1.0")
+++++++++++++++++++++++++++ +++++++++++++++++++++++++++