func newLCD(width, height int) *lcd { window, err := sdl.CreateWindow("Game Boy", sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, width, height, sdl.WINDOW_SHOWN) if err != nil { log.Fatal(err) } windowSurface, err := window.GetSurface() if err != nil { window.Destroy() log.Fatal(err) } surface, err := sdl.CreateRGBSurface(0, lcdWidth, lcdHeight, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000) if err != nil { window.Destroy() log.Fatal(err) } return &lcd{window, windowSurface, surface, []byte{}, [lcdWidth * lcdHeight]uint8{}, width, height} }
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 }
//Init interface method func (sw *Switcher) Init() WidgetSettings { sw.Selected = 0 app := sw.App window := sw.App.Window sw.Clients = GetClients() fontSize = 14 w := 500 h := (fontSize + 12) * len(sw.Clients) window, err := sdl.CreateWindow("Shadow", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, w, h, sdl.WINDOW_SHOWN) if err != nil { panic(err) } app.Window = window icons = map[string][]string{} icons["vivaldi-snapshot"] = []string{"\uf27d", "red"} icons["Skype"] = []string{"\uf17e", ACCENT} icons["konsole"] = []string{"\uf120", "default"} icons["Thunderbird"] = []string{"\uf0e0", "default"} icons["Atom"] = []string{"\ue7ba", "default"} icons["yakyak"] = []string{"\uf086", GREEN} return WidgetSettings{fontSize, Geometry{int32(w), int32(h)}, Padding{10, 10, 10}} }
/* 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 }
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), } }
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() }
// 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 }
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 }
func Init() *MissionControl { mc := new(MissionControl) var err error // Create a new window with a default size mc.sdl_window, err = sdl.CreateWindow("Mission Control", sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, 640, 480, sdl.WINDOW_SHOWN) if err != nil { fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", err) os.Exit(1) } // Set window to fullscreen var disp_rect sdl.Rect sdl.GetDisplayBounds(mc.Display, &disp_rect) mc.sdl_window.SetPosition(int(disp_rect.X), int(disp_rect.Y)) mc.sdl_window.SetSize(int(disp_rect.W), int(disp_rect.H)) mc.sdl_window.SetFullscreen(sdl.WINDOW_FULLSCREEN) mc.renderer, err = sdl.CreateRenderer(mc.sdl_window, -1, sdl.RENDERER_ACCELERATED) if err != nil { fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", err) os.Exit(2) } mc.renderer.Clear() mc.SetBackgroundColor(0, 0, 0, 255) return mc }
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) } }
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() }
func main() { rom, err := LoadROM(os.Args[1]) if err != nil { panic(err) } frameDelay := 1000 / frameRate window := sdl.CreateWindow( "Go NES", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 256, 240, sdl.WINDOW_SHOWN, ) if window == nil { panic(sdl.GetError()) } defer window.Destroy() controller := NewController() ppu := NewPPU(window, NewVRAM(rom.Mapper())) cpu := NewCPU(NewMMU(rom.Mapper(), ppu, controller), ppu) ticksPerFrame := uint32(341 * 262) for { expectedTicks := sdl.GetTicks() + frameDelay for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event := event.(type) { case *sdl.KeyDownEvent: controller.SetKeyState(event.Keysym.Sym, true) case *sdl.KeyUpEvent: controller.SetKeyState(event.Keysym.Sym, false) case *sdl.QuitEvent: return } } ppuTicks := uint32(0) for ppuTicks < ticksPerFrame { ppuTicks += ppu.Tick(cpu.Tick()) } actualTicks := sdl.GetTicks() if actualTicks < expectedTicks { sdl.Delay(expectedTicks - actualTicks) } } }
func NewRenderer(title string, width, height, players int, update_duration time.Duration) (rv *SDLRenderer, err error) { return rv, exec(func() error { window, err := sdl.CreateWindow(title, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, width, height, sdl.WINDOW_SHOWN) if err != nil { rv = nil return err } data, err := assets.Asset("final/Fixedsys500c.ttf") if err != nil { window.Destroy() rv = nil return err } mem := sdl.RWFromMem(unsafe.Pointer(&data[0]), len(data)) font, err := ttf.OpenFontRW(mem, 0, 128) if err != nil { window.Destroy() rv = nil return err } frames := int(frameRate * update_duration / time.Second) images, player_rotations, err := loadImages(frames, players) if err != nil { window.Destroy() font.Close() rv = nil return err } sounds, err := loadSounds() if err != nil { cleanupImages(images) cleanupRotations(player_rotations) window.Destroy() font.Close() rv = nil return err } var frame_time time.Duration if frames > 0 { frame_time = update_duration / time.Duration(frames) } rv = &SDLRenderer{Title: title, window: window, font: font, images: images, sounds: sounds, frame_time: frame_time, frames: frames, player_rotations: player_rotations, closed: false} return nil }) }
func run() int { var window *sdl.Window var renderer *sdl.Renderer var points []sdl.Point var rect sdl.Rect var rects []sdl.Rect 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() renderer.Clear() 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) return 0 }
func CreateWindow(width, height int, title string) (*Window, error) { var g Window var err error g.win, err = sdl.CreateWindow(title, sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, width, height, 0) if err != nil { return nil, err } g.rend, err = sdl.CreateRenderer(g.win, -1, 0) return &g, err }
func (w *Window) createWindow() { var err error w.Window, err = sdl.CreateWindow(w.Title, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, int(w.Width), int(w.Height), sdl.WINDOW_OPENGL) if err != nil { panic(err) } }
// Create the graphics window using the SDl library or crash trying func createWindow(w, h int) *sdl.Window { var window *sdl.Window var err error window, err = sdl.CreateWindow("Pong Game", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, w, h, sdl.WINDOW_SHOWN) if err != nil { panic(err) } return window }
func createWindow(title string, width int, height int) *sdl.Window { window, err := sdl.CreateWindow( title, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, width, height, sdl.WINDOW_SHOWN) if err != nil { panic(fmt.Sprintf("Failed to create window: %s\n", err)) } return window }
func createWindow(title string, height int, width int) *sdl.Window { window, err := sdl.CreateWindow(title, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, width, height, sdl.WINDOW_SHOWN) if err != nil { log.Println("Failed to create window, exiting") os.Exit(1) } return window }
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 }
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() }
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 }
//Init interface method func (tn *TNotifier) Init() WidgetSettings { app := tn.App window := tn.App.Window fontSize = 14 w := 500 h := (fontSize + 10) * 13 window, err := sdl.CreateWindow("Shadow", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, w, h, sdl.WINDOW_SHOWN) if err != nil { panic(err) } app.Window = window return WidgetSettings{fontSize, Geometry{int32(w), int32(h)}, Padding{10, 30, 10}} }
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) } }
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 }
func run() int { var window *sdl.Window var renderer *sdl.Renderer 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 := img.Load(imageName) if err != nil { fmt.Fprintf(os.Stderr, "Failed to load PNG: %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.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) return 0 }
//Init interface method func (N *Notifier) Init() WidgetSettings { app := N.App window := N.App.Window fontSize = 14 w := 200 h := (fontSize + 10) * 5 window, err := sdl.CreateWindow("Shadow", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, w, h, sdl.WINDOW_SHOWN) if err != nil { panic(err) } window.SetPosition(1720, 0) app.Window = window return WidgetSettings{fontSize, Geometry{int32(w), int32(h)}, Padding{10, 30, 10}} }
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() }
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() }
func main() { window, err := sdl.CreateWindow("Monster Path", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 640, 480, sdl.WINDOW_SHOWN) if err != nil { os.Exit(1) } defer window.Destroy() renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED) if err != nil { os.Exit(2) } defer renderer.Destroy() var event sdl.Event running := true myGrid := grid.New(17, 12) setupMap(myGrid) gunner.location, _ = myGrid.RoomAt(15, 7) alien.location, _ = myGrid.RoomAt(1, 1) graph := graph.NewFromGrid(myGrid) path := graph.Path(gunner.location, alien.location) for running { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event.(type) { case *sdl.QuitEvent: running = false } } renderer.SetDrawColor(205, 201, 201, 255) renderer.Clear() renderer.SetDrawColor(10, 10, 10, 255) Draw(renderer, myGrid) DrawGraph(renderer, graph) renderer.SetDrawColor(200, 0, 0, 255) DrawPath(renderer, path) renderer.SetDrawColor(0, 100, 0, 255) alien.Draw(renderer) gunner.Draw(renderer) renderer.Present() } }