Example #1
0
File: window.go Project: fmd/gogol
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)
}
Example #2
0
// CullFace specifies which polygons are candidates for culling.
//
// Valid modes: FRONT, BACK, FRONT_AND_BACK.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glCullFace.xhtml
func CullFace(mode Enum) {
	gl.CullFace(uint32(mode))
}
Example #3
0
func main() {
	fmt.Printf(`WolfenGo v%s, Copyright (C) 2016 gdm85
https://github.com/gdm85/wolfengo
WolfenGo comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under GNU/GPLv2 license.`+"\n", version)

	if err := glfw.Init(); err != nil {
		fatalError(err)
	}
	defer glfw.Terminate()

	// create a context and activate it
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.DoubleBuffer, glfw.True)
	var err error
	Window, err = glfw.CreateWindow(800, 600, "WolfenGo", nil, nil)
	if err != nil {
		fatalError(err)
	}
	Window.MakeContextCurrent()

	// gl.Init() should be called after context is current
	if err := gl.Init(); err != nil {
		fatalError(err)
	}

	glfw.SwapInterval(1) // enable vertical refresh

	fmt.Println(gl.GoStr(gl.GetString(gl.VERSION)))

	if debugGL {
		gl.DebugMessageCallback(debugCb, unsafe.Pointer(nil))
		gl.Enable(gl.DEBUG_OUTPUT)
	}

	// init graphics
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)

	gl.FrontFace(gl.CW)
	gl.CullFace(gl.BACK)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)

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

	gl.Enable(gl.DEPTH_CLAMP)
	gl.Enable(gl.TEXTURE_2D)

	isRunning := false

	// load all assets
	_, err = getBasicShader()
	if err != nil {
		fatalError(err)
	}
	err = _defaultMedkit.initMedkit()
	if err != nil {
		fatalError(err)
	}
	err = _defaultMonster.initMonster()
	if err != nil {
		fatalError(err)
	}
	getDoorMesh()
	initPlayer()
	err = initGun()
	if err != nil {
		fatalError(err)
	}

	G, err = NewGame()
	if err != nil {
		fatalError(err)
	}

	// GAME STARTS
	isRunning = true

	var frames uint64
	var frameCounter time.Duration

	frameTime := time.Duration(1000/frameCap) * time.Millisecond
	lastTime := time.Now()
	var unprocessedTime time.Duration

	for isRunning {
		var render bool

		startTime := time.Now()
		passedTime := startTime.Sub(lastTime)
		lastTime = startTime

		unprocessedTime += passedTime
		frameCounter += passedTime

		for unprocessedTime > frameTime {
			render = true

			unprocessedTime -= frameTime
			if Window.ShouldClose() {
				isRunning = false
			}
			G.timeDelta = frameTime.Seconds()

			glfw.PollEvents()
			err := G.input()
			if err != nil {
				fatalError(err)
			}
			err = G.update()
			if err != nil {
				fatalError(err)
			}

			if frameCounter >= time.Second {
				if printFPS {
					fmt.Printf("%d FPS\n", frames)
				}
				frames = 0
				frameCounter -= time.Second
			}
		}

		if render {
			//TODO: Stencil Buffer
			gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

			G.render()
			frames++
			Window.SwapBuffers()
		} else {
			time.Sleep(time.Millisecond)
		}
	}

	Window.Destroy()
}