Example #1
0
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
}
Example #2
0
File: util.go Project: 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)
}
Example #3
0
File: util.go Project: 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)
}
Example #4
0
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)
}