本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Quit函数的典型用法代码示例。如果您正苦于以下问题:Golang Quit函数的具体用法?Golang Quit怎么用?Golang Quit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Quit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (dmg *DMG) Run(file string, width, height int) {
sdl.Init(sdl.INIT_VIDEO)
defer sdl.Quit()
dmg.init(file, width, height)
dmg.exec()
}
示例2: main
func main() {
if err := sdl.Init(sdl.INIT_AUDIO); err != nil {
log.Println(err)
return
}
if err := mix.Init(mix.INIT_MP3); err != nil {
log.Println(err)
return
}
defer sdl.Quit()
defer mix.Quit()
defer mix.CloseAudio()
if err := mix.OpenAudio(22050, mix.DEFAULT_FORMAT, 2, 4096); err != nil {
log.Println(err)
return
}
if music, err := mix.LoadMUS("test.mp3"); err != nil {
log.Println(err)
} else if err = music.Play(1); err != nil {
log.Println(err)
} else {
sdl.Delay(5000)
music.Free()
}
}
示例3: Destroy
/*
Destroy the controller object.
*/
func (c *Controller) Destroy() {
c.window.Destroy()
// TODO can I call this anywhere? is this... ok?
sdl.Quit()
// MUST unlock OS thread
runtime.UnlockOSThread()
}
示例4: Start
func (gui *Gui) Start() {
window, err := sdl.CreateWindow(
"nice life",
sdl.WINDOWPOS_UNDEFINED,
sdl.WINDOWPOS_UNDEFINED,
gui.cam.width,
gui.cam.height,
sdl.WINDOW_SHOWN|sdl.WINDOW_RESIZABLE)
if err != nil {
panic(err)
}
surface, err := window.GetSurface()
if err != nil {
panic(err)
}
gui.sdlWindow = window
gui.sdlSurface = surface
go gui.handleInput()
gui.mainLoop()
sdl.Quit()
}
示例5: Close
func (d *Display) Close() {
if d.renderer != nil {
d.renderer.Destroy()
}
if d.window != nil {
d.window.Destroy()
}
sdl.Quit()
}
示例6: main
func main() {
var winTitle string = "Go-SDL2 + Go-GL"
var winWidth, winHeight int = 800, 600
var window *sdl.Window
var context sdl.GLContext
var event sdl.Event
var running bool
var err error
if err = sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic(err)
}
defer sdl.Quit()
if err = gl.Init(); err != nil {
panic(err)
}
window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
winWidth, winHeight, sdl.WINDOW_OPENGL)
if err != nil {
panic(err)
}
defer window.Destroy()
context, err = sdl.GL_CreateContext(window)
if err != nil {
panic(err)
}
defer sdl.GL_DeleteContext(context)
gl.Enable(gl.DEPTH_TEST)
gl.ClearColor(0.2, 0.2, 0.3, 1.0)
gl.ClearDepth(1)
gl.DepthFunc(gl.LEQUAL)
gl.Viewport(0, 0, int32(winWidth), int32(winHeight))
running = true
for running {
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\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", t.Timestamp, t.Which, t.X, t.Y, t.XRel, t.YRel)
}
}
drawgl()
sdl.GL_SwapWindow(window)
}
}
示例7: main
func main() {
flag.Parse()
// go doesMyCodeWork()
// go doesMyCodeWork2()
var x, y int
if len(os.Args) < 3 {
fmt.Println("No size was specified, using defaults")
x = int(640 * 1.5)
y = int(480 * 1.5)
} else {
var err error
x, err = strconv.Atoi(os.Args[1])
if err != nil {
fmt.Println("Could not parse " + os.Args[1] + " to int!")
return
}
y, err = strconv.Atoi(os.Args[2])
if err != nil {
fmt.Println("Could not parse " + os.Args[2] + " to int!")
return
}
}
window, err := sdl.CreateWindow("Campus Fighter I", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, x, y, sdl.WINDOWPOS_UNDEFINED)
if err != nil {
panic(err)
}
defer window.Destroy()
//sdl.ShowCursor(0)
window.UpdateSurface()
renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if err != nil {
panic(err)
}
surface, err := window.GetSurface()
if err != nil {
panic(err)
}
controlManager := inputManager.GetControlManager()
updateFunctionsToStartWith := make([]inputManager.Update, 1)
updateFunctionsToStartWith[0] = menus.CreateMenus(window, surface, renderer, &controlManager)
inputManager.StateMachine(controlManager.ReadInput(), updateFunctionsToStartWith)
sdl.Quit()
}
示例8: main
func main() {
sdlInit()
gm := gamemanager.GGameManager
gc := gamecontext.GContext
createMainWindow()
defer gc.MainWindow.Destroy()
intro := &introstate.IntroState{}
play := &playstate.PlayState{}
gm.RegisterMode(gamemanager.GameModeIntro, intro)
gm.RegisterMode(gamemanager.GameModePlay, play)
done := false
// Keep handy for use in the loop
mainWindow := gc.MainWindow
mainWindowSurface := gc.MainSurface
gm.SetMode(gamemanager.GameModeIntro)
gm.SetEventMode(gamemanager.GameManagerEventDriven)
for done == false {
event := gm.GetNextEvent()
for ; event != nil; event = sdl.PollEvent() {
done = done || gm.HandleEvent(&event)
switch event := event.(type) {
case *sdl.WindowEvent:
//fmt.Printf("Window: %#v\n", event)
//fmt.Printf("Event: %t %t\n", event.Event, sdl.WINDOWEVENT_CLOSE)
if event.Event == sdl.WINDOWEVENT_CLOSE {
done = done || true
}
}
}
gm.Render(mainWindowSurface)
mainWindow.UpdateSurface()
gm.DelayToNextFrame()
}
sdl.Quit()
}
示例9: Destroy
// Destroys SDL and releases the memory
func (e *Engine) Destroy() {
for _, v := range e.StateText {
v.Texture.Destroy()
}
e.Sprite.Destroy()
e.Font.Close()
e.Music.Free()
e.Sound.Free()
e.Renderer.Destroy()
e.Window.Destroy()
ttf.Quit()
mix.CloseAudio()
mix.Quit()
sdl.Quit()
}
示例10: main
func main() {
if err := sdl.Init(sdl.INIT_AUDIO); err != nil {
log.Println(err)
return
}
defer sdl.Quit()
spec := &sdl.AudioSpec{
Freq: sampleHz,
Format: sdl.AUDIO_U8,
Channels: 2,
Samples: sampleHz,
Callback: sdl.AudioCallback(C.SineWave),
}
sdl.OpenAudio(spec, nil)
sdl.PauseAudio(false)
time.Sleep(1 * time.Second)
}
示例11: main
// The programs main function
func main() {
// ---- This is the start of Owen's graphics setup code ----
// First we have to initalise the SDL library, before we can use it
sdl.Init(sdl.INIT_EVERYTHING)
// defer is a go keyword and a special feature.
// This means that go will automatically call the function sdl.Quit() before
// the program exits for us. We don't have to remember to put this at the end!
defer sdl.Quit()
// if you want to change these try 800 for the width and 600 for the height
windowWidth = 1024
windowHeight = 768
// Now we have to create the window we want to use.
// We need to tell the SDL library how big to make the window of the correct
// size - that's what the bit in the brackets does
window = createWindow(windowWidth, windowHeight)
// automatically destroy the window when the program finishes
defer window.Destroy()
// Now we have a window we need to create a renderer so we can draw into
// it. In this case we want to use the first graphics card that supports faster
// drawing
renderer = createRenderer(window)
// automatically destroy the renderer when the program exits.
defer renderer.Destroy()
// Set a black i.e. RGBA (0,0,0,0) background colour and clear the window
renderer.SetDrawColor(0, 0, 0, 0)
renderer.Clear()
// ---- This is the end of Owen's graphics setup code ----
// defer any cleanup actions
defer cleanup()
// initialise the games variables.
initialise()
// render everything initially so that we can see the game before it starts
render()
// now start the main game loop of the game.
gameMainLoop()
}
示例12: main
func main() {
var (
err error
window *sdl.Window
context sdl.GLContext
)
if err = sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic(err)
}
defer sdl.Quit()
sdl.GL_SetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 3)
sdl.GL_SetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 2)
sdl.GL_SetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_CORE)
window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, winWidth, winHeight, sdl.WINDOW_OPENGL)
if err != nil {
panic(err)
}
defer window.Destroy()
context, err = sdl.GL_CreateContext(window)
if err != nil {
panic(err)
}
defer sdl.GL_DeleteContext(context)
if err = sdl.GL_MakeCurrent(window, context); err != nil {
panic(err)
}
if err = gl.Init(); err != nil {
panic(err)
}
printGLInfo()
cameraMatrixUniform := setupGL()
windowLoop(window, cameraMatrixUniform)
}
示例13: main
func main() {
var (
err error
window *sdl.Window
context sdl.GLContext
)
if err = sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic(err)
}
defer sdl.Quit()
sdl.GL_SetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_COMPATIBILITY)
window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, winWidth, winHeight, sdl.WINDOW_OPENGL)
if err != nil {
panic(err)
}
defer window.Destroy()
context, err = sdl.GL_CreateContext(window)
if err != nil {
panic(err)
}
defer sdl.GL_DeleteContext(context)
if err = sdl.GL_MakeCurrent(window, context); err != nil {
panic(err)
}
if err = gl.Init(); err != nil {
panic(err)
}
sdl.GL_SetSwapInterval(1)
printGLInfo()
setupGL()
windowLoop(window)
}
示例14: TestTexture
func TestTexture(t *testing.T) {
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
panic(sdl.GetError())
}
defer sdl.Quit()
window := sdl.CreateWindow("test", 0, 0, 320, 200, sdl.WINDOW_HIDDEN|sdl.WINDOW_OPENGL)
defer window.Destroy()
sdl.GL_SetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_ES)
sdl.GL_SetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 2)
sdl.GL_SetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 0)
glctx := sdl.GL_CreateContext(window)
defer sdl.GL_DeleteContext(glctx)
tex := gl.CreateTexture()
gl.BindTexture(gl.TEXTURE_2D, tex)
if !gl.IsTexture(tex) {
t.Error(tex, "is not a texture")
}
}
示例15: main
func main() {
sdl.Init(sdl.INIT_EVERYTHING)
window, err := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
800, 600, sdl.WINDOW_SHOWN)
if err != nil {
panic(err)
}
defer window.Destroy()
surface, err := window.GetSurface()
if err != nil {
panic(err)
}
rect := sdl.Rect{0, 0, 200, 200}
surface.FillRect(&rect, 0xffff0000)
window.UpdateSurface()
sdl.Delay(1000)
sdl.Quit()
}