Beispiel #1
0
func (r *Receiver) Draw(window *glfw.Window) {
	// fmt.Println("render", r.SimulationTime.Elapsed)
	bg := gtk.SoftBlack
	gl.ClearColor(bg[0], bg[1], bg[2], bg[3])
	gl.Enable(gl.DEPTH_TEST)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)

	r.Shaders.UseProgram(PROGRAM_FILL)
	gl.Uniform4fv(r.FillLoc.Color, 1, &gtk.SkyBlue[0])
	gl.Uniform1f(r.FillLoc.Depth, gl.Float(r.Constants.PlayerViewFar))
	r.Shaders.UseProgram(PROGRAM_SCENE)
	gl.Uniform1f(r.SceneLoc.ElapsedSeconds, gl.Float(r.SimulationTime.Elapsed))
	gl.Uniform1f(r.SceneLoc.Glow, 0)
	gl.UniformMatrix4fv(r.SceneLoc.Projection, 1, gl.FALSE, gtk.MatArray(r.Data.Projection))
	gl.UniformMatrix4fv(r.SceneLoc.Cameraview, 1, gl.FALSE, gtk.MatArray(r.Data.Cameraview))
	gl.UniformMatrix4fv(r.SceneLoc.Inception, 1, gl.FALSE, gtk.MatArray(r.Data.Inception))
	mv := glm.Ident4d()
	gl.UniformMatrix4fv(r.SceneLoc.Portalview, 1, gl.FALSE, gtk.MatArray(mv))
	gl.UniformMatrix4fv(r.SceneLoc.Worldview, 1, gl.FALSE, gtk.MatArray(mv))
	// gtk.AttachTexture(r.SceneLoc.Tex0, gl.TEXTURE0, gl.TEXTURE_2D, r.Data.Tex0)
	// gtk.AttachTexture(r.SceneLoc.Tex1, gl.TEXTURE1, gl.TEXTURE_2D, r.Data.Tex1)
	gtk.PanicOnError()

	r.DrawPortalScene(mv, 0, 1)
	r.Invalid = false
}
Beispiel #2
0
func (s *StencilOp) Enable() *StencilOp {
	gl.Enable(gl.STENCIL_TEST)
	s.Draw()
	s.Mask(0)
	s.Keep()
	s.Depth()
	s.DepthMask()
	s.DepthLT()
	return s
}
Beispiel #3
0
func (r *Receiver) Draw(window *glfw.Window) {
	bg := gtk.SoftBlack
	gl.ClearColor(bg[0], bg[1], bg[2], bg[3])
	gl.Enable(gl.DEPTH_TEST)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)

	r.Shaders.UseProgram(ProgramScene)
	gl.UniformMatrix4fv(r.SceneLoc.Projection, 1, gl.FALSE, gtk.MatArray(r.Data.Projection))
	gl.UniformMatrix4fv(r.SceneLoc.Cameraview, 1, gl.FALSE, gtk.MatArray(r.Data.Cameraview))
	gtk.PanicOnError()
	gtk.DrawModel(glm.Ident4d(), r.Data.Scene, r.SceneLoc.Worldview, r.SceneLoc.Position, r.Data.Vao)
	// p := r.Data.Scene.Children[0].Transform.Mul4x1(r.Car.Center)
	// m := glm.Translate3Dd(math.Ceil(p[0]/5)*5,0,math.Ceil(p[2]/5)*5)
	// gtk.DrawModel(m, r.Data.Scene.Children[1], r.SceneLoc.Worldview, r.SceneLoc.Position, r.Data.Vao)
}
Beispiel #4
0
func (s *StencilOp) Depth() *StencilOp {
	gl.Enable(gl.DEPTH_TEST)
	return s
}
Beispiel #5
0
func (r *Receiver) DrawPortalScene(mv glm.Mat4d, stencilLevel int, depth int) {
	s := gtk.Stencil
	if depth == 0 {
		if stencilLevel > 0 {
			gl.Enable(gl.CLIP_DISTANCE0)
		}
		s.Enable().Mask(stencilLevel)
		r.DrawModel(mv, r.Data.Scene, false)
		s.Disable()
		gl.Disable(gl.CLIP_DISTANCE0)
	} else {
		s.Enable().Mask(stencilLevel).NoDraw()
		r.DrawModel(mv, r.Data.Scene, false)
		s.DepthLE().Increment()
		gl.Enable(gl.CULL_FACE)
		r.DrawModel(mv, r.Data.Portal, false)

		if r.Constants.Debug {
			r.DrawModel(mv, r.Data.Portal, true)
		}

		gl.Disable(gl.CULL_FACE)
		s.Draw().Keep()

		if stencilLevel > 0 {
			gl.Enable(gl.CLIP_DISTANCE0)
		}
		r.DrawModel(mv, r.Data.Scene, false)

		if r.Constants.Debug {
			gl.Uniform1f(r.SceneLoc.Glow, 1)
			s.Mask(stencilLevel + 1)
			r.DrawModel(mv, r.Data.Portal, true)
			gl.Uniform1f(r.SceneLoc.Glow, 0)
		}

		gl.Disable(gl.CLIP_DISTANCE0)

		//scene drawn at stencil level
		//portal are at level 1
		r.StepDown(stencilLevel + 1)
		r.Shaders.UseProgram(PROGRAM_SCENE)
		s.Enable().Depth().DepthLE().Mask(stencilLevel)
		//scene is at stencil level

		for i, portal := range r.Portals {
			s.NoDraw().Increment()
			gl.UniformMatrix4fv(r.SceneLoc.Worldview, 1, gl.FALSE, gtk.MatArray(mv))
			gl.Enable(gl.CULL_FACE)
			r.DrawGeometry(r.Data.Portal.Geometry[i], r.SceneLoc.Position, false)
			gl.Disable(gl.CULL_FACE)
			s.Draw().Keep()

			//need to clear the depth buffer on stencil level1
			r.Shaders.UseProgram(PROGRAM_FILL)
			s.NoDraw().DepthAlways().Mask(stencilLevel + 1)
			// color := gtk.DebugPallet.Pick(i)
			// gl.Uniform4fv(r.FillLoc.Color, 1, &color[0])
			r.DrawGeometry(r.Data.Fill, r.FillLoc.Position, false)
			r.Shaders.UseProgram(PROGRAM_SCENE)
			s.Enable().Depth().DepthLE().Mask(stencilLevel)

			gl.UniformMatrix4fv(r.SceneLoc.Portalview, 1, gl.FALSE, gtk.MatArray(portal.Portalview))
			w1 := mv.Mul4(portal.Transform)
			r.DrawPortalScene(w1, stencilLevel+1, depth-1)

			r.StepDown(stencilLevel + 1)
			r.Shaders.UseProgram(PROGRAM_SCENE)
			s.Enable().Depth().DepthLE().Mask(stencilLevel)
		}
		s.Disable()
	}
}