コード例 #1
0
ファイル: main.go プロジェクト: GlenKelley/portal
func (r *Receiver) DrawModel(mv glm.Mat4d, model *gtk.Model, lines bool) {
	mv2 := mv.Mul4(model.Transform)
	gl.UniformMatrix4fv(r.SceneLoc.Worldview, 1, gl.FALSE, gtk.MatArray(mv2))
	for _, geo := range model.Geometry {
		r.DrawGeometry(geo, r.SceneLoc.Position, lines)
	}
	for _, child := range model.Children {
		r.DrawModel(mv2, child, lines)
	}
}
コード例 #2
0
ファイル: pipeline.go プロジェクト: GlenKelley/go-glutil
func DrawModel(mv glm.Mat4d, model *Model, modelview gl.UniformLocation, vertexAttribute gl.AttributeLocation, vao gl.VertexArrayObject) {
	mv2 := mv.Mul4(model.Transform)
	gl.UniformMatrix4fv(modelview, 1, gl.FALSE, MatArray(mv2))
	for _, geo := range model.Geometry {
		DrawGeometry(geo, vertexAttribute, vao)
	}
	for _, child := range model.Children {
		DrawModel(mv2, child, modelview, vertexAttribute, vao)
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: GlenKelley/portal
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()
	}
}