main.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. function lovr.load()
  2. lovr.graphics.setBackgroundColor(1, 1, 1)
  3. mask = lovr.headset.getDisplayMask()
  4. -- Print the mesh, for debugging
  5. if mask then
  6. print('mask = {')
  7. for i = 1, #mask do
  8. print(string.format('\t{ %f, %f }', mask[i][1], mask[i][2]))
  9. end
  10. print('}')
  11. else
  12. print('No mask found')
  13. end
  14. shader = lovr.graphics.newShader([[
  15. vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
  16. // Rescale mesh coordinates from (0,1) to (-1,1)
  17. vertex.xy *= 2.;
  18. vertex.xy -= 1.;
  19. // Flip the mesh if it's being drawn in the right eye
  20. if (lovrViewID == 1) {
  21. vertex.x = -vertex.x;
  22. }
  23. return vertex;
  24. }
  25. ]], [[
  26. // The fragment shader returns solid black for illustration purposes. It could be transparent.
  27. vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
  28. return vec4(0., 0., 0., 1.);
  29. }
  30. ]])
  31. if mask then
  32. mesh = lovr.graphics.newMesh({ { 'lovrPosition', 'float', 2 } }, mask, 'triangles')
  33. end
  34. end
  35. function lovr.draw()
  36. if mask then
  37. -- Mask out parts of the display that aren't visible to skip rendering those pixels later
  38. lovr.graphics.setShader(shader)
  39. mesh:draw()
  40. lovr.graphics.setShader()
  41. -- Draw a red cube
  42. lovr.graphics.setColor(0xff0000)
  43. lovr.graphics.cube('fill', 0, 1.7, -1, .5, lovr.timer.getTime())
  44. lovr.graphics.setColor(0xffffff)
  45. else
  46. lovr.graphics.setColor(0x000000)
  47. lovr.graphics.print('No mask found.', 0, 1.7, -3, .2)
  48. lovr.graphics.setColor(0xffffff)
  49. end
  50. end