func (self *AppStateManager) Setup(state AppState, caption string) { if *FLAG_profile { pfile, _ := os.Create("gowar.prof") pprof.StartCPUProfile(pfile) } // Lock, so we got no GL-in-wrong-thread foolery sdl.Init(sdl.INIT_VIDEO) self.Screen = sdl.SetVideoMode(800, 600, 32, sdl.OPENGL|sdl.RESIZABLE) gl.Init() if self.Screen == nil { sdl.Quit() panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n") } sdl.WM_SetCaption(caption, caption) Setup() GetViewport().SetScreenSize(float32(self.Screen.W), float32(self.Screen.H)) self.Push(state) }
func initScreen() { sdl.Init(sdl.INIT_VIDEO) const ( resx int = 640 resy int = 480 ) var ( screen = sdl.SetVideoMode(resx, resy, 16, sdl.OPENGL) ) if screen == nil { sdl.Quit() panic("Couldn't set GL video mode: " + sdl.GetError() + "\n") } if gl.Init() != 0 { panic("gl error") } gl.MatrixMode(gl.PROJECTION) //gl.MatrixMode(gl.MODELVIEW) gl.Viewport(0, 0, int(screen.W), int(screen.H)) gl.LoadIdentity() gl.Ortho(0, float64(screen.W), float64(screen.H), 0, -1.0, 1.0) //gl.DepthRange(-1, 1) gl.ClearColor(0, 0, 0, 0) gl.Clear(gl.COLOR_BUFFER_BIT) }
func main() { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic(sdl.GetError()) } defer sdl.Quit() screen := sdl.SetVideoMode(640, 480, 32, 0) if screen == nil { panic(sdl.GetError()) } sdl.WM_SetCaption("Ohai", "") sdl.EnableKeyRepeat(20, 20) fmt.Println("Launching mainloop") loadTextures() loadLevel() gameloop(screen) }
// Wrap the SDL into one single thread func (s SdlWrap) wrap() { runtime.LockOSThread() if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic("Unable to init SDL. Cause: " + sdl.GetError()) } sdl.EnableUNICODE(1) s.InitDone <- struct{}{} for { select { case t := <-s.Title: sdl.WM_SetCaption(t, t) case <-s.Quit: close(s.Events) sdl.Quit() case sz := <-s.Size: s.Surface <- sdl.SetVideoMode(int(sz.X), int(sz.Y), 32, sdl.HWSURFACE|sdl.DOUBLEBUF|sdl.RESIZABLE) default: e := sdl.PollEvent() if e != nil { s.Events <- e } } } }
// Runs everything, calling the methods required to get the game // running, runs the main loop, and then cleanly exits. func (g *game) run() (err error) { err = g.load() if err != nil { return } defer g.quit() if sdl.Init(sdl.INIT_EVERYTHING) < 0 { return errors.New(sdl.GetError()) } defer sdl.Quit() g.screen = sdl.SetVideoMode(640, 480, 32, sdl.DOUBLEBUF) if g.screen == nil { return errors.New(sdl.GetError()) } sdl.WM_SetCaption(WinCap, "") err = g.main() if err != nil { return } return }
func main() { sdl.Init(sdl.INIT_VIDEO) fmt.Printf("fullscreen modes:\n") listModes(sdl.FULLSCREEN) }
func main() { if sdl.Init(sdl.INIT_VIDEO) < 0 { panic("Video initialization failed: " + sdl.GetError()) } if sdl.EnableKeyRepeat(100, 25) != 0 { panic("Setting keyboard repeat failed: " + sdl.GetError()) } videoFlags := sdl.OPENGL // Enable OpenGL in SDL videoFlags |= sdl.DOUBLEBUF // Enable double buffering videoFlags |= sdl.HWPALETTE // Store the palette in hardware // FIXME: this causes segfault. // videoFlags |= sdl.RESIZABLE // Enable window resizing surface = sdl.SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, uint32(videoFlags)) if surface == nil { panic("Video mode set failed: " + sdl.GetError()) } sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1) initGL() resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT) SetupWorld("data/world.txt") // wait for events running := true isActive := true for running { for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() { switch e := ev.(type) { case *sdl.ActiveEvent: isActive = e.Gain != 0 case *sdl.ResizeEvent: width, height := int(e.W), int(e.H) surface = sdl.SetVideoMode(width, height, SCREEN_BPP, uint32(videoFlags)) if surface == nil { fmt.Println("Could not get a surface after resize:", sdl.GetError()) Quit(1) } resizeWindow(width, height) case *sdl.KeyboardEvent: if e.Type == sdl.KEYDOWN { handleKeyPress(e.Keysym) } case *sdl.QuitEvent: running = false } } // draw the scene if isActive { drawGLScene(sector1) } } }
func sdlSetup() (world *World) { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic(sdl.GetError()) } sdl.EnableUNICODE(1) sdl.EnableKeyRepeat(25, 25) return }
// Creates / Initializes the sound system. func NewSound() (s *Sound, err error) { sdl.Init(sdl.INIT_AUDIO) if mixer.OpenAudio(mixer.DEFAULT_FREQUENCY, mixer.DEFAULT_FORMAT, mixer.DEFAULT_CHANNELS, 4096) != 0 { err = fmt.Errorf(sdl.GetError()) return } s = &Sound{} return }
func Play() { sdl.Init(sdl.INIT_AUDIO) if mixer.OpenAudio(mixer.DEFAULT_FREQUENCY, mixer.DEFAULT_FORMAT, mixer.DEFAULT_CHANNELS, 4096) != 0 { panic(sdl.GetError()) } var m = mixer.LoadMUS("data/track.ogg") if m == nil { panic(sdl.GetError()) } m.PlayMusic(-1) }
func init() { sdl.Init(sdl.INIT_VIDEO) screen := sdl.SetVideoMode(320, 200, 32, sdl.OPENGL) if screen == nil { panic("Couldn't set video mode: " + sdl.GetError() + "\n") } if err := gl.Init(); err != 0 { panic("glInit error") } }
func initinc() error { if initnum == 0 { errn := sdl.Init(sdl.INIT_VIDEO) if errn < 0 { return errors.New(sdl.GetError()) } } initnum++ return nil }
func main() { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic(sdl.GetError()) } if ttf.Init() != 0 { panic(sdl.GetError()) } var screen = sdl.SetVideoMode(1400, 300, 32, 0) var video_info = sdl.GetVideoInfo() println("HW_available = ", video_info.HW_available) println("WM_available = ", video_info.WM_available) println("Video_mem = ", video_info.Video_mem, "kb") sdl.EnableUNICODE(1) font := ttf.OpenFont("euler.otf", 24) if font == nil { panic(sdl.GetError()) } black := sdl.Color{0, 0, 0, 0} text := ttf.RenderUTF8_Blended(font, "!!", black) fmt.Println(text.Bounds()) sdl.WM_SetCaption("Go-SDL SDL Test", "") running := true num := NewNumberShower("b+c", "", "euler.otf", 24, 0) denom := NewNumberShower("a", "", "euler.otf", 24, 0) testy := NewFractionShower(num, denom, "euler.otf", 24, 0) testy.CursorPosition = 3 testy.RenderEmptyIndextxt = true str := "" for running { switch e := sdl.PollEvent().(type) { case *sdl.QuitEvent: running = false break case *sdl.KeyboardEvent: if e.State == 1 { str = handlekeypress2(e.Keysym, str) fmt.Println("rendering string", str) text = ttf.RenderUTF8_Blended(font, str, black) } } screen.FillRect(nil, 0xFFFFFF) screen.Blit(&sdl.Rect{23, 0, 0, 0}, testy.Render(), nil) screen.Flip() sdl.Delay(5) } }
func NewScreen(w, h int) *Screen { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { log.Fatal("failed to init sdl", sdl.GetError()) return nil } if ttf.Init() != 0 { log.Fatal("failed to init ttf", sdl.GetError()) return nil } var ctx Screen if err := ctx.setSurface(w, h); err != nil { log.Fatal(err) } var vInfo = sdl.GetVideoInfo() log.Println("HW_available = ", vInfo.HW_available) log.Println("WM_available = ", vInfo.WM_available) log.Println("Video_mem = ", vInfo.Video_mem, "kb") /* title := "Subtitle Player" */ title := os.Args[0] icon := "" // path/to/icon sdl.WM_SetCaption(title, icon) sdl.EnableUNICODE(1) ctx.fps = opt.fps err := ctx.setFont(opt.fontPath, opt.fontSize) if err != nil { log.Fatal("failed to set default font") return nil } ctx.debugFont = ttf.OpenFont(DFLT_FONT_PATH, 20) if ctx.debugFont == nil { errMsg := fmt.Sprintf("failed to open debug font: %s", sdl.GetError()) /* return errors.New(errMsg) */ log.Fatal(errMsg) } ctx.debugLineHeight = uint16(ctx.debugFont.LineSkip()) ctx.updateC = make(chan int) return &ctx }
func main() { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic(sdl.GetError()) } defer sdl.Quit() println("unpause with space or p") println("while paused you can place cells with the three mouse buttons") rand.Seed(time.Now().UnixNano()) Screen = NewSurface(Width*Scale, Height*Scale) Setup() HandleEvents() }
func main() { globalState.Mouse = make(map[int]bool) flag.Parse() var err error if sdl.Init(sdl.INIT_VIDEO) != 0 { log.Printf("Unable to init SDL") return } if len(flag.Args()) == 0 { old := flag.Usage flag.Usage = func() { old() fmt.Fprintf(os.Stderr, "You MUST pass the name of the file to view\n") } flag.Usage() return } mesh, err = wfobj.LoadMeshFromFile(flag.Args()[0]) if err != nil { flag.Usage() fmt.Fprintf(os.Stderr, "[e] %v\n", err) return } defer sdl.Quit() screen := sdl.SetVideoMode(1024, 600, 32, sdl.OPENGL|sdl.RESIZABLE) if screen == nil { log.Printf("Unable to init sdl Screen") } sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1) initGL() sdl.WM_SetCaption("sdlviewer", "sdlviewer") running = true for running { handleInput() drawScene() } }
func main() { sdl.Init(sdl.INIT_VIDEO) defer sdl.Quit() screen := sdl.SetVideoMode(width, height, 32, sdl.OPENGL) if screen == nil { panic("Couldn't set video mode: " + sdl.GetError() + "\n") } if err := gl.Init(); err != 0 { panic("gl error") } initGl() initShaders() mainLoop() }
func sdlSetup() { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic(sdl.GetError()) } Screen = &Surface{sdl.SetVideoMode(Width, Height, 32, 0)} if Screen == nil { panic(sdl.GetError()) } if sdl.EnableKeyRepeat(25, 25) != 0 { panic(sdl.GetError()) } if ttf.Init() != 0 { panic(sdl.GetError()) } }
func InitUI() *UI { ui := &UI{ running: false, } if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic(sdl.GetError()) } if ttf.Init() != 0 { panic(sdl.GetError()) } ui.screen = sdl.SetVideoMode(300, 300, 32, sdl.OPENGL) if ui.screen == nil { panic("sdl error") } if gl.Init() != 0 { panic("gl error") } gl.MatrixMode(gl.PROJECTION) gl.Viewport(0, 0, int(ui.screen.W), int(ui.screen.H)) gl.LoadIdentity() gl.Ortho(0, float64(ui.screen.W), float64(ui.screen.H), 0, -1.0, 1.0) gl.ClearColor(1, 1, 1, 0) gl.Clear(gl.COLOR_BUFFER_BIT) // TTF sdl.EnableUNICODE(1) ui.font = ttf.OpenFont("FontinSans.otf", 20) ui.font.SetStyle(ttf.STYLE_UNDERLINE) if ui.font == nil { panic(sdl.GetError()) } ui.running = true return ui }
func main() { var done bool sdl.Init(sdl.INIT_VIDEO) var screen = sdl.SetVideoMode(300, 300, 18, sdl.OPENGL|sdl.RESIZABLE) if screen == nil { sdl.Quit() panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n") } gl.Init() //if gl.Init() != nil { //panic("gl error") //} init_() reshape(int32(screen.W), int32(screen.H)) done = false for !done { for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() { switch e.(type) { case *sdl.ResizeEvent: re := e.(*sdl.ResizeEvent) screen = sdl.SetVideoMode(int(re.W), int(re.H), 16, sdl.OPENGL|sdl.RESIZABLE) if screen != nil { reshape(int32(screen.W), int32(screen.H)) } else { panic("we couldn't set the new video mode??") } break case *sdl.QuitEvent: done = true break } } done = key_handler() draw() } sdl.Quit() return }
func main() { sdl.Init(sdl.INIT_VIDEO) ttf.Init() screen := sdl.SetVideoMode(480, 560, 16, sdl.OPENGL|sdl.RESIZABLE) sdl.WM_SetCaption("Flappy Bird", "") bg := utils.TextureFromFile("./bg.png") font := utils.LoadFont("/usr/share/fonts/truetype/DroidSans.ttf", 32) reshape(int(screen.W), int(screen.H)) renderBackground(screen, bg) font.Printf(110, 50, "Click to play") sdl.GL_SwapBuffers() for { OuterLoop: for { e := sdl.WaitEvent() switch e.(type) { case *sdl.MouseButtonEvent: if e.(*sdl.MouseButtonEvent).Type == sdl.MOUSEBUTTONUP { break OuterLoop } } } score, quit := playGame(screen, bg, font) if quit { break } quit = gameOverScreen(screen, strconv.Itoa(score), bg, font) if quit { break } } screen.Free() ttf.Quit() sdl.Quit() return }
func main() { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic(sdl.GetError()) } // The actual resolution (screenspace) W := 800 H := 600 // The virtual resolution (worldspace) MAXX := 400 MAXY := 300 screen := sdl.SetVideoMode(W, H, 32, sdl.FULLSCREEN) if screen == nil { panic(sdl.GetError()) } sdl.EnableUNICODE(1) sdl.ShowCursor(0) sdl.WM_SetCaption("Random Lines", "") red := sdl.Color{255, 0, 0, 255} color := red rand.Seed(time.Now().UnixNano()) for { color = sdl.Color{uint8(rand.Intn(255)), uint8(rand.Intn(255)), uint8(rand.Intn(255)), 255} DoublePixelLine(screen, rand.Intn(MAXX), rand.Intn(MAXY), rand.Intn(MAXX), rand.Intn(MAXY), color) if escPressed() { break } screen.Flip() sdl.PollEvent() //sdl.Delay(10) } sdl.Quit() }
func DisplayImage(src image.Image) { // Initialise SDL log.Println("Initialising SDL.") sdl.Init(sdl.INIT_VIDEO) defer sdl.Quit() // Transform the image into an SDL surface. log.Println("Transforming image into SDL surface.") var buf bytes.Buffer png.Encode(&buf, src) sdlRW := sdl.RWFromReader(&buf) sdlSurf := sdl.Load_RW(sdlRW, false) // Set the display up. log.Println("Setting up screen.") sdlScreen := sdl.SetVideoMode(int(sdlSurf.W), int(sdlSurf.H), 32, sdl.SWSURFACE) sdlScreen.Blit(nil, sdlSurf, nil) // Loop until exit. log.Println("Displaying image.") loop(sdlScreen) }
func ui_main() { if sdl.Init(sdl.INIT_VIDEO) != 0 { panic(sdl.GetError()) } if screen == nil { panic(sdl.GetError()) } sdl.EnableUNICODE(1) sdl.WM_SetCaption("Go-SDL SDL Test", "") running := true for running { for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() { switch e := ev.(type) { case *sdl.QuitEvent: running = false break case *sdl.ResizeEvent: println("resize screen ", e.W, e.H) screen = sdl.SetVideoMode(int(e.W), int(e.H), 32, sdl.RESIZABLE) if screen == nil { panic(sdl.GetError()) } } } } ttf.Quit() sdl.Quit() }
func main() { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { panic(sdl.GetError()) } defer sdl.Quit() var screen = sdl.SetVideoMode(640, 480, 32, 0) if screen == nil { panic(sdl.GetError()) } sdl.WM_SetCaption("Template", "") for true { e := &sdl.Event{} for e.Poll() { switch e.Type { case sdl.QUIT: return default: } } screen.FillRect(nil, 0x000000) //screen.Blit(&sdl.Rect{x,y, 0, 0}, image, nil) screen.Flip() sdl.Delay(25) } }
func main() { sdl.Init(sdl.INIT_VIDEO) defer sdl.Quit() screen := sdl.SetVideoMode(width, height, 32, sdl.OPENGL) if screen == nil { panic("Couldn't set video mode: " + sdl.GetError() + "\n") } sdl.EnableKeyRepeat(200, 20) if err := gl.Init(); err != 0 { panic("gl error") } cam.Yaw(3.14) initGl() initShaders() initVoxels() mainLoop() }
func initGraphic(w, h uint, fullscreen bool) error { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { return errors.New(sdl.GetError()) } var vmFlags uint32 if fullscreen { vmFlags = sdl.FULLSCREEN } bg = sdl.SetVideoMode(int(w), int(h), 32, vmFlags) if bg == nil { return errors.New(sdl.GetError()) } sdl.WM_SetCaption("whac-a-gopher", "") // Load images gopherEye = loadImage("gopher_doteye.png") gopherEyeX = loadImage("gopher_xeye.png") gopherBody = loadImage("gopher_body_normal.png") return nil }
func Open(w, h int, fullscreen bool, title, tabname string) *Window { if GWindow != nil { panic("only one Window is allowed") } win := &Window{width: w, height: h, title: title, tabname: tabname} GWindow = win sdl.Init(sdl.INIT_EVERYTHING) gl.Init() var screen = sdl.SetVideoMode(win.width, win.height, 16, sdl.OPENGL) if screen == nil { sdl.Quit() panic("Couldn't set sdl GL video mode: " + sdl.GetError() + "\n") } sdl.WM_SetCaption(win.title, win.tabname) win.initGL() win.pixelData = make([]uint8, win.width*win.height*4) return win }
func main() { // Initialize SDL if sdl.Init(sdl.INIT_VIDEO) < 0 { panic("Video initialization failed: " + sdl.GetError()) } // To avoid cramps sdl.EnableKeyRepeat(250, 25) // Sets up OpenGL double buffering sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1) // flags to pass to sdl.SetVideoMode videoFlags := sdl.OPENGL // Enable OpenGL in SDL videoFlags |= sdl.DOUBLEBUF // Enable double buffering videoFlags |= sdl.HWPALETTE // Store the palette in hardware // FIXME: this causes segfault. // videoFlags |= sdl.RESIZABLE // Enable window resizing // get a SDL surface surface = sdl.SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, uint32(videoFlags)) // verify there is a surface if surface == nil { panic("Video mode set failed: " + sdl.GetError()) Quit(1) } // When this function is finished, clean up and exit. defer Quit(0) LoadGLTextures("data/glass.bmp") // Initialize OpenGL initGL() // Resize the initial window resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT) // wait for events running := true isActive := true for running { for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() { switch e := ev.(type) { case *sdl.ActiveEvent: isActive = e.Gain != 0 case *sdl.ResizeEvent: width, height := int(e.W), int(e.H) surface = sdl.SetVideoMode(width, height, SCREEN_BPP, uint32(videoFlags)) if surface == nil { fmt.Println("Could not get a surface after resize:", sdl.GetError()) Quit(1) } resizeWindow(width, height) case *sdl.KeyboardEvent: if e.Type == sdl.KEYDOWN { handleKeyPress(e.Keysym) } case *sdl.QuitEvent: running = false } } // draw the scene if isActive { drawGLScene() } } }
func main() { flag.Parse() var done bool var keys []uint8 sdl.Init(sdl.INIT_VIDEO) var screen = sdl.SetVideoMode(300, 300, 16, sdl.OPENGL|sdl.RESIZABLE) if screen == nil { sdl.Quit() panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n") } if gl.Init() != 0 { panic("gl error") } sdl.WM_SetCaption("Gears", "gears") init_() reshape(int(screen.W), int(screen.H)) done = false for !done { idle() for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() { switch e.(type) { case *sdl.ResizeEvent: re := e.(*sdl.ResizeEvent) screen = sdl.SetVideoMode(int(re.W), int(re.H), 16, sdl.OPENGL|sdl.RESIZABLE) if screen != nil { reshape(int(screen.W), int(screen.H)) } else { panic("we couldn't set the new video mode??") } break case *sdl.QuitEvent: done = true break } } keys = sdl.GetKeyState() if keys[sdl.K_ESCAPE] != 0 { done = true } if keys[sdl.K_UP] != 0 { view_rotx += 5.0 } if keys[sdl.K_DOWN] != 0 { view_rotx -= 5.0 } if keys[sdl.K_LEFT] != 0 { view_roty += 5.0 } if keys[sdl.K_RIGHT] != 0 { view_roty -= 5.0 } if keys[sdl.K_z] != 0 { if (sdl.GetModState() & sdl.KMOD_RSHIFT) != 0 { view_rotz -= 5.0 } else { view_rotz += 5.0 } } draw() } sdl.Quit() return }