func setModelViewOptions() { gl.Enable(gl.TEXTURE_2D) gl.Disable(gl.LIGHTING) gl.Disable(gl.DITHER) gl.Enable(gl.CULL_FACE) gl.CullFace(gl.FRONT) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Enable(gl.BLEND) gl.Enable(gl.ALPHA_TEST) gl.DepthFunc(gl.LEQUAL) gl.Disable(gl.DEPTH_TEST) }
func main() { var winTitle string = "Go-SDL2 + Go-GL" var winWidth, winHeight int = 800, 600 var window *sdl.Window var context sdl.GLContext var event sdl.Event var running bool var err error if err = sdl.Init(sdl.INIT_EVERYTHING); err != nil { panic(err) } defer sdl.Quit() if err = gl.Init(); err != nil { panic(err) } window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, winWidth, winHeight, sdl.WINDOW_OPENGL) if err != nil { panic(err) } defer window.Destroy() context, err = sdl.GL_CreateContext(window) if err != nil { panic(err) } defer sdl.GL_DeleteContext(context) gl.Enable(gl.DEPTH_TEST) gl.ClearColor(0.2, 0.2, 0.3, 1.0) gl.ClearDepth(1) gl.DepthFunc(gl.LEQUAL) gl.Viewport(0, 0, int32(winWidth), int32(winHeight)) running = true for running { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { case *sdl.QuitEvent: running = false case *sdl.MouseMotionEvent: fmt.Printf("[%d ms] MouseMotion\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", t.Timestamp, t.Which, t.X, t.Y, t.XRel, t.YRel) } } drawgl() sdl.GL_SwapWindow(window) } }
func setupScene() { gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.LIGHTING) gl.ClearColor(0.5, 0.5, 0.5, 0.0) gl.ClearDepth(1) gl.DepthFunc(gl.LEQUAL) ambient := []float32{0.5, 0.5, 0.5, 1} diffuse := []float32{1, 1, 1, 1} lightPosition := []float32{-5, 5, 10, 0} gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0]) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0]) gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightPosition[0]) gl.Enable(gl.LIGHT0) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.0, 10.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() }
// DepthFunc sets the function used for depth buffer comparisons. // // Valid fn values: // NEVER // LESS // EQUAL // LEQUAL // GREATER // NOTEQUAL // GEQUAL // ALWAYS // // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthFunc.xhtml func DepthFunc(fn Enum) { gl.DepthFunc(uint32(fn)) }
func (*backend) DepthFunc(f gg.Enum) { gl.DepthFunc(uint32(f)) }