local demo_dir = gh_utils.get_demo_dir()
local lib_dir = gh_utils.get_lib_dir() 		

dofile(lib_dir .. "lua/libfont/libfont1.lua")   




winW, winH = gh_window.getsize(0)


--[[
local aspect = 1.333
if (winH > 0) then
  aspect = winW / winH
end  
 camera = gh_camera.create_persp(40, aspect, 0.1, 1000.0)
gh_camera.set_viewport(camera, 0, 0, winW, winH)
gh_camera.set_position(camera, 0, 0, 500)
gh_camera.set_lookat(camera, 0, 0, 0, 1)
gh_camera.set_upvec(camera, 0, 1, 0, 0)
--]]


camera_ortho = gh_camera.create_ortho(-winW/2, winW/2, -winH/2, winH/2, 1.0, 10.0)
gh_camera.set_viewport(camera_ortho, 0, 0, winW, winH)
gh_camera.set_position(camera_ortho, 0, 0, 4)





texture_prog = gh_node.getid("texture_prog")
gh_gpu_program.uniform1i(texture_prog, "tex0", 0)









webcam1 = 0
frame_w = 256
frame_h = 256
webcam_name = ""


-- Webcam built-in functions are available on Windows platform only.
--
local platform_windows = 1 
--local platform_osx = 2 
--local platform_linux = 3 
--local platform_rpi = 4 

if (gh_utils.get_platform() == platform_windows) then

  webcam1 = gh_utils.webcam_create()

  -- 320×240
  -- 640×480 -- default resolution on Windows
  -- 1280×720
  -- 1920×1080
  --gh_utils.webcam_start_v2(webcam1, 1, 640, 480) -- GeeXLab 0.39+
  gh_utils.webcam_start_v2(webcam1, 1, 1280, 720) -- GeeXLab 0.39+
  --gh_utils.webcam_start_v2(webcam1, 1, 1920, 1080) -- GeeXLab 0.39+
  --gh_utils.webcam_start(webcam1, 1)

  webcam_name = gh_utils.webcam_get_name(webcam1)

  frame_w, frame_h = gh_utils.webcam_get_frame_size(webcam1)
end





function VideoQuadResize(win_w, win_h, scale)

  local quad_y_offset = 0

  local r = 1.0
  r = frame_w / frame_h
  quad_width = win_w * scale
  quad_height = quad_width / r

  if (quad_height > (win_h * scale)) then
    quad_height = win_h * scale
    quad_width = quad_height * r
  end

  gh_mesh.update_quad_size(mesh_quad, quad_width, quad_height)
  gh_object.set_position(mesh_quad, 0, 0, 0)
end


mesh_quad = gh_mesh.create_quad(winW, winH)
VideoQuadResize(winW, winH, 1.0)











abs_path = 1
PF_U8_RGB = 1
PF_U8_BGR = 2
PF_U8_RGBA = 3
tex01 = gh_texture.create_2d_v2(frame_w, frame_h, PF_U8_BGR, 0)


g_frames = 0
g_images = 0
g_img_src = 1

gh_renderer.set_depth_test_state(1)
gh_renderer.set_vsync(1)

last_time = gh_utils.get_elapsed_time()

