示例#1
0
文件: effects.go 项目: pikkpoiss/ld33
func (r *EffectsRenderer) Bind() error {
	gl.BindFramebuffer(gl.FRAMEBUFFER, r.framebuffer)
	gl.Enable(gl.STENCIL_TEST)
	gl.Viewport(0, 0, int32(r.width), int32(r.height))
	gl.ClearStencil(0)
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.StencilMask(0xFF) // Write to buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
	gl.StencilMask(0x00) // Don't write to buffer
	return nil
}
示例#2
0
文件: effects.go 项目: pikkpoiss/ld33
func (r *EffectsRenderer) EnableOutput() {
	gl.ColorMask(true, true, true, true)
	gl.StencilMask(0x00)              // No more writing
	gl.StencilFunc(gl.EQUAL, 0, 0xFF) // Only pass where stencil is 0
}
示例#3
0
文件: effects.go 项目: pikkpoiss/ld33
func (r *EffectsRenderer) DisableOutput() {
	gl.ColorMask(false, false, false, false)
	gl.StencilFunc(gl.NEVER, 1, 0xFF)                // Never pass
	gl.StencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE) // Replace to ref=1
	gl.StencilMask(0xFF)                             // Write to buffer
}
示例#4
0
文件: setup.go 项目: hialin/hialin
func InitGL() error {
	defer tlog.FuncLog(tlog.Func("InitGL"))

	err := gl.Init()
	if err != nil {
		return err
	}
	gl.GetError() // cleanup gl error state

	version := gl.GoStr(gl.GetString(gl.VERSION))
	tlog.Println("OpenGL version", version)

	gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
	Check()
	gl.ReadBuffer(gl.BACK)
	Check()
	gl.DrawBuffer(gl.BACK)
	Check()

	gl.FrontFace(gl.CW)
	Check()
	gl.CullFace(gl.BACK)
	Check()
	gl.Disable(gl.CULL_FACE)
	Check()

	gl.ClearColor(1, 1, 0.5, 0)
	Check()
	gl.ClearDepth(1.0)
	Check()
	gl.ClearStencil(0)
	Check()

	gl.Disable(gl.STENCIL_TEST)
	Check()
	gl.StencilMask(0xFFFFFFFF)
	Check()
	gl.StencilFunc(gl.EQUAL, 0x00000000, 0x00000001)
	Check()
	gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP)
	Check()

	gl.Disable(gl.DITHER)
	Check()

	gl.Enable(gl.DEPTH_TEST)
	Check()
	gl.DepthFunc(gl.LEQUAL)
	Check()
	gl.DepthMask(true)
	Check()
	gl.DepthRange(0., 1.)
	Check()
	gl.Enable(gl.DEPTH_CLAMP)
	Check()

	gl.Enable(gl.BLEND)
	Check()
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	ForceCheck()
	return nil
}