本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Init函数的典型用法代码示例。如果您正苦于以下问题:Golang Init函数的具体用法?Golang Init怎么用?Golang Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Init
// Initializes SDL
func (e *Engine) Init() (err error) {
err = sdl.Init(sdl.INIT_VIDEO | sdl.INIT_AUDIO)
if err != nil {
return
}
err = mix.Init(mix.INIT_OGG)
if err != nil {
return
}
err = ttf.Init()
if err != nil {
return
}
err = mix.OpenAudio(mix.DEFAULT_FREQUENCY, mix.DEFAULT_FORMAT, mix.DEFAULT_CHANNELS, 3072)
if err != nil {
return
}
e.Window, err = sdl.CreateWindow(WinTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, WinWidth, WinHeight, sdl.WINDOW_SHOWN)
if err != nil {
return
}
e.Renderer, err = sdl.CreateRenderer(e.Window, -1, sdl.RENDERER_ACCELERATED)
if err != nil {
return
}
return
}
开发者ID:yukiisbored,项目名称:Kaori-Android,代码行数:34,代码来源:example.go
示例2: Build
/*
Build creates a Controller struct. NOTE: locks the OS thread. Make sure to call
all Controller.func from the exact same goroutine, otherwise the SDL context
may crash!
*/
func Build() (*Controller, error) {
// MUST guarantee controller always runs in same OS thread
runtime.LockOSThread()
sdl.Init(sdl.INIT_EVERYTHING)
// prepare basic Controller stuff
c := &Controller{}
c.renderable = makeOrdered()
c.entities = make(map[string]interface{})
c.keyreceivers = make(map[string][]*keyReceive)
c.textCache = make(map[string]*sdl.Texture)
// window
window, err := sdl.CreateWindow("Orbiting", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 800, 600, sdl.WINDOW_SHOWN)
if err != nil {
return nil, err
}
c.window = window
// create renderer (reference kept by window, no need to do it ourselves)
renderer, err := sdl.CreateRenderer(c.window, -1, 0)
if err != nil {
return nil, err
}
// however, we DO want to keep just a single instance of the wrapper
c.wrapped = &Renderer{renderer: renderer}
return c, nil
}
开发者ID:xamino,项目名称:orbengine,代码行数:30,代码来源:main.go
示例3: 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()
}
}
开发者ID:4gophers,项目名称:go-sdl2,代码行数:28,代码来源:audio_mp3.go
示例4: 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)
}
}
开发者ID:EvanTheB,项目名称:SDLGame,代码行数:26,代码来源:21sound.go
示例5: 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()
}
开发者ID:jlukacs,项目名称:gameboy,代码行数:7,代码来源:DMG.go
示例6: Init
func Init() error {
// This is needed to make sure that we are always running the graphics code in the same OS thread as it is initialized in.
runtime.LockOSThread()
if runtime.GOMAXPROCS(-1) == 1 {
runtime.GOMAXPROCS(2)
}
return sdl.Init(sdl.INIT_EVERYTHING)
}
开发者ID:Oralordos,项目名称:Game-Programming-Project,代码行数:8,代码来源:window.go
示例7: OpenDisplay
func OpenDisplay(width uint32, height uint32) (*Display, error) {
display := Display{}
sdl.Init(sdl.INIT_EVERYTHING)
window, err := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, int(width), int(height), sdl.WINDOW_SHOWN)
if err != nil {
return nil, err
}
display.window = window
return &display, nil
}
开发者ID:sparkymat,项目名称:deimos,代码行数:12,代码来源:raw.go
示例8: NewAdaptor
// NewAdaptor returns a new Joystick Adaptor.
func NewAdaptor() *Adaptor {
return &Adaptor{
name: "Joystick",
connect: func(j *Adaptor) (err error) {
sdl.Init(sdl.INIT_JOYSTICK)
if sdl.NumJoysticks() > 0 {
j.joystick = sdl.JoystickOpen(0)
return
}
return errors.New("No joystick available")
},
}
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:14,代码来源:joystick_adaptor.go
示例9: NewJoystickAdaptor
// NewJoystickAdaptor returns a new JoystickAdaptor with specified name.
func NewJoystickAdaptor(name string) *JoystickAdaptor {
return &JoystickAdaptor{
name: name,
connect: func(j *JoystickAdaptor) (err error) {
sdl.Init(sdl.INIT_JOYSTICK)
if sdl.NumJoysticks() > 0 {
j.joystick = sdl.JoystickOpen(0)
return
}
return errors.New("No joystick available")
},
}
}
开发者ID:nathany,项目名称:gobot,代码行数:14,代码来源:joystick_adaptor.go
示例10: 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)
}
}
开发者ID:emlai,项目名称:go-sdl2,代码行数:50,代码来源:opengl.go
示例11: initSDL
func initSDL() *sdl.Window {
sdl.Init(sdl.INIT_EVERYTHING)
window, err := sdl.CreateWindow("Game of Life",
sdl.WINDOWPOS_UNDEFINED,
sdl.WINDOWPOS_UNDEFINED,
1280, 720,
sdl.WINDOW_OPENGL)
if err != nil {
panic(err)
}
return window
}
开发者ID:FSX,项目名称:nanovg,代码行数:14,代码来源:window.go
示例12: Init
func (engine *GameEngine) Init(name string) {
sdl.Init(sdl.INIT_EVERYTHING)
ttf.Init()
engine.window = sdl.CreateWindow(name, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 800, 600, sdl.WINDOW_SHOWN)
engine.renderer = sdl.CreateRenderer(engine.window, -1, sdl.RENDERER_ACCELERATED|sdl.RENDERER_PRESENTVSYNC)
engine.Input = &InputHandler{}
engine.Assets = &AssetsManager{}
engine.Input.Init()
engine.Assets.Init(engine)
engine.Running = true
engine.states = NewStack()
}
开发者ID:kageurufu,项目名称:platformr,代码行数:15,代码来源:engine.go
示例13: 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
示例14: sdlInit
func sdlInit() {
sdl.Init(sdl.INIT_EVERYTHING)
// init the image subsystem
imgFlags := img.INIT_PNG | img.INIT_JPG
if imgFlags != img.Init(imgFlags) {
panic(fmt.Sprintf("Error initializing img: %v\n", img.GetError()))
}
// init the TTF subsystem
if err := ttf.Init(); err != nil {
panic(fmt.Sprintf("Error initializing ttf: %v\n", err))
}
}
开发者ID:beejjorgensen,项目名称:eggdrop,代码行数:16,代码来源:main.go
示例15: main
func main() {
if len(os.Args) < 2 {
fmt.Println("usage: emuChip8 <game>")
os.Exit(1)
}
sdl.Init(sdl.INIT_EVERYTHING)
window, err := sdl.CreateWindow("Chip8", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
WIN_WIDTH, WIN_HEIGHT, sdl.WINDOW_SHOWN)
if err != nil {
panic(err)
}
defer window.Destroy()
surface, err := window.GetSurface()
if err != nil {
panic(err)
}
chip := new(Chip8)
chip.surface = surface
chip.init()
chip.loadGame(os.Args[1])
chip.quit = false
for !chip.quit {
if err := chip.emulateCycle(); err != nil {
fmt.Println(err)
}
if chip.drawFlag {
chip.drawGraphics()
window.UpdateSurface()
chip.drawFlag = false
}
chip.setKeys()
sdl.Delay(1)
}
chip.cleanup()
}
开发者ID:PeBraz,项目名称:Chip.emul8ter,代码行数:47,代码来源:chip8.go
示例16: Init
// Init is used for a starting procedure of the game which will do things
// such as creating the SDL Window, creating the SDL Renderer, Start the Scene, etc.
func Init(title string, x, y, width, height int, fullscreen bool) {
var flags uint32
if fullscreen {
flags = sdl.WINDOW_FULLSCREEN
}
err := sdl.Init(sdl.INIT_EVERYTHING)
if err != nil {
log.Fatalln("Game // Error whie initialising SDL")
log.Panic(err)
}
log.Println("Game // SDL Initialised")
win, err := sdl.CreateWindow(title, x, y, width, height, flags)
if err != nil {
log.Fatalln("Game // Error while creating window")
log.Panic(err)
}
log.Println("Game // Created Window")
ren, err := sdl.CreateRenderer(win, -1, 0)
if err != nil {
log.Fatalln("Game // Error while creating renderer")
log.Panic(err)
}
ren.SetDrawColor(255, 255, 255, 255)
log.Println("Game // Created Renderer")
log.Println("Game // Init Success")
window = win
renderer = ren
input.InitJoystick()
running = true
currentScene.Enter()
}
开发者ID:yukiisbored,项目名称:Kaori,代码行数:49,代码来源:game.go
示例17: init
func (d *Display) init() (err error) {
err = sdl.Init(sdl.INIT_VIDEO)
if err != nil {
return err
}
d.window, err = sdl.CreateWindow("anna", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 1400, 500, sdl.WINDOW_SHOWN)
if err != nil {
return err
}
d.renderer, err = sdl.CreateRenderer(d.window, -1, sdl.RENDERER_ACCELERATED)
if err != nil {
return err
}
return nil
}
开发者ID:kierdavis,项目名称:anna,代码行数:18,代码来源:display.go
示例18: 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)
}
开发者ID:emlai,项目名称:go-sdl2,代码行数:18,代码来源:audio.go
示例19: 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()
}
开发者ID:gophercoders,项目名称:pong,代码行数:42,代码来源:pong.go
示例20: GetJs
func GetJs() (*sdl.Joystick, error) {
sdl.Init(sdl.INIT_JOYSTICK)
numJs := sdl.NumJoysticks()
if numJs == 0 {
return nil, errors.New("Joystick missing.")
}
jsIdx := -1
for i := 0; i < numJs; i++ {
if sdl.JoystickNameForIndex(i) == "T.Flight Hotas X" {
jsIdx = i
break
}
}
if jsIdx == -1 {
return nil, errors.New("Unsuported joystick!")
}
return sdl.JoystickOpen(jsIdx), nil
}
开发者ID:vjeko,项目名称:godrone,代码行数:21,代码来源:joystick.go
注:本文中的github.com/veandco/go-sdl2/sdl.Init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论