示例#1
0
文件: video.go 项目: nictuku/chip-8
func CaptureToPng(filename string) error {
	// Based on a version from https://github.com/go-gl/glh.

	// Copyright (c) 2012 The go-gl Authors. All rights reserved.
	w, h := glh.GetViewportWH()

	im := image.NewNRGBA(image.Rect(0, 0, w, h))
	gl.ReadBuffer(gl.BACK_LEFT)
	gl.ReadPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, im.Pix)

	// Flip the image vertically.
	//
	// From IRC:
	// <ClaudiusMaximus> nictuku: glReadPixels uses (0,0) at bottom left always
	// - some (most?) image formats use (0,0) as top left
	im = imaging.FlipV(im)

	fd, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer fd.Close()

	png.Encode(fd, im)
	return nil
}
示例#2
0
文件: util.go 项目: pwaller/mema
func Capture() {
	// TODO: co-ordinates, filename, cleverness to stitch many together
	im := image.NewNRGBA(image.Rect(0, 0, 400, 400))
	gl.ReadBuffer(gl.BACK_LEFT)
	gl.ReadPixels(0, 0, 400, 400, gl.RGBA, gl.UNSIGNED_BYTE, im.Pix)

	fd, err := os.Create("test.png")
	if err != nil {
		log.Panic("Err: ", err)
	}
	defer fd.Close()

	png.Encode(fd, im)
}
示例#3
0
文件: util.go 项目: andrebq/glh
func CaptureToPng(filename string) {
	w, h := GetViewportWH()

	im := image.NewNRGBA(image.Rect(0, 0, w, h))
	gl.ReadBuffer(gl.BACK_LEFT)
	gl.ReadPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, im.Pix)

	fd, err := os.Create(filename)
	if err != nil {
		log.Panic("Err: ", err)
	}
	defer fd.Close()

	png.Encode(fd, im)
}
示例#4
0
文件: util.go 项目: jasonrpowers/glh
func CaptureRGBA(im *image.RGBA) {
	b := im.Bounds()
	gl.ReadBuffer(gl.BACK_LEFT)
	gl.ReadPixels(0, 0, b.Dx(), b.Dy(), gl.RGBA, gl.UNSIGNED_BYTE, im.Pix)
}