func writeSDLstr(newStr string) { if ttf.Init() != 0 { panic(sdl.GetError()) } var font = ttf.OpenFont("FontinSans.otf", int(fontsize)) blue := sdl.Color{185, 230, 255, 0} white := sdl.Color{255, 255, 255, 0} text0 := ttf.RenderText_Blended(font, previousStr, blue) font.SetStyle(ttf.STYLE_UNDERLINE) text1 := ttf.RenderText_Blended(font, newStr, white) introw = introw - fontsize - fontsize/2 screen.FillRect(&sdl.Rect{3, introw, uint16(winWidth - 3), uint16(fontsize + fontsize/2)}, bgcolor) screen.Blit(&sdl.Rect{3, introw, 0, 0}, text0, nil) introw = introw + fontsize + fontsize/2 screen.Blit(&sdl.Rect{3, introw, 0, 0}, text1, nil) introw = introw + fontsize + fontsize/2 if introw > (int16(winHeight) - fontsize) { introw = 0 } screen.FillRect(&sdl.Rect{3, introw, uint16(winWidth - 3), uint16(fontsize + fontsize/2)}, bgcolor) screen.Flip() previousStr = newStr }
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 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 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()) } if ttf.Init() != 0 { panic(sdl.GetError()) } if mixer.OpenAudio(mixer.DEFAULT_FREQUENCY, mixer.DEFAULT_FORMAT, mixer.DEFAULT_CHANNELS, 4096) != 0 { panic(sdl.GetError()) } var screen = sdl.SetVideoMode(640, 480, 32, sdl.RESIZABLE) if screen == nil { panic(sdl.GetError()) } 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) sdl.WM_SetCaption("Go-SDL SDL Test", "") image := sdl.Load("test.png") if image == nil { panic(sdl.GetError()) } sdl.WM_SetIcon(image, nil) running := true font := ttf.OpenFont("Fontin Sans.otf", 72) if font == nil { panic(sdl.GetError()) } font.SetStyle(ttf.STYLE_UNDERLINE) white := sdl.Color{255, 255, 255, 0} text := ttf.RenderText_Blended(font, "Test (with music)", white) music := mixer.LoadMUS("test.ogg") sound := mixer.LoadWAV("sound.ogg") if music == nil || sound == nil { panic(sdl.GetError()) } music.PlayMusic(-1) if sdl.GetKeyName(270) != "[+]" { panic("GetKeyName broken") } worm_in := make(chan Point) draw := make(chan Point, 64) var out chan Point var in chan Point out = worm_in in = out out = make(chan Point) go worm(in, out, draw) for running { for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() { switch e := ev.(type) { case *sdl.QuitEvent: running = false break case *sdl.KeyboardEvent: println("") println(e.Keysym.Sym, ": ", sdl.GetKeyName(sdl.Key(e.Keysym.Sym))) if e.Keysym.Sym == 27 { running = false } fmt.Printf("%04x ", e.Type) for i := 0; i < len(e.Pad0); i++ { fmt.Printf("%02x ", e.Pad0[i]) } println() fmt.Printf("Type: %02x Which: %02x State: %02x Pad: %02x\n", e.Type, e.Which, e.State, e.Pad0[0]) fmt.Printf("Scancode: %02x Sym: %08x Mod: %04x Unicode: %04x\n", e.Keysym.Scancode, e.Keysym.Sym, e.Keysym.Mod, e.Keysym.Unicode) case *sdl.MouseButtonEvent: if e.Type == sdl.MOUSEBUTTONDOWN { println("Click:", e.X, e.Y) in = out out = make(chan Point) go worm(in, out, draw) sound.PlayChannel(-1, 0) } 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()) } } } screen.FillRect(nil, 0x302019) screen.Blit(&sdl.Rect{0, 0, 0, 0}, text, nil) loop := true for loop { select { case p := <-draw: screen.Blit(&sdl.Rect{int16(p.x), int16(p.y), 0, 0}, image, nil) case <-out: default: loop = false } } var p Point sdl.GetMouseState(&p.x, &p.y) worm_in <- p screen.Flip() sdl.Delay(25) } image.Free() music.Free() font.Close() ttf.Quit() sdl.Quit() }
func initGame() { viewport.Zoomstd() viewport.Rotx(25) viewport.Roty(70) picker = NewPicker() sdl.Init(sdl.INIT_VIDEO) if ttf.Init() != 0 { panic("Could not initalize fonts") } sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1) screen := sdl.SetVideoMode(1024, 600, 32, sdl.OPENGL|sdl.RESIZABLE) if screen == nil { sdl.Quit() panic("Couldn't set GL video mode: " + sdl.GetError() + "\n") } if gl.Init() != 0 { panic("gl error") } sdl.WM_SetCaption("Amberfell", "amberfell") gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) // gl.ShadeModel(gl.FLAT) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.ShadeModel(gl.SMOOTH) gl.Enable(gl.LIGHTING) gl.Enable(gl.LIGHT0) gl.Enable(gl.LIGHT1) gl.Enable(gl.COLOR_MATERIAL) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.ClearDepth(1.0) // Depth Buffer Setup gl.Enable(gl.DEPTH_TEST) // Enables Depth Testing gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.FASTEST) gl.Enable(gl.TEXTURE_2D) // LoadMapTextures() LoadPlayerTextures() LoadWolfTextures() InitItems() pauseFont = NewFont("res/Jura-DemiBold.ttf", 48, color.RGBA{255, 255, 255, 0}) consoleFont = NewFont("res/Jura-DemiBold.ttf", 16, color.RGBA{255, 255, 255, 0}) inventoryItemFont = NewFont("res/Jura-DemiBold.ttf", 14, color.RGBA{240, 240, 240, 0}) textures[TEXTURE_PICKER] = loadTexture("res/dial.png") terrainTexture = loadTexture("res/tiles.png") itemsTexture = loadTexture("res/items.png") gVertexBuffer = NewVertexBuffer(10000, terrainTexture) gGuiBuffer = NewVertexBuffer(1000, terrainTexture) WolfModel = LoadModel("res/wolf.mm3d") TheWorld = NewWorld() ThePlayer = new(Player) ThePlayer.Init(0, PLAYER_START_X, PLAYER_START_Z) inventory = NewInventory() viewport.Reshape(int(screen.W), int(screen.H)) PreloadChunks(400) }