2
0
Эх сурвалжийг харах

Add Pancake example section; Add 2D_Button example;

bjorn 2 жил өмнө
parent
commit
2d42413a44

+ 34 - 0
examples/Pancake/2D_Button/main.lua

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

+ 0 - 0
examples/Debugging/FPS_Controls/conf.lua → examples/Pancake/FPS_Controls/conf.lua


+ 0 - 0
examples/Debugging/FPS_Controls/lovr-mouse.lua → examples/Pancake/FPS_Controls/lovr-mouse.lua


+ 0 - 0
examples/Debugging/FPS_Controls/main.lua → examples/Pancake/FPS_Controls/main.lua


+ 0 - 0
examples/UI/Spectator_Camera/main.lua → examples/Pancake/Spectator_Camera/main.lua


+ 0 - 0
examples/UI/Window_HUD/main.lua → examples/Pancake/Window_HUD/main.lua


+ 0 - 0
examples/UI/Window_HUD/mouse.lua → examples/Pancake/Window_HUD/mouse.lua


+ 0 - 0
examples/UI/Window_HUD/shader.lua → examples/Pancake/Window_HUD/shader.lua


+ 4 - 3
examples/init.lua

@@ -47,10 +47,11 @@ return {
   'Effects/Cubemap_Generate',
   'Effects/Cubemap_Texturing',
   'Effects/Stencil',
-  'UI/Spectator_Camera',
-  'UI/Window_HUD',
+  'Pancake/2D_Button',
+  'Pancake/FPS_Controls',
+  'Pancake/Spectator_Camera',
+  'Pancake/Window_HUD',
   'Optimization/Instancing',
-  'Debugging/FPS_Controls',
   'Debugging/Raw_Input',
   'Debugging/Tally'
 }