Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Created July 7, 2014 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonDanisch/98aee37ddb76279cf774 to your computer and use it in GitHub Desktop.
Save SimonDanisch/98aee37ddb76279cf774 to your computer and use it in GitHub Desktop.
using ModernGL, GLWindow, GLUtil, React, ImmutableArrays
const window = createwindow("Example", 512, 512)
window_size = window.inputs[:window_size]
w,h = window_size.value # get initial window size
#Resize glviewport, when window size changes.
lift(window_size -> glViewport(0,0, window_size[1], window_size[2]), window_size)
const vsh = """
in vec2 position;
out vec2 uv;
void main() {
uv = (position + vec2(1)) / vec2(2); //texture coordinates are between 0-1
gl_Position = vec4(position, 0.0, 1.0);
}
"""
const fsh = """
in vec2 uv;
uniform sampler2D image;
out vec4 fragment_color;
void main() {
fragment_color = texture(image, uv);
}
"""
imgdata = [Vector4(0f0) for x=1:w, y=1:h]
image = Texture(imgdata)
imgdata = 0
const fullscreenquad = RenderObject(
[
:position => GLBuffer(GLfloat[-1,-1, -1,1, 1,1, 1,1, 1,-1, -1,-1], 2),
:image => image
], GLProgram(vsh, fsh, "vertexshader", "fragmentshader"))
prerender!(fullscreenquad, render, fullscreenquad.vertexarray)
global t = 0
function calculation()
global t
w,h = window_size.value # get current window size
data = [Vector4(float32(x/w), float32(y/h), float32(0.5 * (1 + sin(t * 0.2))), 1f0) for x=1:w, y=1:h]
t += 1
glBindTexture(GL_TEXTURE_2D, image.id)
glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0 , w,h, image.format, image.pixeltype, data)
data = 0
end
while !GLFW.WindowShouldClose(window.glfwWindow)
glClearColor(0.0, 0.0,0.0, 1.0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
calculation()
render(fullscreenquad)
# Swap front and back buffers
GLFW.SwapBuffers(window.glfwWindow)
# Poll for and process events
GLFW.PollEvents()
end
GLFW.Terminate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment