本文整理汇总了Golang中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)
}
}
}
示例2: main
func main() {
flag.Parse()
var done bool
var keys []uint8
sdl.Init(sdl.INIT_VIDEO)
var screen = sdl.SetVideoMode(640, 480, 16, sdl.OPENGL|sdl.RESIZABLE)
if screen == nil {
sdl.Quit()
panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n")
}
sdl.WM_SetCaption("Gears", "gears")
init_()
reshape(int(screen.W), int(screen.H))
done = false
for !done {
var event sdl.Event
idle()
for event.Poll() {
switch event.Type {
case sdl.VIDEORESIZE:
screen = sdl.SetVideoMode(int(event.Resize().W), int(event.Resize().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.QUIT:
done = true
break
}
}
keys = sdl.GetKeyState()
handleKeyPress(keys)
if keys[sdl.K_ESCAPE] != 0 {
done = true
}
draw()
}
sdl.Quit()
return
}
示例3: main
//=================================
//Initialize Lortet
//=================================
func main() {
//INIT SDL
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
panic(sdl.GetError())
}
screen = sdl.SetVideoMode(SCREENWIDTH, SCREENHEIGHT, BPP, sdl.SWSURFACE)
if screen == nil {
panic(sdl.GetError())
}
sdl.WM_SetCaption("MapMaker", "")
if ttf.Init() != 0 {
panic(sdl.GetError())
}
font = ttf.OpenFont("../Fontin Sans.otf", 15)
if font == nil {
panic(sdl.GetError())
}
objects = ScreenObjects{}
//Load Media
IM = LoadImages()
MainLoop()
ExitProgram()
}
示例4: main
func main() {
sdl.Init(sdl.INIT_VIDEO)
var screen = sdl.SetVideoMode(640, 480, 32, sdl.OPENGL)
if screen == nil {
panic("sdl error")
}
if gl.Init() != 0 {
panic("glew error")
}
pen := Pen{}
gl.MatrixMode(gl.PROJECTION)
gl.Viewport(0, 0, gl.GLsizei(screen.W), gl.GLsizei(screen.H))
gl.LoadIdentity()
gl.Ortho(0, gl.GLdouble(screen.W), gl.GLdouble(screen.H), 0, -1.0, 1.0)
gl.ClearColor(1, 1, 1, 0)
gl.Clear(gl.COLOR_BUFFER_BIT)
var running = true
for running {
e := &sdl.Event{}
for e.Poll() {
switch e.Type {
case sdl.QUIT:
running = false
break
case sdl.KEYDOWN:
running = false
break
case sdl.MOUSEMOTION:
me := e.MouseMotion()
if me.State != 0 {
pen.lineTo(Point{int(me.X), int(me.Y)})
} else {
pen.moveTo(Point{int(me.X), int(me.Y)})
}
break
}
}
sdl.GL_SwapBuffers()
sdl.Delay(25)
}
sdl.Quit()
}
示例5: reinitScreen
func reinitScreen(width, height int) {
winWidth, winHeight = gl.Sizei(width), gl.Sizei(height)
if sdlScreen != nil {
sdlScreen.Free()
}
sdlScreen = sdl.SetVideoMode(width, height, 24, sdl.OPENGL|sdl.RESIZABLE)
if sdlScreen == nil {
panic("SDL video init error")
}
}
示例6: resize
func resize(width int, height int) {
screen = sdl.SetVideoMode(width, height, 32, sdl.RESIZABLE)
if screen == nil {
panic(sdl.GetError())
}
gridSizePixels := min(width, height)
cellSize = gridSizePixels / gridSize
offsetX = (width - gridSizePixels) / 2
offsetY = (height - gridSizePixels) / 2
}
示例7: main
func main() {
sdl.Init(sdl.INIT_VIDEO)
var screen = sdl.SetVideoMode(640, 480, 32, sdl.OPENGL)
if screen == nil {
panic("sdl error")
}
if gl.Init() != 0 {
panic("gl error")
}
pen := Pen{}
gl.MatrixMode(gl.PROJECTION)
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.ClearColor(1, 1, 1, 0)
gl.Clear(gl.COLOR_BUFFER_BIT)
var running = true
for running {
for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
switch ev := e.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.KeyboardEvent:
if ev.Keysym.Sym == sdl.K_ESCAPE {
running = false
}
case *sdl.MouseMotionEvent:
if ev.State != 0 {
pen.lineTo(Point{int(ev.X), int(ev.Y)})
} else {
pen.moveTo(Point{int(ev.X), int(ev.Y)})
}
}
}
sdl.GL_SwapBuffers()
sdl.Delay(25)
}
sdl.Quit()
}
示例8: SetupVideo
func SetupVideo() {
if sdl.Init(sdl.INIT_VIDEO) < 0 {
panic("Couldn't initialize sdl")
}
w := WinW
h := WinH
var screen = sdl.SetVideoMode(w, h, 32, SDL_FLAGS)
// var screen = sdl.SetVideoMode(w, h, 32, sdl.OPENGLBLIT | sdl.DOUBLEBUF | sdl.HWSURFACE)
// var screen = sdl.SetVideoMode(w, h, 32, sdl.OPENGL)
if screen == nil {
panic("sdl error")
}
if ttf.Init() != 0 {
panic("ttf init error")
}
if gl.Init() != 0 {
panic("Couldn't init gl")
}
ResizeWindow(screen.W, screen.H)
gl.ClearColor(0, 0, 0, 0)
// gl.ClearColor(1, 1, 1, 0)
gl.ClearDepth(1.0)
gl.DepthFunc(gl.LEQUAL)
gl.Enable(gl.DEPTH_TEST)
gl.ShadeModel(gl.SMOOTH)
gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
/*
if gl.Init() != 0 {
panic("glew error")
}
*/
// gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT )
// gl.Clear(gl.COLOR_BUFFER_BIT)
// initGL
// gl.Ortho(0, gl.GLdouble(screen.W), gl.GLdouble(screen.H), 0, -1.0, 1.0)
}
示例9: main
func main() {
if sdl.Init(sdl.INIT_VIDEO) != 0 {
fmt.Println(sdl.GetError())
return
}
defer sdl.Quit()
if sdl.SetVideoMode(200, 200, 32, 0) == nil {
fmt.Println(sdl.GetError())
return
}
for e := new(sdl.Event); e.Wait() && e.Type != sdl.QUIT; {
}
}
示例10: main
func main() {
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
panic(sdl.GetError())
}
var screen = sdl.SetVideoMode(640, 480, 32, 0)
if screen == nil {
panic(sdl.GetError())
}
sdl.WM_SetCaption("Template", "")
running := true
for running {
e := &sdl.Event{}
for e.Poll() {
switch e.Type {
case sdl.QUIT:
running = false
break
default:
}
}
screen.FillRect(nil, 0x000000)
//screen.Blit(&sdl.Rect{x,y, 0, 0}, image, nil)
screen.Flip()
sdl.Delay(25)
}
sdl.Quit()
}
示例11: NewWindow
func NewWindow(w, h, bpp int, flags uint32) (gui.Window, error) {
win := new(window)
err := initinc()
if err != nil {
return nil, err
}
win.screen = sdl.SetVideoMode(w, h, bpp, flags)
if win.screen == nil {
return nil, errors.New(sdl.GetError())
}
win.ec = make(chan interface{})
win.events = true
go win.eventLoop()
runtime.SetFinalizer(win, func(subwin *window) {
subwin.Close()
})
return win, nil
}
示例12: Init
func (engine *SDLEngine) Init(settings *GraphicsSettings) os.Error {
runtime.LockOSThread()
if sdl.Init(sdl.INIT_VIDEO) != 0 {
return os.NewError("unable to initialize sdl.")
}
if sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1) != 0 {
sdl.Quit()
return os.NewError("double buffering not available.")
}
engine.screen = sdl.SetVideoMode(settings.Width, settings.Height, 16, sdl.OPENGL|sdl.RESIZABLE)
if engine.screen == nil {
sdl.Quit()
return os.NewError("unable to set video mode.")
}
sdl.WM_SetCaption(settings.Caption, settings.Caption)
engine.gdevice = NewOpenGLGraphicsDevice()
return nil
}
示例13: main
func main() {
runtime.LockOSThread()
flag.Parse()
buildPalette()
sdl.Init(sdl.INIT_VIDEO)
defer sdl.Quit()
sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)
if sdl.SetVideoMode(512, 512, 32, sdl.OPENGL) == nil {
panic("sdl error")
}
if gl.Init() != 0 {
panic("gl error")
}
sdl.WM_SetCaption("Gomandel", "Gomandel")
gl.Enable(gl.TEXTURE_2D)
gl.Viewport(0, 0, 512, 512)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, 512, 512, 0, -1, 1)
gl.ClearColor(0, 0, 0, 0)
//-----------------------------------------------------------------------------
var dndDragging bool = false
var dndStart Point
var dndEnd Point
var tex gl.Texture
var tc TexCoords
var lastProgress int
initialRect := Rect{-1.5, -1.5, 3, 3}
rect := initialRect
rc := new(MandelbrotRequest)
rc.MakeRequest(512, 512, rect)
rc.WaitFor(Small, &tex, &tc)
running := true
e := new(sdl.Event)
for running {
for e.Poll() {
switch e.Type {
case sdl.QUIT:
running = false
case sdl.MOUSEBUTTONDOWN:
dndDragging = true
sdl.GetMouseState(&dndStart.X, &dndStart.Y)
dndEnd = dndStart
case sdl.MOUSEBUTTONUP:
dndDragging = false
sdl.GetMouseState(&dndEnd.X, &dndEnd.Y)
if e.MouseButton().Button == 3 {
rect = initialRect
} else {
rect = rectFromSelection(dndStart, dndEnd, 512, 512, rect)
tc = texCoordsFromSelection(dndStart, dndEnd, 512, 512, tc)
}
// make request
rc.MakeRequest(512, 512, rect)
case sdl.MOUSEMOTION:
if dndDragging {
sdl.GetMouseState(&dndEnd.X, &dndEnd.Y)
}
}
}
// if we're waiting for a result, check if it's ready
p := rc.Update(&tex, &tc)
if p != -1 {
lastProgress = p
}
gl.Clear(gl.COLOR_BUFFER_BIT)
tex.Bind(gl.TEXTURE_2D)
drawQuad(0, 0, 512, 512, tc.TX, tc.TY, tc.TX2, tc.TY2)
gl.BindTexture(gl.TEXTURE_2D, 0)
if dndDragging {
drawSelection(dndStart, dndEnd)
}
drawProgress(512, 512, lastProgress, rc.Pending)
sdl.GL_SwapBuffers()
}
}
示例14: main
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 {
//.........这里部分代码省略.........
示例15: main
func main() {
// Initialize SDL
if sdl.Init(sdl.INIT_VIDEO) < 0 {
panic("Video initialization failed: " + sdl.GetError())
}
// 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)
// Sets up OpenGL double buffering
sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
// Execute everything needed for 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()
}
}
}