main.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. -- Set the units of the default font to pixels instead of meters
  2. local font = lovr.graphics.getDefaultFont()
  3. font:setPixelDensity(1)
  4. -- Set up a 2D orthographic projection, where (0, 0) is the upper
  5. -- left of the window and the units are in pixels
  6. local width, height = lovr.system.getWindowDimensions()
  7. local projection = Mat4():orthographic(0, width, 0, height, -10, 10)
  8. function lovr.draw(pass)
  9. pass:setViewPose(1, mat4():identity())
  10. pass:setProjection(1, projection)
  11. pass:setDepthTest()
  12. local button = { x = width / 2, y = height / 2, w = 180, h = 60 }
  13. local mx, my = lovr.system.getMousePosition()
  14. local pressed = lovr.system.isMouseDown(1)
  15. local hovered = mx > button.x - button.w / 2 and mx < button.x + button.w / 2 and
  16. my > button.y - button.h / 2 and my < button.y + button.h / 2
  17. if hovered and pressed then
  18. pass:setColor(.25, .25, .27)
  19. elseif hovered then
  20. pass:setColor(.20, .20, .22)
  21. else
  22. pass:setColor(.15, .15, .17)
  23. end
  24. pass:plane(button.x, button.y, 0, button.w, button.h)
  25. pass:setColor(1, 1, 1)
  26. pass:text('Click me!', button.x, button.y, 0)
  27. end