本文整理汇总了Golang中github.com/0xe2-0x9a-0x9b/Go-SDL/sdl.SetVideoMode函数的典型用法代码示例。如果您正苦于以下问题:Golang SetVideoMode函数的具体用法?Golang SetVideoMode怎么用?Golang SetVideoMode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetVideoMode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Draw_Init
func Draw_Init() {
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
fmt.Println(sdl.GetError())
}
//screen = sdl.SetVideoMode(sw, sh, 32, sdl.OPENGL)
screen = sdl.SetVideoMode(sw, sh, 32, sdl.RESIZABLE)
if screen == nil {
return
}
var video_info = sdl.GetVideoInfo()
fmt.Println("HW_available = ", video_info.HW_available)
fmt.Println("WM_available = ", video_info.WM_available)
fmt.Println("Video_mem = ", video_info.Video_mem, "kiB")
surface = sdl.CreateRGBSurface(sdl.HWSURFACE, 500, 500, 32, rmask,
gmask, bmask, amask)
surface.FillRect(nil, 0xff00ff00)
surfaceb = sdl.CreateRGBSurface(sdl.HWSURFACE, 500, 500, 32, rmask,
gmask, bmask, amask)
surfaceb.FillRect(nil, 0xffff0000)
}
开发者ID:MerlijnWajer,项目名称:Gollision,代码行数:26,代码来源:draw.go
示例2: initTest
func initTest() {
if sdl.Init(sdl.INIT_VIDEO) != 0 {
panic(sdl.GetError())
}
if ttf.Init() != 0 {
panic(sdl.GetError())
}
font = ttf.OpenFont("../testdata/VeraMono.ttf", 12)
if font == nil {
panic(sdl.GetError())
}
appSurface = sdl.SetVideoMode(appSurfaceW, appSurfaceH, 32, 0)
gopher = sdl.Load("../testdata/gopher.jpg")
sdlrenderer := clingon.NewSDLRenderer(sdl.CreateRGBSurface(sdl.SRCALPHA, int(consoleW), int(consoleH), 32, 0, 0, 0, 0), font)
sdlrenderer.GetSurface().SetAlpha(sdl.SRCALPHA, 0xaa)
newRenderingLoop(sdlrenderer)
console = clingon.NewConsole(&Echoer{})
console.SetRenderer(sdlrenderer)
console.Print("Welcome to the CLIngon shell!\n\n")
}
开发者ID:remogatto,项目名称:clingon,代码行数:27,代码来源:specs.go
示例3: main
func main() {
if sdl.Init(sdl.INIT_VIDEO) != 0 {
panic(sdl.GetError())
}
defer sdl.Quit()
screen := sdl.SetVideoMode(400, 300, 32, 0)
if screen == nil {
panic(sdl.GetError())
}
sdl.WM_SetCaption("Template", "")
ticker := time.NewTicker(1e9 / 2 /*2 Hz*/)
loop:
for {
select {
case <-ticker.C:
// Note: For better efficiency, use UpdateRects instead of Flip
screen.FillRect(nil /*color*/, rand.Uint32())
//screen.Blit(&sdl.Rect{x,y, 0, 0}, image, nil)
screen.Flip()
case event := <-sdl.Events:
fmt.Printf("%#v\n", event)
switch event.(type) {
case sdl.QuitEvent:
break loop
}
}
}
}
开发者ID:Chownie,项目名称:-LPC--Farm-Sim,代码行数:35,代码来源:main.go
示例4: newSDL2xScreen
func newSDL2xScreen(fullScreen bool) *sdl2xScreen {
sdlMode := uint32(sdl.SWSURFACE)
if fullScreen {
application.Logf("%s", "Activate fullscreen mode")
sdlMode = sdl.FULLSCREEN
sdl.ShowCursor(sdl.DISABLE)
}
screenSurface := &sdlSurface{sdl.SetVideoMode(SCREEN_WIDTH*2, SCREEN_HEIGHT*2, 32, sdlMode)}
if screenSurface.surface == nil {
log.Printf("%s", sdl.GetError())
application.Exit()
return nil
}
borderSurface := &sdlSurface{sdl.CreateRGBSurface(sdl.SWSURFACE, SCREEN_WIDTH*2, SCREEN_HEIGHT*2, 32, 0, 0, 0, 0)}
if borderSurface.surface == nil {
log.Printf("%s", sdl.GetError())
application.Exit()
return nil
}
displaySurface := &sdlSurface{sdl.CreateRGBSurface(sdl.SWSURFACE, DISPLAY_WIDTH*2, DISPLAY_HEIGHT*2, 32, 0, 0, 0, 0)}
if displaySurface.surface == nil {
log.Printf("%s", sdl.GetError())
application.Exit()
return nil
}
return &sdl2xScreen{screenSurface, borderSurface, displaySurface}
}
开发者ID:cocoa-alex,项目名称:sms,代码行数:27,代码来源:sdl.go
示例5: initSDL
func initSDL() {
if sdl.Init(sdl.INIT_VIDEO) != 0 {
panic(sdl.GetError())
}
if ttf.Init() != 0 {
panic(sdl.GetError())
}
font := ttf.OpenFont("testdata/VeraMono.ttf", 20)
if font == nil {
panic(sdl.GetError())
}
appSurface = sdl.SetVideoMode(640, 480, 32, 0)
sdlrenderer = NewSDLRenderer(sdl.CreateRGBSurface(sdl.SRCALPHA, 640, 480, 32, 0, 0, 0, 0), font)
sdlrenderer.GetSurface().SetAlpha(sdl.SRCALPHA, 0xaa)
console = NewConsole(nil)
go func() {
for {
select {
case rects := <-sdlrenderer.UpdatedRectsCh():
render(rects)
}
}
}()
render(nil)
}
开发者ID:robert-dale-schell,项目名称:clingon,代码行数:32,代码来源:sdlrenderer_benchmark_test.go
示例6: main
func main() {
if sdl.Init(sdl.INIT_VIDEO) < 0 {
fmt.Printf(
"Video initialization failed: %s\n",
sdl.GetError())
quit_tutorial(1)
}
info := sdl.GetVideoInfo()
if info == nil {
fmt.Printf(
"Video query failed: %s\n",
sdl.GetError())
quit_tutorial(1)
}
width := 640
height := 480
bpp := int(info.Vfmt.BitsPerPixel)
sdl.GL_SetAttribute(sdl.GL_RED_SIZE, 5)
sdl.GL_SetAttribute(sdl.GL_GREEN_SIZE, 5)
sdl.GL_SetAttribute(sdl.GL_BLUE_SIZE, 5)
sdl.GL_SetAttribute(sdl.GL_DEPTH_SIZE, 16)
sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
flags := uint32(sdl.OPENGL | sdl.FULLSCREEN)
if sdl.SetVideoMode(width, height, bpp, flags) == nil {
fmt.Printf("Video mode set failed: %s\n", sdl.GetError())
quit_tutorial(1)
}
setup_opengl(width, height)
for {
process_events()
draw_screen()
}
os.Exit(0)
}
开发者ID:glenn-brown,项目名称:aima,代码行数:34,代码来源:sdldoc.go
示例7: main
func main() {
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
panic(sdl.GetError())
}
defer sdl.Quit()
screen := sdl.SetVideoMode(640, 480, 32, sdl.SWSURFACE)
if screen == nil {
panic(sdl.GetError())
}
sdl.WM_SetCaption("Hello World", "test.png")
message := load_image("hello.bmp")
background := load_image("background.bmp")
apply_surface(0, 0, background, screen)
apply_surface(320, 0, background, screen)
apply_surface(0, 240, background, screen)
apply_surface(320, 240, background, screen)
apply_surface(180, 140, message, screen)
message.Free()
background.Free()
screen.Flip()
sdl.Delay(2000)
}
开发者ID:pakohan,项目名称:sdl-tutorial,代码行数:31,代码来源:main.go
示例8: sdlInit
func sdlInit(width, height int32) *sdl.Surface {
var surface = sdl.SetVideoMode(int(width), int(height), 32, sdl.RESIZABLE)
if surface == nil {
panic(sdl.GetError())
}
return surface
}
开发者ID:radekp,项目名称:alfi,代码行数:9,代码来源:main.go
示例9: 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")
}
}
开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:10,代码来源:basicgl.go
示例10: initialize
// Initialization boilerplate
func initialize(config *configuration) *renderer {
var bgImage, appSurface *sdl.Surface
if sdl.Init(sdl.INIT_VIDEO) != 0 {
panic(sdl.GetError())
}
if ttf.Init() != 0 {
panic(sdl.GetError())
}
font := ttf.OpenFont(flag.Arg(0), 12)
if font == nil {
panic(sdl.GetError())
}
sdl.EnableUNICODE(1)
if config.fullscreen {
flags := sdl.FULLSCREEN
appSurface = sdl.SetVideoMode(640, 480, 32, uint32(flags))
sdl.ShowCursor(sdl.DISABLE)
} else {
appSurface = sdl.SetVideoMode(640, 480, 32, 0)
}
if config.bgImage != "" {
bgImage = sdl.Load(config.bgImage)
}
sdlrenderer = clingon.NewSDLRenderer(sdl.CreateRGBSurface(sdl.SRCALPHA, int(config.consoleW), int(config.consoleH), 32, 0, 0, 0, 0), font)
sdlrenderer.GetSurface().SetAlpha(sdl.SRCALPHA, 0xaa)
return &renderer{
config: config,
appSurface: appSurface,
sdlRenderer: sdlrenderer,
bgImageSurface: bgImage,
}
}
开发者ID:remogatto,项目名称:clingon,代码行数:41,代码来源:shell.go
示例11: main
func main() {
sdl.Init(sdl.INIT_VIDEO)
sdl.SetVideoMode(800, 600, 32, sdl.OPENGL)
gl.Init()
gl.Enable(gl.DEPTH_TEST)
gl.Viewport(0, 0, 800, 600)
tick := time.Tick(time.Second / 50)
timer := 0.0
posbuf := gl.NewBuffer(gl.ARRAY_BUFFER, Vertices, gl.STATIC_DRAW)
prog, err := gl.MakeProgram([]string{vertexShader}, []string{fragmentShader})
if err != nil {
fmt.Println(err)
return
}
f, err := os.Open("glenda.png")
if err != nil {
fmt.Println(err)
return
}
img, _, err := image.Decode(f)
if err != nil {
fmt.Println(err)
return
}
tex := gl.NewTexture2D(img, 0)
for {
select {
case ev := <-sdl.Events:
if _, ok := ev.(sdl.QuitEvent); ok {
return
}
case <-tick:
gl.ClearColor(0, 0, 0, 1)
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
prog.Use()
mat := gl.Mul4(gl.Frustum(45, 800./600, 0.01, 100), gl.Translate(0, 0, -8), gl.RotX(timer), gl.RotY(2*timer), gl.RotZ(3*timer))
prog.EnableAttrib("position", posbuf, 0, 3, 5, false)
prog.EnableAttrib("texcoord", posbuf, 3, 2, 5, false)
prog.SetUniform("tex", 0)
prog.SetUniform("matrix", mat)
tex.Enable(0, gl.TEXTURE_2D)
gl.DrawArrays(gl.TRIANGLE_STRIP, 0, len(Vertices)/5)
prog.DisableAttrib("position")
prog.Unuse()
sdl.GL_SwapBuffers()
timer += 1
}
}
}
开发者ID:uriel,项目名称:gl,代码行数:51,代码来源:cube.go
示例12: Init
func (v *Video) Init(t <-chan []int, d <-chan []int, n string) {
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
log.Fatal(sdl.GetError())
}
v.screen = sdl.SetVideoMode(512, 480, 32, 0)
if v.screen == nil {
log.Fatal(sdl.GetError())
}
sdl.WM_SetCaption(fmt.Sprintf("Fergulator - %s", n), "")
v.tick = t
v.debug = d
}
开发者ID:samnardoni,项目名称:Fergulator,代码行数:16,代码来源:video.go
示例13: main
func main() {
iWidth := int32(WIDTH)
iHeight := int32(HEIGHT)
var screen = sdl.SetVideoMode(int(iWidth), int(iHeight), 32, sdl.RESIZABLE)
if screen == nil {
log.Fatal(sdl.GetError())
}
iIterationNr := 0
iIterations := int(math.Min(float64(333333), float64((WIDTH)*(HEIGHT))))
iStartNS := time.Now().UnixNano()
//mainloop:
for {
var iX int32
var iY int32
var iColor uint32
for i := 0; i < iIterations; i++ {
iX = rand.Int31() % (iWidth)
iY = rand.Int31() % (iHeight)
iColor = rand.Uint32()
iColor &= 0x00ffffff
iColor += 0x88000000
draw_point(iX, iY, iColor, screen)
//break mainloop;
}
screen.Flip()
iIterationNr++
if iIterationNr%99 == 0 {
iIterationNS := time.Now().UnixNano()
iDeltaNS := iIterationNS - iStartNS
nDeltaS := float64(iDeltaNS) / float64(1000000000)
nFPS := float64(iIterationNr) / nDeltaS
fmt.Printf("fps: %v\n", nFPS)
fmt.Printf("%v x %v\n", screen.W, screen.H)
}
}
base.Dump("")
}
开发者ID:ramanamaharshi,项目名称:my_go_stuff,代码行数:47,代码来源:main.go
示例14: StartGraphics
func StartGraphics(id uint32, update chan *State, move chan MoveMsg, quit chan bool) error {
var err error
rc := sdl.Init(sdl.INIT_VIDEO)
if rc == -1 {
return errors.New(sdl.GetError())
}
disp := sdl.SetVideoMode(800, 600, 32, sdl.OPENGL)
if disp == nil {
return errors.New(sdl.GetError())
}
winscale = gl.Mul4(gl.Translate(-1, 1, 0), gl.Scale(1./400, -1./300, 1))
gl.Init()
gl.ClearColor(1, 1, 1, 1)
s := new(State)
ls := time.Now()
quadBuf = gl.NewBuffer(gl.ARRAY_BUFFER, quadData, gl.STATIC_DRAW)
prog, err = gl.MakeProgram([]string{vertexShader}, []string{fragmentShader})
if err != nil {
log.Fatal(err)
}
AddTex("glenda", "glenda.png")
AddTex("tux", "tux.png")
i := image.NewRGBA(image.Rect(0, 0, 800, 600))
texs["black"] = gl.NewTexture2D(i, 0)
tick := time.Tick(time.Second / 50)
squit := make(chan bool)
go ProcessInput(move, quit, squit)
for {
select {
case s = <-update:
ls = time.Now()
case <-tick:
s.Advance(time.Now().Sub(ls))
ls = time.Now()
gl.Clear(gl.COLOR_BUFFER_BIT)
RenderScene(s)
sdl.GL_SwapBuffers()
case <-squit:
return nil
}
}
return nil
}
开发者ID:aiju,项目名称:killer-rabbit,代码行数:45,代码来源:graphics.go
示例15: newSDLUnscaledScreen
func newSDLUnscaledScreen() *sdlUnscaledScreen {
screenSurface := &sdlSurface{sdl.SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, sdl.SWSURFACE)}
if screenSurface.surface == nil {
log.Printf("%s", sdl.GetError())
application.Exit()
return nil
}
borderSurface := &sdlSurface{sdl.CreateRGBSurface(sdl.SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, 32, 0, 0, 0, 0)}
if borderSurface.surface == nil {
log.Printf("%s", sdl.GetError())
application.Exit()
return nil
}
displaySurface := &sdlSurface{sdl.CreateRGBSurface(sdl.SWSURFACE, DISPLAY_WIDTH, DISPLAY_HEIGHT, 32, 0, 0, 0, 0)}
if displaySurface.surface == nil {
log.Printf("%s", sdl.GetError())
application.Exit()
return nil
}
return &sdlUnscaledScreen{screenSurface, borderSurface, displaySurface}
}
开发者ID:cocoa-alex,项目名称:sms,代码行数:21,代码来源:sdl.go
示例16: main
func main() {
runtime.LockOSThread()
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
log.Fatal(sdl.GetError())
}
var screen = sdl.SetVideoMode(screenWidth, screenHeight, 32, sdl.OPENGL|sdl.HWSURFACE|sdl.GL_DOUBLEBUFFER|sdl.FULLSCREEN)
if screen == nil {
log.Fatal(sdl.GetError())
}
sdl.WM_SetCaption("Lecture Hall Games", "")
sdl.EnableUNICODE(1)
if gl.Init() != 0 {
log.Fatal("could not initialize OpenGL")
}
gl.Viewport(0, 0, int(screen.W), int(screen.H))
gl.ClearColor(1, 1, 1, 0)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, float64(screen.W), float64(screen.H), 0, -1.0, 1.0)
gl.Disable(gl.LIGHTING)
gl.Disable(gl.DEPTH_TEST)
gl.TexEnvi(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
if mixer.OpenAudio(mixer.DEFAULT_FREQUENCY, mixer.DEFAULT_FORMAT,
mixer.DEFAULT_CHANNELS, 4096) != 0 {
log.Fatal(sdl.GetError())
}
if ttf.Init() != 0 {
log.Fatal(sdl.GetError())
}
if p, err := build.Default.Import(basePkg, "", build.FindOnly); err == nil {
os.Chdir(p.Dir)
}
var err error
rand.Seed(time.Now().UnixNano())
levelDir := fmt.Sprintf("data/levels/demolevel%d", 3+rand.Intn(numberLevels))
//carsDir := fmt.Sprintf(" data/cars/car%d/", 1+rand.Intn(numberCars))
if game, err = NewRacer(levelDir); err != nil {
log.Fatal(err)
}
go func() {
listen, err := net.Listen("tcp", ":8001")
if err != nil {
log.Fatal(err)
}
for {
conn, err := listen.Accept()
if err != nil {
log.Println(err)
continue
}
go handleConnection(conn)
}
}()
running := true
last := time.Now()
for running {
select {
case event := <-sdl.Events:
switch e := event.(type) {
case sdl.QuitEvent:
running = false
case sdl.ResizeEvent:
screen = sdl.SetVideoMode(int(e.W), int(e.H), 32, sdl.RESIZABLE)
case sdl.KeyboardEvent:
if e.Type == sdl.KEYDOWN {
if e.Keysym.Sym == sdl.K_ESCAPE {
running = false
} else {
game.KeyPressed(e.Keysym)
}
}
}
default:
}
current := time.Now()
t := current.Sub(last)
last = current
mu.Lock()
game.Update(t)
game.Render(screen)
mu.Unlock()
sdl.GL_SwapBuffers()
}
sdl.Quit()
}
开发者ID:mfpi,项目名称:lecture-hall-games,代码行数:98,代码来源:main.go
示例17: main
func main() {
runtime.LockOSThread()
flag.Parse()
sdl.Init(sdl.INIT_VIDEO)
defer sdl.Quit()
sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)
if sdl.SetVideoMode(640, 480, 32, sdl.OPENGL) == nil {
panic("sdl error")
}
sdl.WM_SetCaption("Gotris", "Gotris")
sdl.EnableKeyRepeat(250, 45)
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Viewport(0, 0, 640, 480)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, 640, 480, 0, -1, 1)
gl.ClearColor(0, 0, 0, 0)
//-----------------------------------------------------------------------------
font, err := LoadFontFromFile("dejavu.font")
if err != nil {
panic(err)
}
rand.Seed(int64(sdl.GetTicks()))
gs := NewGameSession(*initLevel, font)
lastTime := sdl.GetTicks()
ticker := time.NewTicker(10 * time.Millisecond)
stop := make(chan byte, 1)
go func() {
for {
switch e := (<-sdl.Events).(type) {
case sdl.QuitEvent:
stop <- 0
case sdl.KeyboardEvent:
if e.Type == sdl.KEYDOWN {
running := gs.HandleKey(e.Keysym.Sym)
if !running {
stop <- 0
}
gs.update <- 0
}
}
}
}()
loop:
for {
select {
case <-ticker.C:
gs.update <- 0
case <-gs.update:
now := sdl.GetTicks()
delta := now - lastTime
lastTime = now
gs.Update(delta)
gl.Clear(gl.COLOR_BUFFER_BIT)
font.Draw(5, 5, fmt.Sprintf("Level: %d | Score: %d", gs.Level, gs.Score))
gs.Draw()
gl.Color3ub(255, 255, 255)
sdl.GL_SwapBuffers()
case <-stop:
break loop
}
}
}
开发者ID:nsf,项目名称:gotris,代码行数:79,代码来源:gotris.go
示例18: main
func main() {
log.SetFlags(0)
var resourcePath string
{
GOPATH := os.Getenv("GOPATH")
if GOPATH == "" {
log.Fatal("No such environment variable: GOPATH")
}
for _, gopath := range strings.Split(GOPATH, ":") {
a := gopath + "/src/github.com/0xe2-0x9a-0x9b/Go-SDL/sdl-test"
_, err := os.Stat(a)
if err == nil {
resourcePath = a
break
}
}
if resourcePath == "" {
log.Fatal("Failed to find resource directory")
}
}
var joy *sdl.Joystick
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
log.Fatal(sdl.GetError())
}
if ttf.Init() != 0 {
log.Fatal(sdl.GetError())
}
if sdl.NumJoysticks() > 0 {
// Open joystick
joy = sdl.JoystickOpen(0)
if joy != nil {
println("Opened Joystick 0")
println("Name: ", sdl.JoystickName(0))
println("Number of Axes: ", joy.NumAxes())
println("Number of Buttons: ", joy.NumButtons())
println("Number of Balls: ", joy.NumBalls())
} else {
println("Couldn't open Joystick!")
}
}
if mixer.OpenAudio(mixer.DEFAULT_FREQUENCY, mixer.DEFAULT_FORMAT,
mixer.DEFAULT_CHANNELS, 4096) != 0 {
log.Fatal(sdl.GetError())
}
var screen = sdl.SetVideoMode(640, 480, 32, sdl.RESIZABLE)
if screen == nil {
log.Fatal(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(resourcePath + "/test.png")
if image == nil {
log.Fatal(sdl.GetError())
}
sdl.WM_SetIcon(image, nil)
running := true
font := ttf.OpenFont(resourcePath+"/Fontin Sans.otf", 72)
if font == nil {
log.Fatal(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(resourcePath + "/test.ogg")
sound := mixer.LoadWAV(resourcePath + "/sound.ogg")
if music == nil || sound == nil {
log.Fatal(sdl.GetError())
}
music.PlayMusic(-1)
if sdl.GetKeyName(270) != "[+]" {
log.Fatal("GetKeyName broken")
}
worm_in := make(chan Point)
//.........这里部分代码省略.........
开发者ID:scottferg,项目名称:Go-SDL,代码行数:101,代码来源:test.go
示例19: main
func main() {
var p Playfield = NewPlayfield(StandardWidth, StandardHeight)
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
panic(sdl.GetError())
}
var screen = sdl.SetVideoMode(p.width*PixPerBrick,
p.height*PixPerBrick, 32, sdl.RESIZABLE)
if screen == nil {
panic(sdl.GetError())
}
//var video_info = sdl.GetVideoInfo()
sdl.EnableUNICODE(1)
sdl.WM_SetCaption("YATI:Go", "")
dropTicker := time.NewTicker(time.Second / 2.0)
var curPiece *Piece = nil
score := 0
mainloop:
for {
select {
case <-dropTicker.C:
if curPiece == nil {
curPiece = makeNewTet()
curPiece.pos.x = p.width/2 - 2
if !curPiece.move(&p, 0, 0) {
fmt.Println("Failed placement test")
break mainloop
}
} else {
// advance piece
if !curPiece.move(&p, 0, 1) {
p.place(curPiece)
// remove lines
score += p.removeCompletedLines()
fmt.Println(score)
timeDiv := 2.0 + float64(score/10)/4.0
duration := float64(time.Second) / timeDiv
dropTicker = time.NewTicker(time.Duration(duration))
curPiece = nil
}
}
case _event := <-sdl.Events:
switch e := _event.(type) {
case sdl.QuitEvent:
break mainloop
case sdl.KeyboardEvent:
//key := sdl.GetKeyName(sdl.Key(e.Keysym.Sym))
//println(e.Keysym.Sym, ": ", sdl.GetKeyName(sdl.Key(e.Keysym.Sym)))
if e.Type == sdl.KEYDOWN {
switch e.Keysym.Sym {
case sdl.K_ESCAPE:
break mainloop
case sdl.K_w:
curPiece.rotate(&p, -1)
case sdl.K_a:
curPiece.move(&p, -1, 0)
case sdl.K_d:
curPiece.move(&p, 1, 0)
case sdl.K_s:
//curPiece.rotate(&p,1)
fallthrough
case sdl.K_SPACE:
// turn on drop mode
dropTicker = time.NewTicker(time.Second / 60.0)
}
}
}
}
p.render(screen)
curPiece.render(screen)
screen.Flip()
}
//fmt.Println("----")
//p.removeLine(5)
//p.print()
}
开发者ID:phooky,项目名称:golang,代码行数:84,代码来源:tetris.go
示例20: main
func main() {
sdl.Init(sdl.INIT_VIDEO)
screen = sdl.SetVideoMode(300, 300, 16, sdl.OPENGL|sdl.RESIZABLE)
if !screen {
fprintf(stderr, "Couldn't set 300x300 GL video mode: %s\n", sdl.GetError())
sdl.Quit()
exit(2)
}
sdl.WM_SetCaption("Gears", "gears")
init(argc, argv)
reshape(screen.w, screen.h)
done := false
for !done {
var event sdl.Event
idle()
for sdl.PollEvent(&event) {
switch event.Type {
case sdl.VIDEORESIZE:
screen = sdl.SetVideoMode(event.resize.w, event.resize.h, 16,
sdl.OPENGL|sdl.RESIZABLE)
if screen {
reshape(screen.w, screen.h)
} else {
/* Uh oh, we couldn't set the new video mode?? */
}
break
case sdl.QUIT:
done = true
break
}
}
keys = sdl.GetKeyState(NULL)
if keys[SDLK_ESCAPE] {
done = true
}
if keys[SDLK_UP] {
view_rotx += 5.0
}
if keys[SDLK_DOWN] {
view_rotx -= 5.0
}
if keys[SDLK_LEFT] {
view_roty += 5.0
}
if keys[SDLK_RIGHT] {
view_roty -= 5.0
}
if keys[SDLK_z] {
if sdl.GetModState() & KMOD_SHIFT {
view_rotz -= 5.0
} else {
view_rotz += 5.0
}
}
draw()
}
sdl.Quit()
return 0 /* ANSI C requires main to return int. */
}
开发者ID:glenn-brown,项目名称:aima,代码行数:66,代码来源:sdlgears.go
注:本文中的github.com/0xe2-0x9a-0x9b/Go-SDL/sdl.SetVideoMode函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论