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


Golang sdl.GL_SwapBuffers函數代碼示例

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


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

示例1: Run

func (s *Sim) Run() {
	for s.ui.running {

		start := time.Now()

		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch ev := e.(type) {
			case *sdl.QuitEvent:
				s.ui.running = false
			case *sdl.KeyboardEvent:
				if ev.Keysym.Sym == sdl.K_ESCAPE {
					s.ui.running = false
				} else if ev.Keysym.Sym == sdl.K_SPACE {
					if !s.running {
						s.running = true
						go s.Update()
					}
				}
			}
		}

		s.Draw()

		sdl.GL_SwapBuffers()

		fps := 1 / (float64(time.Since(start)) / float64(time.Second))
		_ = fps
		//fmt.Printf("%f\n", fps)
	}
}
開發者ID:erikmuttersbach,項目名稱:PotentialFieldGL,代碼行數:30,代碼來源:simulator.go

示例2: Process

func (self *MCPlayAppState) Process(time_step float32) {
	glutils.Clear()

	self.gameState.Physics.Process(time_step)

	self.gameState.UpdatePlayerCtrl(
		self.moveDir.Mul(0.2), v.Angle(self.Controller.HorAxis))

	self.gameState.ObjectManager.Process(time_step)

	self.Controller.Pos = self.gameState.Player.Position

	self.Controller.SetupCamera()

	self.gameState.VoxelsMesh.SetCenter(
		self.Controller.Pos)

	self.gameState.VoxelsMesh.Render(self.Camera,
		self.shader,
		self.bindFunc)

	self.gameState.ObjectManager.ForAllObjects(func(ob *wobject.WObject) {
		if ob.RendererModule != nil {
			ob.RendererModule.Render()
		}
	})

	sdl.GL_SwapBuffers()

	if self.frameStats.FrameFinished(int64(time_step * 1000)) {
		fmt.Printf("%v\n", &self.frameStats)
	}
}
開發者ID:pzsz,項目名稱:mold,代碼行數:33,代碼來源:appstate.go

示例3: gameOverScreen

func gameOverScreen(
	screen *sdl.Surface,
	score string,
	bg *glh.Texture,
	font *gltext.Font) bool {

	for {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.ResizeEvent:
				resize(screen, e.(*sdl.ResizeEvent))
			case *sdl.QuitEvent:
				return true
			case *sdl.MouseButtonEvent:
				return false
			}
		}
		renderBackground(screen, bg)
		font.Printf(110, 50, "Game Over")
		font.Printf(110, 100, "Your score: "+score)
		font.Printf(110, 150, "Click to play again")
		sdl.GL_SwapBuffers()
		time.Sleep((1 / 30) * time.Second)
	}
	return false
}
開發者ID:Tohie,項目名稱:GoFlappyBird,代碼行數:27,代碼來源:flappybird.go

示例4: drawGLScene

// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Move left 1.5 units and into the screen 6.0 units.
	gl.LoadIdentity()
	gl.Translatef(-1.5, 0.0, -6.0)
	gl.Rotatef(float32(rtri), 0.0, 1.0, 0.0) // Rotate the triangle on the Y axis

	gl.Begin(gl.TRIANGLES)       // Draw triangles
	gl.Color3f(1.0, 0.0, 0.0)    // Set The Color To Red
	gl.Vertex3f(0.0, 1.0, 0.0)   // top
	gl.Color3f(0.0, 1.0, 0.0)    // Set The Color To Red
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.Color3f(0.0, 0.0, 1.0)    // Set The Color To Red
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.End()                     // finish drawing the triangle

	// Move right 3 units
	gl.LoadIdentity()
	gl.Translatef(1.5, 0.0, -6.0)
	gl.Color3f(0.5, 0.5, 1.0)                 // Set The Color To Blue One Time Only
	gl.Rotatef(float32(rquad), 1.0, 0.0, 0.0) // rotate the quad on the X axis

	gl.Begin(gl.QUADS)           // draw quads
	gl.Vertex3f(-1.0, 1.0, 0.0)  // top left
	gl.Vertex3f(1.0, 1.0, 0.0)   // top right
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.End()                     // done drawing the quad

	// Draw to the screen
	sdl.GL_SwapBuffers()

	rtri += 0.2   // Increase The Rotation Variable For The Triangle
	rquad -= 0.15 // Decrease The Rotation Variable For The Quad

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
開發者ID:navneet1v,項目名稱:opengl-go-tutorials,代碼行數:49,代碼來源:lesson04.go

示例5: playGame

func playGame(screen *sdl.Surface, bg *glh.Texture, font *gltext.Font) (int, bool) {
	movingUp := false
	b := bird.NewBird(240, 380)
	score := 0
	var pipes []*pipe.Pipe
	ticker := 0
	for {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		quit := manageEvents(screen, &movingUp)
		if quit {
			return score, true
		}

		renderBackground(screen, bg)
		ticker++
		if ticker > 100 {
			pipes = append(pipes, pipe.NewPipe(int(screen.W), int(screen.H)))
			ticker = 0
		}

		if movingUp {
			b.MoveUp()
		} else {
			b.MoveDown()
		}

		for _, p := range pipes {
			if p.X < 0 {
				p.Destroy()
				pipes = pipes[1:]
			}
			if p.CollidesWith(b.X, b.Y, b.Width, b.Height) {
				return score, false
			}
			if p.GonePast(b.X, b.Y) {
				score++
			}
			p.Tick()
			p.Render()
		}
		b.Render()

		font.Printf(240, 50, strconv.Itoa(score))
		screen.Flip()
		time.Sleep((1 / 30) * time.Second)
		sdl.GL_SwapBuffers()
	}
}
開發者ID:Tohie,項目名稱:GoFlappyBird,代碼行數:48,代碼來源:flappybird.go

示例6: drawScene

func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.LoadIdentity()

	gl.Translatef(0, 0, -20+globalState.MousePos.Z*globalState.speed)

	gl.Rotatef(globalState.Rot.X, 1, 0, 0)
	gl.Rotatef(globalState.Rot.Y, 0, 1, 0)
	gl.Rotatef(globalState.Rot.Z, 0, 0, 1)

	if globalState.speed != 1 {
		gl.Scalef(globalState.speed, globalState.speed, globalState.speed)
	}

	gl.RenderMode(gl.RENDER)

	gl.Begin(gl.QUADS)
	for i, _ := range mesh.Faces {
		if colors, ok := faceColor[i]; ok {
			gl.Color3f(colors[0], colors[1], colors[2])
		} else {
			faceColor[i] = make([]float32, 3)
			faceColor[i][0] = rand.Float32()
			faceColor[i][1] = rand.Float32()
			faceColor[i][2] = rand.Float32()
			gl.Color3f(faceColor[i][0], faceColor[i][1], faceColor[i][2])
		}

		face := &mesh.Faces[i]
		for j, _ := range face.Vertices {
			var v *wfobj.Vertex
			if len(face.Normals) > 0 {
				v = &face.Normals[j]
				gl.Normal3f(v.X, v.Y, v.Z)
			}
			v = &face.Vertices[j]
			gl.Vertex3f(v.X, v.Y, v.Z)
		}
	}
	gl.End()
	gl.Finish()
	gl.Flush()

	sdl.GL_SwapBuffers()
}
開發者ID:andrebq,項目名稱:wfobj,代碼行數:46,代碼來源:main.go

示例7: drawGLScene

// Here goes our drawing code
func drawGLScene(sector Sector) {
	xtrans := gl.GLfloat(-xpos)
	ztrans := gl.GLfloat(-zpos)
	ytrans := gl.GLfloat(-walkbias - 0.25)
	scenroty := gl.GLfloat(360.0 - yrot)

	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// reset the view
	gl.LoadIdentity()

	// Rotate up and down to look up and down
	gl.Rotatef(float32(lookupdown), 1.0, 0.0, 0.0)
	// Rotate depending on direction player is facing
	gl.Rotatef(float32(scenroty), 0.0, 1.0, 0.0)
	// translate the scene based on player position
	gl.Translatef(float32(xtrans), float32(ytrans), float32(ztrans))

	gl.BindTexture(gl.TEXTURE_2D, uint(textures[filter]))

	for _, vertices := range sector {
		gl.Begin(gl.TRIANGLES)
		for _, triangle := range *vertices {
			gl.Normal3f(0.0, 0.0, 1.0)
			gl.TexCoord2f(float32(triangle.u), float32(triangle.v))
			gl.Vertex3f(float32(triangle.x), float32(triangle.y), float32(triangle.z))
		}
		gl.End()
	}

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
開發者ID:navneet1v,項目名稱:opengl-go-tutorials,代碼行數:46,代碼來源:lesson10.go

示例8: draw

// general draw function
func draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) // CARGOCULT
	gl.PushMatrix()                                     // CARGOCULT
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)
	gl.Translated(0.0, 0.0, view_z)

	for i := range boxes {
		gl.PushMatrix() // CARGOCULT
		gl.CallList(boxes[i])
		gl.PopMatrix() // CARGOCULT
	}

	gl.PopMatrix() // CARGOCULT

	sdl.GL_SwapBuffers() // CARGOCULT
}
開發者ID:pietdaniel,項目名稱:gl_maze,代碼行數:19,代碼來源:main.go

示例9: draw

func draw() {

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.PushMatrix()
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)

	gl.PushMatrix()
	gl.Translated(-3.0, -2.0, 0.0)
	gl.Rotated(angle, 0.0, 0.0, 1.0)
	gl.CallList(gear1)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(3.1, -2.0, 0.0)
	gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0)
	gl.CallList(gear2)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(-3.1, 4.2, 0.0)
	gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0)
	gl.CallList(gear3)
	gl.PopMatrix()

	gl.PopMatrix()

	sdl.GL_SwapBuffers()

	Frames++
	{
		t := sdl.GetTicks()
		if t-T0 >= 5000 {
			seconds := (t - T0) / 1000.0
			fps := Frames / seconds
			print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
開發者ID:jayschwa,項目名稱:examples,代碼行數:43,代碼來源:main.go

示例10: drawGLScene

// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// reset the view
	gl.LoadIdentity()

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
開發者ID:navneet1v,項目名稱:opengl-go-tutorials,代碼行數:22,代碼來源:lesson01.go

示例11: main

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
}
開發者ID:Tohie,項目名稱:GoFlappyBird,代碼行數:40,代碼來源:flappybird.go

示例12: drawGLScene

// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Move left 1.5 units and into the screen 6.0 units.
	gl.LoadIdentity()
	gl.Translatef(-1.5, 0.0, -6.0)

	gl.Begin(gl.TRIANGLES)       // Draw triangles
	gl.Vertex3f(0.0, 1.0, 0.0)   // top
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.End()                     // finish drawing the triangle

	// Move right 3 units
	gl.Translatef(3.0, 0.0, 0.0)

	gl.Begin(gl.QUADS)           // draw quads
	gl.Vertex3f(-1.0, 1.0, 0.0)  // top left
	gl.Vertex3f(1.0, 1.0, 0.0)   // top right
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.End()                     // done drawing the quad

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
開發者ID:shogg,項目名稱:opengl-go-tutorials,代碼行數:39,代碼來源:lesson02.go

示例13: mainLoop

func mainLoop() {
	done := false
	for !done {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.QuitEvent:
				done = true
				break
			case *sdl.KeyboardEvent:
				keyEvent := e.(*sdl.KeyboardEvent)
				if keyEvent.Type == sdl.KEYDOWN {
					done = handleKey(keyEvent)
				}
			}
		}

		updateShaderParams()
		draw()
		drawOverlay()
		sdl.GL_SwapBuffers()
		checkShaders()
	}
}
開發者ID:shogg,項目名稱:glvox,代碼行數:23,代碼來源:main.go

示例14: mainLoop

func mainLoop() {
	done := false
	for !done {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.QuitEvent:
				done = true
				break
			case *sdl.KeyboardEvent:
				key := e.(*sdl.KeyboardEvent).Keysym.Sym
				if key == sdl.K_RETURN {
					done = true
					break
				} else {
					handleKey(key)
				}
			}
		}

		draw()
		drawOverlay()
		sdl.GL_SwapBuffers()
	}
}
開發者ID:shogg,項目名稱:gltoy,代碼行數:24,代碼來源:gltoy.go

示例15: 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
	for running {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.MouseButtonEvent:
				mbe := e.(*sdl.MouseButtonEvent)
				if mbe.Type == sdl.MOUSEBUTTONDOWN {
					dndDragging = true
					sdl.GetMouseState(&dndStart.X, &dndStart.Y)
					dndEnd = dndStart
				} else {
					dndDragging = false
					sdl.GetMouseState(&dndEnd.X, &dndEnd.Y)
					if mbe.Which == 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.MouseMotionEvent:
				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)
		tex.Unbind(gl.TEXTURE_2D)
		if dndDragging {
			drawSelection(dndStart, dndEnd)
		}
		drawProgress(512, 512, lastProgress, rc.Pending)
		sdl.GL_SwapBuffers()
	}
}
開發者ID:jayschwa,項目名稱:examples,代碼行數:90,代碼來源:main.go


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