示例#1
0
// Fills the backbuffer with a particular color. Color is 0xAARRGGBB
func (bb *Backbuffer) Fill(color uint32) {

	r, g, b, a := utils.ColorToRGBABytes(color)

	for i := 0; i < len(bb.pixels); i += bb.bytesPerPixel {
		bb.pixels[i] = b
		bb.pixels[i+1] = g
		bb.pixels[i+2] = r
		bb.pixels[i+3] = a
	}
}
示例#2
0
// Draws a pixel at given coordinates, color is 0xAARRGGBB
func (bb *Backbuffer) DrawPixel(x, y int, color uint32) error {

	pos := ((y * bb.width) + x) * bb.bytesPerPixel

	// Stop unsafe operations
	if pos < 0 {
		return errors.New("Position cannot be negative")
	}
	if pos+3 >= len(bb.pixels)-1 {
		return errors.New("Pixel exceeds backbuffer, cannot set")
	}

	r, g, b, a := utils.ColorToRGBABytes(color)

	// Blue, Green, Red, Alpha
	bb.pixels[pos] = b
	bb.pixels[pos+1] = g
	bb.pixels[pos+2] = r
	bb.pixels[pos+3] = a

	return nil
}