Example #1
0
File: init.go Project: shenyp09/mx3
func InitWindow(w, h int, multisample int, vsync bool) {
	core.Fatal(glfw.Init())
	if multisample != 0 {
		glfw.OpenWindowHint(glfw.FsaaSamples, multisample)
	}
	Width, Height = w, h
	core.Fatal(glfw.OpenWindow(Width, Height, r, g, b, a, depth, stencil, glfw.Windowed))
	glfw.SetWindowTitle("mumax cubed")
	if vsync {
		glfw.SetSwapInterval(1)
	}
}
Example #2
0
func Screenshot() {
	log.Println("screenshot")
	img := image.NewNRGBA(image.Rect(0, 0, Width, Height))
	gl.ReadPixels(0, 0, gl.Sizei(Width), gl.Sizei(Height), gl.RGBA, gl.UNSIGNED_INT_8_8_8_8, gl.Pointer(&img.Pix[0]))
	// reverse byte order, opengl seems to use little endian.
	pix := img.Pix
	for i := 0; i < len(pix); i += 4 {
		pix[i+0], pix[i+1], pix[i+2], pix[i+3] = pix[i+3], pix[i+2], pix[i+1], pix[i+0]
	}
	fname := fmt.Sprintf("frame%04d.png", scroti)
	scroti++
	f, err := os.OpenFile(fname, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
	core.Fatal(err)
	defer f.Close()
	core.Fatal(png.Encode(f, img))
}
Example #3
0
File: init.go Project: shenyp09/mx3
func InitGL(smooth bool, multisample int) {
	core.Fatal(gl.Init())

	gl.Enable(gl.LIGHTING)

	gl.Enable(gl.CULL_FACE)
	gl.CullFace(gl.BACK)

	if multisample != 0 {
		gl.Enable(gl.MULTISAMPLE)
	}

	if smooth {
		gl.ShadeModel(gl.SMOOTH)
	}
}