本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Surface.Free方法的典型用法代码示例。如果您正苦于以下问题:Golang Surface.Free方法的具体用法?Golang Surface.Free怎么用?Golang Surface.Free使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/veandco/go-sdl2/sdl.Surface
的用法示例。
在下文中一共展示了Surface.Free方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例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
}
示例3: 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()
}
示例4: 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()
}
}
示例5: 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)
}