From d31a57c0afc8769cef8af82321c07cbc14c0474b Mon Sep 17 00:00:00 2001
From: sanine <sanine.not@pm.me>
Date: Fri, 24 Mar 2023 16:08:18 -0500
Subject: fix issue with nanovg breaking rendering

---
 main.lua | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

(limited to 'main.lua')

diff --git a/main.lua b/main.lua
index 2c92223..9f39825 100644
--- a/main.lua
+++ b/main.lua
@@ -59,14 +59,13 @@ level:addSystem{
 					surface = {
 						mode = ode.ContactBounce + ode.ContactSoftCFM,
 						mu = ode.Infinity,
-						bounce = 0.99,
+						bounce = 0.90,
 						bounce_vel = 0.1,
 						soft_cfm = 0.001,
 					},
 				}
 				local collisions = ode.Collide(o1, o2, 1)
 				if #collisions > 0 then
-					print("collision detected!")
 					ode.ContactSetGeom(contact, collisions[1])
 					local joint = ode.JointCreateContact(self.world, self.contactgroup, contact)
 					ode.JointAttach(joint, b1, b2)
@@ -83,7 +82,7 @@ level:addSystem{
 		end
 
 		local x, y, z = ode.BodyGetPosition(entity.physicsBody)
-		local a, b, c, d = ode.BodyGetQuaternion(entity.physicsBody)
+		local d, a, b, c = ode.BodyGetQuaternion(entity.physicsBody)
 		entity.transform:identity():translate(Vec3{x, y, z}):mul(Quaternion{a, b, c, d}:toMat4())
 	end,
 }
@@ -150,7 +149,7 @@ local ball = {
 	parent=false,
 	mesh=icosa,
 	shader=shader,
-	collisionShape=ode.CreateSphere(space, 0.5),
+	collisionShape=ode.CreateSphere(space, 1.0),
 	physicsBody=ode.BodyCreate(world),
 }
 level:addEntity(ball)
@@ -195,12 +194,21 @@ local fpsAverage = averager(200)
 -- main loop
 honey.loop(window, function(dt)
 	gl.ClearColor(0.2, 0.4, 1.0, 1.0)
-	gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT)
+	gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT + gl.STENCIL_BUFFER_BIT)
+
+	gl.UseProgram(0)
+	gl.Enable(gl.DEPTH_TEST)
+
 	level:update(dt)
 	nvg.BeginFrame(vg, vw, vh, 1.0)
 	nvg.StrokeColor(vg, nvg.RGBf(1, 1, 1))
 	nvg.FontFace(vg, "November")
 	nvg.Text(vg, 50, 50, "fps: "..tostring(math.floor(fpsAverage(1/dt))))
+	nvg.BeginPath(vg)
+	nvg.MoveTo(vg, 50, 50)
+	nvg.LineTo(vg, 50, 100)
+	nvg.LineTo(vg, 100, 50)
+	nvg.Stroke(vg)
 	nvg.EndFrame(vg)
 end)
 
-- 
cgit v1.2.1