Esempio n. 1
0
func (l *sdlAssetLoader) loadResources() error {
	resourceData, err := payload.Read()
	if err != nil {
		return err
	}
	l.resources, err = blob.Read(bytes.NewBuffer(resourceData))
	if err != nil {
		return err
	}

	// load the texture atlas
	atlas, found := l.resources.GetByID("atlas")
	if !found {
		panic("texture atlas not found in resources")
	}
	rwOps := sdl.RWFromMem(unsafe.Pointer(&atlas[0]), len(atlas))
	surface, err := img.Load_RW(rwOps, false)
	check(err)
	defer surface.Free()
	texture, err := l.renderer.CreateTextureFromSurface(surface)
	check(err)
	l.textureAtlas = texture

	return err
}
Esempio n. 2
0
func (l *windowsAssetloader) loadResources() {
	resourceData, err := payload.Read()
	check(err)
	l.resources, err = blob.Read(bytes.NewBuffer(resourceData))

	// load the texture atlas
	atlas, found := l.resources.GetByID("atlas")
	if !found {
		panic("texture atlas not found in resources")
	}

	ping, err := png.Decode(bytes.NewReader(atlas))
	check(err)

	var nrgba *image.NRGBA
	if asNRGBA, ok := ping.(*image.NRGBA); ok {
		nrgba = asNRGBA
	} else {
		nrgba = image.NewNRGBA(ping.Bounds())
		draw.Draw(nrgba, nrgba.Bounds(), ping, image.ZP, draw.Src)
	}

	texture, err := l.device.CreateTexture(
		uint(nrgba.Bounds().Dx()),
		uint(nrgba.Bounds().Dy()),
		1,
		d3d9.USAGE_SOFTWAREPROCESSING,
		d3d9.FMT_A8R8G8B8,
		d3d9.POOL_MANAGED,
		nil,
	)
	check(err)
	lockedRect, err := texture.LockRect(0, nil, d3d9.LOCK_DISCARD)
	check(err)
	lockedRect.SetAllBytes(nrgba.Pix, nrgba.Stride)
	check(texture.UnlockRect(0))

	l.textureAtlas = texture
	l.textureAtlasBounds = nrgba.Bounds()
}