summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--html/examples/videocapture.wlua82
1 files changed, 82 insertions, 0 deletions
diff --git a/html/examples/videocapture.wlua b/html/examples/videocapture.wlua
new file mode 100644
index 0000000..f6b065f
--- /dev/null
+++ b/html/examples/videocapture.wlua
@@ -0,0 +1,82 @@
+local im = require "imlua"
+require "imlua_capture"
+local gl = require "luagl"
+local iup = require "iuplua"
+require "iupluagl"
+
+local vc = im.VideoCaptureCreate()
+if (not vc) then
+ error("ERROR: No capture device found!")
+end
+
+if (vc:Connect(0) == 0) then
+ error("ERROR: Fail to connect to capture device")
+end
+
+local capw, caph = vc:GetImageSize()
+local initimgsize = string.format("%ix%i", capw, caph)
+
+
+local frbuf = im.ImageCreate(capw, caph, im.RGB, im.BYTE)
+local gldata, glformat = frbuf:GetOpenGLData()
+
+cnv = iup.glcanvas{buffer="DOUBLE", rastersize = initimgsize}
+
+function cnv:resize_cb(width, height)
+ iup.GLMakeCurrent(self)
+ gl.Viewport(0, 0, width, height)
+end
+
+function cnv:action(x, y)
+ iup.GLMakeCurrent(self)
+ gl.PixelStore(gl.UNPACK_ALIGNMENT, 1)
+
+ gldata, glformat = frbuf:GetOpenGLData() --update the data
+ gl.DrawPixelsRaw (capw, caph, glformat, gl.UNSIGNED_BYTE, gldata)
+
+ iup.GLSwapBuffers(self)
+end
+
+
+vc:Live(1)
+
+local dlg = iup.dialog{title = "Oh Snap!", cnv}
+
+local in_loop = true
+
+function dlg:close_cb()
+ in_loop = false
+end
+
+function dlg:k_any(c)
+ if c == iup.K_q or c == iup.K_ESC then
+ return iup.CLOSE
+ end
+
+ if c == iup.K_F1 then
+ if fullscreen then
+ fullscreen = false
+ dlg.fullscreen = "No"
+ else
+ fullscreen = true
+ dlg.fullscreen = "Yes"
+ end
+ iup.SetFocus(cnv)
+ end
+end
+
+dlg:show()
+iup.SetFocus(cnv)
+
+while in_loop do
+ vc:Frame(frbuf,-1)
+ iup.Update(cnv)
+ local result = iup.LoopStep()
+ if result == iup.CLOSE then
+ in_loop = false
+ end
+end
+
+vc:Live(0)
+vc:Disconnect()
+vc:Destroy()