Bläddra i källkod

Add Canvas example;

bjorn 7 år sedan
förälder
incheckning
ab5e0c609c
2 ändrade filer med 5 tillägg och 8 borttagningar
  1. 4 8
      examples/Canvas/main.lua
  2. 1 0
      examples/init.lua

+ 4 - 8
examples/Canvas/main.lua

@@ -63,6 +63,7 @@ function lovr.load()
   local texture = lovr.graphics.newTexture('eye-chart-test-vintage-cc0.jpg')
   local textureWidth, textureHeight = texture:getDimensions()
   eyechart = {
+    scale = .75,
     aspect = textureHeight / textureWidth,
     material = lovr.graphics.newMaterial( texture )
   }
@@ -83,8 +84,8 @@ function lovr.load()
       lovr.graphics.newCanvas(width, height)
     }
 
-    tempCanvas[1]:setWrap('clamp')
-    tempCanvas[2]:setWrap('clamp')
+    tempCanvas[1]:getTexture():setWrap('clamp')
+    tempCanvas[2]:getTexture():setWrap('clamp')
   end
 end
 
@@ -101,12 +102,7 @@ local function sceneDraw()
     lovr.graphics.pop()
   end
 
-  -- Because the eyechart image is non-square, we must stretch its plane
-  lovr.graphics.push()
-  lovr.graphics.scale(1, eyechart.aspect, 1)
-  lovr.graphics.translate(0, 0.5, -0.75)
-  lovr.graphics.plane(eyechart.material, 0, 0, 0)
-  lovr.graphics.pop()
+  lovr.graphics.plane(eyechart.material, 0, 1.7, -1, eyechart.scale, eyechart.scale * eyechart.aspect)
 end
 
 -- This simple callback is used to draw one canvas onto another

+ 1 - 0
examples/init.lua

@@ -7,6 +7,7 @@ return {
   'Physics',
   'PBR_Materials',
   'Cubemap',
+  'Canvas',
   'Instancing',
   'Primitives',
   'Microphone'