當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Window.GetSurface方法代碼示例

本文整理匯總了Golang中github.com/veandco/go-sdl2/sdl.Window.GetSurface方法的典型用法代碼示例。如果您正苦於以下問題:Golang Window.GetSurface方法的具體用法?Golang Window.GetSurface怎麽用?Golang Window.GetSurface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/veandco/go-sdl2/sdl.Window的用法示例。


在下文中一共展示了Window.GetSurface方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: createMainWindow

func createMainWindow() {
	var err error
	var mainWindow *sdl.Window

	gc := gamecontext.GContext
	gc.WindowWidth = 800
	gc.WindowHeight = 600

	mainWindow, err = sdl.CreateWindow("Eggdrop!", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, int(gc.WindowWidth), int(gc.WindowHeight), sdl.WINDOW_SHOWN)
	if err != nil {
		panic(err)
	}

	gc.MainSurface, err = mainWindow.GetSurface()
	if err != nil {
		panic(err)
	}

	gc.PixelFormatEnum, err = mainWindow.GetPixelFormat()
	if err != nil {
		panic(err)
	}

	gc.PixelFormat, err = sdl.AllocFormat(uint(gc.PixelFormatEnum)) // TODO why the cast? Seems to work?
	if err != nil {
		panic(err)
	}

	gc.MainWindow = mainWindow
}
開發者ID:beejjorgensen,項目名稱:eggdrop,代碼行數:30,代碼來源:main.go

示例2: 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

示例3: Draw

func Draw(window *sdl.Window, parsedInput *ParsedInput, loop *bool) inputManager.Update {
	surface, err := window.GetSurface()
	if err != nil {
		panic(err)
	}
	surface.FillRect(&sdl.Rect{0, 0, surface.W, surface.H}, 0xff000000)

	var player2Rects [6]sdl.Rect
	for i := 0; i < 6; i++ {
		player2Rects[i] = sdl.Rect{(256 + player1Rects[i].X), (player1Rects[i].Y), (player1Rects[i].W), (player1Rects[i].H)}
	}

	return func(state int) int {
		if *loop {
			for i := 0; i < 6; i++ {
				if parsedInput[i] {
					surface.FillRect(&player1Rects[i], 0xffff0000)
				} else {
					surface.FillRect(&player1Rects[i], 0xffffff00)
				}
				if parsedInput[i+6] {
					surface.FillRect(&player2Rects[i], 0xffff0000)
				} else {
					surface.FillRect(&player2Rects[i], 0xffffff00)
				}
			}
			if parsedInput[12] {
				surface.FillRect(&sdl.Rect{192, 160, 64, 64}, 0xffff0000)
			} else {
				surface.FillRect(&sdl.Rect{192, 160, 64, 64}, 0xffffff00)
			}
			if parsedInput[13] {
				surface.FillRect(&sdl.Rect{192, 224, 64, 64}, 0xffff0000)
			} else {
				surface.FillRect(&sdl.Rect{192, 224, 64, 64}, 0xffffff00)
			}
			err := window.UpdateSurface()
			if err != nil {
				panic(err)
			}
		} else {
			return -1
		}
		return 0
	}
}
開發者ID:ITR13,項目名稱:campusFighterI,代碼行數:46,代碼來源:Graphics.go

示例4: NewPPU

func NewPPU(window *sdl.Window, vram *VRAM) *PPU {
	return &PPU{window: window, surface: window.GetSurface(), vram: vram}
}
開發者ID:jlippitt,項目名稱:gones,代碼行數:3,代碼來源:ppu.go


注:本文中的github.com/veandco/go-sdl2/sdl.Window.GetSurface方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。