• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang sdl.Surface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Surface的典型用法代码示例。如果您正苦于以下问题:Golang Surface类的具体用法?Golang Surface怎么用?Golang Surface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Surface类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Render

// Render renders the intro state
func (ps *PlayState) Render(mainWindowSurface *sdl.Surface) {
	ps.update()

	mainWindowSurface.FillRect(nil, ps.bgColor)

	ps.interludeTextEntity.Visible = ps.state.state == stateInterlude

	ps.rootEntity.Render(mainWindowSurface)
}
开发者ID:beejjorgensen,项目名称:eggdrop,代码行数:10,代码来源:playstate.go


示例2: drawCell

func (r *SDLRenderer) drawCell(window_surf, cell_surface *sdl.Surface,
	x, y, w, h int32, transparent bool) error {
	if cell_surface == nil {
		return fmt.Errorf("unknown cell type")
	}
	if !transparent {
		err := r.getCellImage(grid.Cell{Type: grid.Empty}).BlitScaled(nil,
			window_surf, &sdl.Rect{X: x, Y: y + statusSize, W: w, H: h})
		if err != nil {
			return err
		}
	}
	return cell_surface.BlitScaled(nil, window_surf, &sdl.Rect{
		X: x, Y: y + statusSize, W: w, H: h})
}
开发者ID:nkhuyu,项目名称:htc2015,代码行数:15,代码来源:sdl.go


示例3: run

func run() int {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var image *sdl.Surface
	var texture *sdl.Texture
	var src, dst sdl.Rect
	var err error

	window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		winWidth, winHeight, sdl.WINDOW_SHOWN)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", err)
		return 1
	}
	defer window.Destroy()

	renderer, err = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", err)
		return 2
	}
	defer renderer.Destroy()

	image, err = sdl.LoadBMP(imageName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to load BMP: %s\n", err)
		return 3
	}
	defer image.Free()

	texture, err = renderer.CreateTextureFromSurface(image)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", err)
		return 4
	}
	defer texture.Destroy()

	src = sdl.Rect{0, 0, 512, 512}
	dst = sdl.Rect{100, 50, 512, 512}

	renderer.Clear()
	renderer.Copy(texture, &src, &dst)
	renderer.Present()

	sdl.Delay(2000)

	return 0
}
开发者ID:emlai,项目名称:go-sdl2,代码行数:48,代码来源:texture.go


示例4: run

func run() int {
	var window *sdl.Window
	var font *ttf.Font
	var surface *sdl.Surface
	var solid *sdl.Surface
	var err error

	sdl.Init(sdl.INIT_VIDEO)

	if err := ttf.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "Failed to initialize TTF: %s\n", err)
		return 1
	}

	if window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, winWidth, winHeight, sdl.WINDOW_SHOWN); err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", err)
		return 2
	}
	defer window.Destroy()

	if font, err = ttf.OpenFont("../../assets/test.ttf", 32); err != nil {
		fmt.Fprint(os.Stderr, "Failed to open font: %s\n", err)
		return 4
	}
	defer font.Close()

	if solid, err = font.RenderUTF8_Solid("Hello, World!", sdl.Color{255, 0, 0, 255}); err != nil {
		fmt.Fprint(os.Stderr, "Failed to render text: %s\n", err)
		return 5
	}
	defer solid.Free()

	if surface, err = window.GetSurface(); err != nil {
		fmt.Fprint(os.Stderr, "Failed to get window surface: %s\n", err)
		return 6
	}

	if err = solid.Blit(nil, surface, nil); err != nil {
		fmt.Fprint(os.Stderr, "Failed to put text on window surface: %s\n", err)
		return 7
	}

	// Show the pixels for a while
	window.UpdateSurface()
	sdl.Delay(3000)

	return 0
}
开发者ID:veandco,项目名称:go-sdl2,代码行数:48,代码来源:text.go


示例5: main

func main() {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var image *sdl.Surface
	var texture *sdl.Texture
	var src, dst sdl.Rect

	window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		winWidth, winHeight, sdl.WINDOW_SHOWN)
	if window == nil {
		fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
		os.Exit(1)
	}

	renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
	if renderer == nil {
		fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
		os.Exit(2)
	}

	image = sdl.LoadBMP(imageName)
	if image == nil {
		fmt.Fprintf(os.Stderr, "Failed to load BMP: %s", sdl.GetError())
		os.Exit(3)
	}

	texture = renderer.CreateTextureFromSurface(image)
	if texture == nil {
		fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", sdl.GetError())
		os.Exit(4)
	}

	src = sdl.Rect{0, 0, 512, 512}
	dst = sdl.Rect{100, 50, 512, 512}

	renderer.Clear()
	renderer.Copy(texture, &src, &dst)
	renderer.Present()

	sdl.Delay(2000)

	image.Free()
	texture.Destroy()
	renderer.Destroy()
	window.Destroy()
}
开发者ID:JalfResi,项目名称:go-sdl2,代码行数:46,代码来源:texture.go


示例6: TestTTF

func TestTTF(t *testing.T) {
	var font *Font
	var solid *sdl.Surface
	var err error

	if err := Init(); err != nil {
		t.Errorf("Failed to initialize TTF: %s\n", err)
	}

	if font, err = OpenFont("../assets/test.ttf", 32); err != nil {
		t.Errorf("Failed to open font: %s\n", err)
	}
	defer font.Close()

	for i := 0; i < 10000; i++ {
		if solid, err = font.RenderUTF8_Solid(randomString(t), sdl.Color{255, 0, 0, 255}); err != nil {
			t.Errorf("Failed to render text: %s\n", err)
		}
		defer solid.Free()
	}
}
开发者ID:veandco,项目名称:go-sdl2,代码行数:21,代码来源:sdl_ttf_test.go


示例7: CreateMenus

func CreateMenus(window *sdl.Window, surface *sdl.Surface, renderer *sdl.Renderer, controlManager *inputManager.ControlManager) inputManager.Update {
	progress := float64(0)
	mutex := sync.Mutex{}
	dx := 4 * surface.W / 8
	startRect := sdl.Rect{surface.W / 4, 4 * surface.H / 7, 0, 2 * surface.H / 7}
	midBackgroundRect := sdl.Rect{surface.W / 4, 4 * surface.H / 7, dx, 2 * surface.H / 7}
	backgroundRect := sdl.Rect{surface.W/4 - 5, 4*surface.H/7 - 5, dx + 10, 2*surface.H/7 + 10}
	var mainMenu *Menu
	go asyncMenuCreator(renderer, &mutex, &progress, &mainMenu, surface.W, surface.H, window, controlManager)
	return func(state int) int {
		if controlManager.Player1.BF || controlManager.Player2.BF {
			controlManager.Running = false
			return -1
		}
		mutex.Lock()
		startRect.W = int32(float64(dx) * progress)
		surface.FillRect(&backgroundRect, 0xffff0000)
		surface.FillRect(&midBackgroundRect, 0xff000000)
		surface.FillRect(&startRect, 0xffff0000)
		window.UpdateSurface()
		if progress == 1 {
			menuInfo := MenuInfo{0, controlManager, renderer, &sdl.Rect{0, 0, surface.W, surface.H}}
			inputManager.UpdateFunctions = append(inputManager.UpdateFunctions, mainMenu.Open(0, &menuInfo))
			return -1
		}
		mutex.Unlock()
		return 0
	}
}
开发者ID:ITR13,项目名称:campusFighterI,代码行数:29,代码来源:CreateMenus.go


示例8: surfaceManipulate

// 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
}
开发者ID:beejjorgensen,项目名称:eggdrop,代码行数:29,代码来源:util.go


示例9: SurfaceConvertToImage

func SurfaceConvertToImage(s *sdl.Surface) (img image.Image, err error) {
	switch s.Format.Format {
	case sdl.PIXELFORMAT_RGBA8888, sdl.PIXELFORMAT_RGBX8888:
		i := &image.RGBA{Rect: image.Rect(0, 0, int(s.W), int(s.H))}
		i.Pix = s.Pixels()
		img = i
	case sdl.PIXELFORMAT_INDEX8:
		i := image.NewRGBA(image.Rect(0, 0, int(s.W), int(s.H)))
		key, err := s.GetColorKey()
		if err != nil {
			return nil, err
		}
		//		fmt.Println(s.PixelNum(), len(s.Pixels()), len(i.Pix), s.W, s.H, s.Pitch, s.Format.BitsPerPixel, s.Format.BytesPerPixel, key)
		l := len(s.Pixels())
		var r, g, b, a uint8
		for n := 0; n < l; n += 1 {
			pixel := s.Pixels()[n]
			if pixel == uint8(key) {
				r, g, b, a = 0, 0, 0, 0
			} else {
				r, g, b, a = sdl.GetRGBA(uint32(pixel), s.Format)
			}

			p := i.PixOffset(n%int(s.Pitch), n/int(s.Pitch))
			i.Pix[p], i.Pix[p+1], i.Pix[p+2], i.Pix[p+3] = r, g, b, a
		}
		img = i
	default:
		sx, err := s.ConvertFormat(sdl.PIXELFORMAT_RGBX8888, 0)
		if err != nil {
			return nil, err
		}
		i := &image.RGBA{Rect: image.Rect(0, 0, int(s.W), int(s.H))}
		i.Pix = sx.Pixels()
		img = i
	}
	return
}
开发者ID:FieldSoft-HelloClyde,项目名称:bbvm,代码行数:38,代码来源:sdl.go


示例10: LoadGraphic

// LoadGraphic loads a graphic from disk or panics trying. The image can be in
// BMP, GIF, JPEG, LBM, PCX, PNG, PNM, TGA, TIFF, WEBP, XCF, XPM, or XV format.
// The user must supply the filename of the graphic file to load, in the
// parameter filename.
//
// If the function succeeds then a variable of type Graphic will be returned
// back to the calling function. It is the programmers responsibility to
// store this in a variable of type Graphic.
//
// If the function fails it will panic and crash the program.
// The reasons for a panic are:
//
// 1. The toolbox has not been initalised
//
// 2. The filename does not exist, or is otherwise inaccessable. The specific
// reason will be contained in the panic message itself. This message will
// be prefixed with "Failed to load file: ".
//
// 3. The file could not be converted into a Graphic type. Again the specific
// reason will be contained in the panic message itself. This message will be
// prefixed with "Failed to create Graphic: "
func LoadGraphic(filename string) Graphic {
	if !initialised {
		// this stops execution here, so ne need for an else after the if
		panic(notInitialisedMessage)
	}

	var err error
	var image *sdl.Surface
	image, err = img.Load(filename)
	if err != nil {
		fmt.Print("Failed to load file: ")
		fmt.Println(err)
		panic(err)
	}
	defer image.Free()
	var graphic *sdl.Texture
	graphic, err = renderer.CreateTextureFromSurface(image)
	if err != nil {
		fmt.Print("Failed to create Graphic: ")
		fmt.Println(err)
		panic(err)
	}
	return Graphic(graphic)
}
开发者ID:gophercoders,项目名称:toolbox,代码行数:45,代码来源:toolbox.go


示例11: Render

// Render renders the intro state
func (is *IntroState) Render(mainWindowSurface *sdl.Surface) {
	rootEntity := is.rootEntity

	mainWindowSurface.FillRect(nil, is.bgColor)
	rootEntity.Render(mainWindowSurface)
}
开发者ID:beejjorgensen,项目名称:eggdrop,代码行数:7,代码来源:introstate.go



注:本文中的github.com/veandco/go-sdl2/sdl.Surface类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang sdl.Texture类代码示例发布时间:2022-05-28
下一篇:
Golang sdl.Renderer类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap