예제 #1
0
func LoadTextureCube(filename string) {
	surface := loadSdlSurface(filename)
	defer surface.Free()

	W := surface.W / 4
	H := surface.H / 3

	top_rect := sdl.Rect{W, 0 * H, W, H}
	bottom_rect := sdl.Rect{W, 2 * H, W, H}
	left_rect := sdl.Rect{0 * W, H, W, H}
	front_rect := sdl.Rect{1 * W, H, W, H}
	right_rect := sdl.Rect{2 * W, H, W, H}
	back_rect := sdl.Rect{3 * W, H, W, H}
	bounds := sdl.Rect{0, 0, W, H}
	imageData, _ := sdl.CreateRGBSurface(0, W, H, 32, surface.Format.Rmask, surface.Format.Gmask, surface.Format.Bmask, surface.Format.Amask)

	surface.Blit(&top_rect, imageData, &bounds)
	gl.TexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.RGBA, int(W), int(H), 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData.Pixels())
	surface.Blit(&bottom_rect, imageData, &bounds)
	gl.TexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGBA, int(W), int(H), 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData.Pixels())
	surface.Blit(&left_rect, imageData, &bounds)
	gl.TexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, gl.RGBA, int(W), int(H), 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData.Pixels())
	surface.Blit(&right_rect, imageData, &bounds)
	gl.TexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA, int(W), int(H), 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData.Pixels())
	surface.Blit(&back_rect, imageData, &bounds)
	gl.TexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGBA, int(W), int(H), 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData.Pixels())
	surface.Blit(&front_rect, imageData, &bounds)
	gl.TexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGBA, int(W), int(H), 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData.Pixels())
}
예제 #2
0
파일: lcd.go 프로젝트: jlukacs/gameboy
func newLCD(width, height int) *lcd {
	window, err := sdl.CreateWindow("Game Boy",
		sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED,
		width, height,
		sdl.WINDOW_SHOWN)

	if err != nil {
		log.Fatal(err)
	}

	windowSurface, err := window.GetSurface()

	if err != nil {
		window.Destroy()
		log.Fatal(err)
	}

	surface, err := sdl.CreateRGBSurface(0, lcdWidth, lcdHeight, 32,
		0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000)

	if err != nil {
		window.Destroy()
		log.Fatal(err)
	}

	return &lcd{window, windowSurface, surface, []byte{},
		[lcdWidth * lcdHeight]uint8{}, width, height}
}
예제 #3
0
// MakeFillSurfaceAlpha makes a new rectangular surface and fills with with RGBA
func MakeFillSurfaceAlpha(width, height int32, red, green, blue, alpha uint8) (*sdl.Surface, error) {
	pf, err := sdl.AllocFormat(sdl.PIXELFORMAT_RGBA8888)
	if err != nil {
		return nil, err
	}
	color := sdl.MapRGBA(pf, red, green, blue, alpha)
	surface, err := sdl.CreateRGBSurface(0, width, height, 32, pf.Rmask, pf.Gmask, pf.Bmask, pf.Amask)
	if err != nil {
		return nil, err
	}
	surface.FillRect(&sdl.Rect{X: 0, Y: 0, W: width, H: height}, color)

	return surface, nil
}
예제 #4
0
// surfaceManipulate is an internal function that creates a new surface, gets
// metadata, and then calls a passed-in function to actually do something to it,
// e.g. horizontally flip all the pixels.
//
// Note: this only supports manipulations that leave the Surface the same
// dimensions. It could potentially be generalized to handle manipulations that
// leave the Surface with the same number of pixels.
func surfaceManipulate(src *sdl.Surface, f func(src *sdl.Surface, srcWBytes, bytesPerPixel int32, srcPx, destPx []byte)) (*sdl.Surface, error) {
	pf := src.Format

	pixels := src.Pixels()
	bytesPP := int32(pf.BytesPerPixel)
	bitsPP := int32(pf.BitsPerPixel)

	newSurface, err := sdl.CreateRGBSurface(0, src.W, src.H, bitsPP, pf.Rmask, pf.Gmask, pf.Bmask, pf.Amask)

	if err != nil {
		return nil, err
	}

	pixelsDest := newSurface.Pixels()

	srcWBytes := int32(src.W * bytesPP)

	// Perform the manipulation
	f(src, srcWBytes, bytesPP, pixels, pixelsDest)

	return newSurface, nil
}
예제 #5
0
// MakeEmptySurfaceFrom makes a new empty surface the same size and format of the given surface.
// WARNING: does not handle palettized images!
func MakeEmptySurfaceFrom(src *sdl.Surface) (*sdl.Surface, error) {
	pf := src.Format

	return sdl.CreateRGBSurface(0, src.W, src.H, int32(pf.BitsPerPixel), pf.Rmask, pf.Gmask, pf.Bmask, pf.Amask)
}