I've been trying to get input with IUP to make a small pong game. I wanted to try some input, and tried some of the code that comes with the IUPGL examples, but the input doesn't seem to be working at all. Here's the code as it stands so far:
require "iuplua"
require "iupluagl"
require "luagl"
paddle = {x = -0.9, y = 0.2}
function drawPaddle(x, y)
gl.Begin(gl.QUADS)
gl.Color(0.0, 0.5, 0.0)
gl.Vertex(x, y)
gl.Vertex(x + 0.1, y)
gl.Vertex(x + 0.1, y - 0.4)
gl.Vertex(x, y - 0.4)
end
canvas = iup.glcanvas{buffer = "DOUBLE", rastersize = "300x300"}
function canvas:action(x, y)
iup.GLMakeCurrent(self)
gl.ClearColor(0.0, 0.0, 0.0, 0.0)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Clear(gl.DEPTH_BUFFER_BIT)
gl.MatrixMode(gl.PROJECTION)
gl.Viewport(0, 0, 300, 300)
gl.LoadIdentity()
drawPaddle(paddle.x, paddle.y)
gl.End()
iup.GLSwapBuffers(self)
end
window = iup.dialog{canvas, title = "Soon to be Pong"}
function canvas:k_any(c)
if c == iup.K_q then
return iup.CLOSE
elseif c == iup.K_w then
paddle.y = paddle.y + 0.02
return iup.CONTINUE
else
return iup.DEFAULT
end
end
window:show()
iup.MainLoop()
It's my understanding that canvas:k_any()
gets called when a key is pressed, but it's not responding, even to the quit command. Any ideas?