本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.GetError函数的典型用法代码示例。如果您正苦于以下问题:Golang GetError函数的具体用法?Golang GetError怎么用?Golang GetError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Init
func Init(width, height int32) *Engine {
window, err := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
int(width), int(height), sdl.WINDOW_SHOWN)
if err != nil {
fmt.Fprint(os.Stderr, "Failed to create window", sdl.GetError())
os.Exit(1)
}
renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED|sdl.RENDERER_PRESENTVSYNC)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(2)
}
img.Init(0)
ttf.Init()
return &Engine{
Window: window,
Renderer: renderer,
Running: true,
width: width,
height: height,
entities: make([]Drawable, 0),
}
}
示例2: start
func start() {
if sdl.Init(sdl.INIT_AUDIO) < 0 {
fmt.Fprintf(os.Stderr, "Failed to init:", sdl.GetError())
os.Exit(1)
}
window = sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
int(W), int(H), 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|sdl.RENDERER_PRESENTVSYNC)
if renderer == nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(1)
}
mix.SetSoundFonts("resources/")
if !mix.OpenAudio(44100, mix.DEFAULT_FORMAT, 2, 2048) {
fmt.Fprintf(os.Stderr, "Failed to open audio:%s\n", sdl.GetError())
os.Exit(1)
}
}
示例3: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var event sdl.Event
var running bool
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)
}
var peepArray []sdl.Event = make([]sdl.Event, 5)
running = true
for running {
sdl.PumpEvents()
numEventsRetrieved := sdl.PeepEvents(peepArray, sdl.PEEKEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
if numEventsRetrieved < 0 {
fmt.Printf("PeepEvents error: %s\n", sdl.GetError())
} else {
for i := 0; i < numEventsRetrieved; i++ {
fmt.Printf("Event Peeked Value: %v\n", peepArray[i]) // primitive printing of event
}
}
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyUpEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
}
}
sdl.Delay(1000 / 30)
}
renderer.Destroy()
window.Destroy()
}
示例4: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var points []sdl.Point
var rect sdl.Rect
var rects []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)
}
renderer.SetDrawColor(255, 255, 255, 255)
renderer.DrawPoint(150, 300)
renderer.SetDrawColor(0, 0, 255, 255)
renderer.DrawLine(0, 0, 200, 200)
points = []sdl.Point{{0, 0}, {100, 300}, {100, 300}, {200, 0}}
renderer.SetDrawColor(255, 255, 0, 255)
renderer.DrawLines(points)
rect = sdl.Rect{300, 0, 200, 200}
renderer.SetDrawColor(255, 0, 0, 255)
renderer.DrawRect(&rect)
rects = []sdl.Rect{{400, 400, 100, 100}, {550, 350, 200, 200}}
renderer.SetDrawColor(0, 255, 255, 255)
renderer.DrawRects(rects)
rect = sdl.Rect{250, 250, 200, 200}
renderer.SetDrawColor(0, 255, 0, 255)
renderer.FillRect(&rect)
rects = []sdl.Rect{{500, 300, 100, 100}, {200, 300, 200, 200}}
renderer.SetDrawColor(255, 0, 255, 255)
renderer.FillRects(rects)
renderer.Present()
sdl.Delay(2000)
renderer.Destroy()
window.Destroy()
}
示例5: Start
func Start(windowText string, W, H int) (*sdl.Window, *sdl.Renderer) {
window, err := sdl.CreateWindow(windowText, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
W, H, sdl.WINDOW_SHOWN)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
os.Exit(1)
}
renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED|sdl.RENDERER_PRESENTVSYNC)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(1)
}
return window, renderer
}
示例6: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var event sdl.Event
var running bool
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)
}
running = true
for running {
event = sdl.WaitEventTimeout(1000) // wait here until an event is in the event queue
if event == nil {
fmt.Println("WaitEventTimeout timed out")
continue
}
switch t := event.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyUpEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
}
}
renderer.Destroy()
window.Destroy()
}
示例7: SetMusicPosition
// SetMusicPosition
// (https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_65.html)
func SetMusicPosition(position int64) error {
_position := (C.double)(position)
if C.Mix_SetMusicPosition(_position) == -1 {
return sdl.GetError()
}
return nil
}
示例8: NewWindowedWindow
func NewWindowedWindow(title string, width, height int) Window {
// FOR GLFW event handling
runtime.LockOSThread()
windowSDL, err := sdl.CreateWindow(title, sdl.WINDOWPOS_UNDEFINED,
sdl.WINDOWPOS_UNDEFINED,
width, height, sdl.WINDOW_OPENGL)
if err != nil {
panic(err)
}
if windowSDL == nil {
panic(sdl.GetError())
}
context, err := sdl.GL_CreateContext(windowSDL)
sdl.GL_MakeCurrent(windowSDL, context)
if err != nil {
panic("Error loading window: " + err.Error())
}
w := Window{title: title, Width: width, Height: height, full: false, windowSDL: windowSDL, contextSDL: context, running: false}
w.init()
var current sdl.DisplayMode
if err := sdl.GetCurrentDisplayMode(0, ¤t); err != nil {
fmt.Println("COuld not get display mode: " + err.Error())
}
fmt.Printf("Display #%d: current display mode is %dx%dpx @ %dhz. \n", 0, current.W, current.H, current.RefreshRate)
return w
}
示例9: Init
func Init(flags int) error {
initted := int(C.Mix_Init(C.int(flags)))
if initted&flags != flags {
return sdl.GetError()
}
return nil
}
示例10: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
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 := img.Load(imageName)
if image == nil {
fmt.Fprintf(os.Stderr, "Failed to load PNG: %s\n", 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.SetDrawColor(255, 0, 0, 255)
renderer.FillRect(&sdl.Rect{0, 0, int32(winWidth), int32(winHeight)})
renderer.Copy(texture, &src, &dst)
renderer.Present()
sdl.Delay(2000)
image.Free()
texture.Destroy()
renderer.Destroy()
window.Destroy()
}
示例11: loadTexture
func loadTexture(path string) *sdl.Texture {
bmp := img.Load(path)
if bmp == nil {
fmt.Fprintf(os.Stderr, "Unable to load image %s! SDL Error: %s\n", path, img.GetError())
} else {
if bmp.SetColorKey(1, sdl.Color{0xFF, 0xFF, 0x00, 0xFF}.Uint32()) != 0 {
fmt.Fprintf(os.Stderr, "Unable to set Color Key %s! SDL Error: %s\n", path, sdl.GetError())
}
texture := renderer.CreateTextureFromSurface(bmp)
if texture == nil {
fmt.Fprintf(os.Stderr, "Unable to create texture %s! SDL Error: %s\n", path, sdl.GetError())
}
bmp.Free()
return texture
}
return nil
}
示例12: Play
// Play (https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_57.html)
func (music *Music) Play(loops int) error {
_music := (*C.Mix_Music)(unsafe.Pointer(music))
_loops := (C.int)(loops)
if C.Mix_PlayMusic(_music, _loops) == -1 {
return sdl.GetError()
}
return nil
}
示例13: LoadTextureTransparent
func LoadTextureTransparent(renderer *sdl.Renderer, path string, r, g, b uint8) *sdl.Texture {
bmp, err := img.Load(path)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to load image %s! SDL Error: %s\n", path, img.GetError())
} else {
if bmp.SetColorKey(1, sdl.MapRGB(bmp.Format, r, g, b)) != 0 {
fmt.Fprintf(os.Stderr, "Unable to set Color Key %s! SDL Error: %s\n", path, sdl.GetError())
}
texture, err := renderer.CreateTextureFromSurface(bmp)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create texture %s! SDL Error: %s\n", path, sdl.GetError())
}
bmp.Free()
return texture
}
return nil
}
示例14: SetMusicCMD
// SetMusicCMD
// (https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_66.html)
func SetMusicCMD(command string) error {
_command := C.CString(command)
defer C.free(unsafe.Pointer(_command))
if C.Mix_SetMusicCMD(_command) == -1 {
return sdl.GetError()
}
return nil
}
示例15: SetDistance
// SetDistance
// (https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_81.html)
func SetDistance(channel int, distance uint8) error {
_channel := (C.int)(channel)
_distance := (C.Uint8)(distance)
if (C.Mix_SetDistance(_channel, _distance)) == 0 {
return sdl.GetError()
}
return nil
}