當前位置: 首頁>>代碼示例>>Golang>>正文


Golang sdl.SetVideoMode函數代碼示例

本文整理匯總了Golang中github.com/banthar/Go-SDL/sdl.SetVideoMode函數的典型用法代碼示例。如果您正苦於以下問題:Golang SetVideoMode函數的具體用法?Golang SetVideoMode怎麽用?Golang SetVideoMode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了SetVideoMode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

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)
		}
	}
}
開發者ID:navneet1v,項目名稱:opengl-go-tutorials,代碼行數:58,代碼來源:lesson10.go

示例2: Setup

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)
}
開發者ID:pzsz,項目名稱:glutils,代碼行數:26,代碼來源:appstate.go

示例3: initScreen

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)
}
開發者ID:charlieb,項目名稱:gostrange,代碼行數:30,代碼來源:main.go

示例4: wrap

// 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
			}
		}
	}
}
開發者ID:andrebq,項目名稱:wde.sdl,代碼行數:28,代碼來源:init.go

示例5: main

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)
}
開發者ID:githubnemo,項目名稱:Jinx,代碼行數:25,代碼來源:main.go

示例6: run

// 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
}
開發者ID:DeedleFake,項目名稱:ggigl,代碼行數:28,代碼來源:ggigl.go

示例7: NewSurface

func NewSurface(height int, width int) (surface *sdl.Surface) {
	surface = sdl.SetVideoMode(height, width, 32, 0)
	if surface == nil {
		panic(sdl.GetError())
	}
	return
}
開發者ID:manveru,項目名稱:go.life,代碼行數:7,代碼來源:life.go

示例8: setSurface

func (c *Screen) setSurface(w, h int) error {
	log.Printf("setSurface to %dx%d", w, h)
	if opt.fullscreen {
		c.surface = sdl.SetVideoMode(w, h, 32, sdl.FULLSCREEN)
	} else {
		c.surface = sdl.SetVideoMode(w, h, 32, sdl.RESIZABLE)
	}
	if c.surface == nil {
		errMsg := fmt.Sprintf("sdl: failed to set video to %dx%d: %s",
			w, h, sdl.GetError())
		return errors.New(errMsg)
	}

	c.w, c.h = uint16(w), uint16(h)
	c.DisplayScript(c.currScript)

	return nil
}
開發者ID:suapapa,項目名稱:subtitle-raider,代碼行數:18,代碼來源:graphic.go

示例9: resize

func resize(screen *sdl.Surface, e *sdl.ResizeEvent) {
	screen = sdl.SetVideoMode(int(e.W), int(e.H), 16,
		sdl.OPENGL|sdl.RESIZABLE)
	if screen != nil {
		reshape(int(screen.W), int(screen.H))
	} else {
		panic("Couldn't set the new video mode??")
	}
}
開發者ID:Tohie,項目名稱:GoFlappyBird,代碼行數:9,代碼來源:flappybird.go

示例10: main

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
}
開發者ID:pietdaniel,項目名稱:gl_maze,代碼行數:42,代碼來源:main.go

示例11: init

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")
	}
}
開發者ID:shogg,項目名稱:gl,代碼行數:12,代碼來源:gl_test.go

示例12: main

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)
	}
}
開發者ID:Englebabz,項目名稱:CasGO,代碼行數:52,代碼來源:main.go

示例13: main

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()
	}
}
開發者ID:andrebq,項目名稱:wfobj,代碼行數:45,代碼來源:main.go

示例14: sdlSetup

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())
	}
}
開發者ID:manveru,項目名稱:raptgo,代碼行數:18,代碼來源:raptgo.go

示例15: main

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()
}
開發者ID:shogg,項目名稱:gltoy,代碼行數:18,代碼來源:gltoy.go


注:本文中的github.com/banthar/Go-SDL/sdl.SetVideoMode函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。