本文整理汇总了Golang中github.com/banthar/Go-SDL/sdl.GL_SwapBuffers函数的典型用法代码示例。如果您正苦于以下问题:Golang GL_SwapBuffers函数的具体用法?Golang GL_SwapBuffers怎么用?Golang GL_SwapBuffers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GL_SwapBuffers函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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(0.0, 0.0, float32(z)) // translate by z
gl.Rotatef(float32(xrot), 1.0, 0.0, 0.0) /* Rotate On The X Axis */
gl.Rotatef(float32(yrot), 0.0, 1.0, 0.0) /* Rotate On The Y Axis */
/* Select Our Texture */
gl.BindTexture(gl.TEXTURE_2D, uint(textures[filter])) // based on filter
gl.Begin(gl.QUADS)
// Front face
gl.Normal3f(0.0, 0.0, 1.0) // Normal Pointing Towards Viewer
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom left
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(1.0, -1.0, 1.0) // Bottom right
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(1.0, 1.0, 1.0) // Top right
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(-1.0, 1.0, 1.0) // Top left
// Back Face
gl.Normal3f(0.0, 0.0, -1.0) // Normal Pointing Away From Viewer
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom right
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top right
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(1.0, 1.0, -1.0) // Top left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(1.0, -1.0, -1.0) // Bottom left
// Top Face
gl.Normal3f(0.0, 1.0, 0.0) // Normal Pointing Up
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(-1.0, 1.0, 1.0) // Bottom left
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(1.0, 1.0, 1.0) // Bottom right
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(1.0, 1.0, -1.0) // Top right
// Bottom Face
gl.Normal3f(0.0, -1.0, 0.0) // Normal Pointing Down
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(-1.0, -1.0, -1.0) // Top right
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(1.0, -1.0, -1.0) // Top left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(1.0, -1.0, 1.0) // Bottom left
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom right
// Right face
gl.Normal3f(1.0, 0.0, 0.0) // Normal Pointing Right
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(1.0, -1.0, -1.0) // Bottom right
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(1.0, 1.0, -1.0) // Top right
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(1.0, 1.0, 1.0) // Top left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(1.0, -1.0, 1.0) // Bottom left
// Left Face
gl.Normal3f(-1.0, 0.0, 0.0) // Normal Pointing Left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom left
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom right
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(-1.0, 1.0, 1.0) // Top right
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top left
gl.End()
sdl.GL_SwapBuffers()
xrot += xspeed
yrot += yspeed
// 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,代码行数:101,代码来源:lesson08.go
示例17: Draw
func Draw(t int64) {
console.culledVertices = 0
console.vertices = 0
gVertexBuffer.Reset()
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
gl.Color4ub(192, 192, 192, 255)
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.DEPTH_TEST)
//gl.Enable(gl.FOG)
gl.Enable(gl.LIGHTING)
gl.Enable(gl.LIGHT0)
gl.Enable(gl.COLOR_MATERIAL)
if timeOfDay < 5.3 || timeOfDay > 20.7 {
gl.Enable(gl.LIGHT1)
} else {
gl.Disable(gl.LIGHT1)
}
// CheckGLError()
gl.LoadIdentity()
center := ThePlayer.Position()
// matrix := *viewport.matrix.Float32()
matrix := ModelMatrix().Float32()
gl.MultMatrixf(&matrix[0])
//gl.Translatef(-float32(center[XAXIS]), -float32(center[YAXIS]), -float32(center[ZAXIS]))
// Sun
gl.Materialfv(gl.FRONT, gl.AMBIENT, []float32{0.1, 0.1, 0.1, 1})
gl.Materialfv(gl.FRONT, gl.DIFFUSE, []float32{0.1, 0.1, 0.1, 1})
gl.Materialfv(gl.FRONT, gl.SPECULAR, []float32{0.1, 0.1, 0.1, 1})
gl.Materialfv(gl.FRONT, gl.SHININESS, []float32{0.0, 0.0, 0.0, 1})
var daylightIntensity float32 = 0.45
var nighttimeIntensity float32 = 0.15
if timeOfDay < 5 || timeOfDay > 21 {
gl.LightModelfv(gl.LIGHT_MODEL_AMBIENT, []float32{0.2, 0.2, 0.2, 1})
daylightIntensity = 0.01
} else if timeOfDay < 6 {
daylightIntensity = nighttimeIntensity + daylightIntensity*(timeOfDay-5)
} else if timeOfDay > 20 {
daylightIntensity = nighttimeIntensity + daylightIntensity*(21-timeOfDay)
}
gl.LightModelfv(gl.LIGHT_MODEL_AMBIENT, []float32{daylightIntensity / 2.5, daylightIntensity / 2.5, daylightIntensity / 2.5, 1})
gl.Lightfv(gl.LIGHT0, gl.POSITION, []float32{30 * float32(math.Sin(ThePlayer.Heading()*math.Pi/180)), 60, 30 * float32(math.Cos(ThePlayer.Heading()*math.Pi/180)), 0})
gl.Lightfv(gl.LIGHT0, gl.AMBIENT, []float32{daylightIntensity, daylightIntensity, daylightIntensity, 1})
// gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, []float32{daylightIntensity, daylightIntensity, daylightIntensity,1})
// gl.Lightfv(gl.LIGHT0, gl.SPECULAR, []float32{daylightIntensity, daylightIntensity, daylightIntensity,1})
gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, []float32{daylightIntensity * 2, daylightIntensity * 2, daylightIntensity * 2, 1})
gl.Lightfv(gl.LIGHT0, gl.SPECULAR, []float32{daylightIntensity, daylightIntensity, daylightIntensity, 1})
// Torch
// ambient := float32(0.6)
// specular := float32(0.6)
// diffuse := float32(1)
// gl.Lightfv(gl.LIGHT1, gl.POSITION, []float32{float32(ThePlayer.position[XAXIS]), float32(ThePlayer.position[YAXIS] + 1), float32(ThePlayer.position[ZAXIS]), 1})
// gl.Lightfv(gl.LIGHT1, gl.AMBIENT, []float32{ambient, ambient, ambient, 1})
// gl.Lightfv(gl.LIGHT1, gl.SPECULAR, []float32{specular, specular, specular, 1})
// gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, []float32{diffuse, diffuse, diffuse, 1})
// gl.Lightf(gl.LIGHT1, gl.CONSTANT_ATTENUATION, 1.5)
// gl.Lightf(gl.LIGHT1, gl.LINEAR_ATTENUATION, 0.5)
// gl.Lightf(gl.LIGHT1, gl.QUADRATIC_ATTENUATION, 0.01)
// gl.Lightf(gl.LIGHT1, gl.SPOT_CUTOFF, 35)
// gl.Lightf(gl.LIGHT1, gl.SPOT_EXPONENT, 2.0)
// gl.Lightfv(gl.LIGHT1, gl.SPOT_DIRECTION, []float32{float32(math.Cos(ThePlayer.Heading() * math.Pi / 180)), float32(-0.7), -float32(math.Sin(ThePlayer.Heading() * math.Pi / 180))})
gl.RenderMode(gl.RENDER)
selectedBlockFace := viewport.SelectedBlockFace()
ThePlayer.Draw(center, selectedBlockFace)
TheWorld.Draw(center, selectedBlockFace)
if pause.visible {
pause.Draw(t)
} else if inventory.visible {
inventory.Draw(t)
} else {
picker.Draw(t)
}
if console.visible {
console.Draw(t)
}
gl.Finish()
gl.Flush()
sdl.GL_SwapBuffers()
// runtime.GC()
}
开发者ID:Cyberdada,项目名称:amberfell,代码行数:97,代码来源:amberfell.go
示例18: Draw
func Draw(t int64) {
console.culledVertices = 0
console.vertices = 0
gVertexBuffer.Reset()
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
gl.Color4ub(192, 192, 192, 255)
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.DEPTH_TEST)
gl.Enable(gl.LIGHTING)
gl.Enable(gl.LIGHT0)
gl.Enable(gl.COLOR_MATERIAL)
gl.LoadIdentity()
center := ThePlayer.Position()
matrix := ModelMatrix().Float32()
gl.MultMatrixf(&matrix[0])
// Sun
gl.Materialfv(gl.FRONT, gl.AMBIENT, []float32{0.1, 0.1, 0.1, 1})
gl.Materialfv(gl.FRONT, gl.DIFFUSE, []float32{0.1, 0.1, 0.1, 1})
gl.Materialfv(gl.FRONT, gl.SPECULAR, []float32{0.1, 0.1, 0.1, 1})
gl.Materialfv(gl.FRONT, gl.SHININESS, []float32{0.0, 0.0, 0.0, 1})
daylightIntensity := float32(SUNLIGHT_LEVELS[sunlightLevel])
gl.LightModelfv(gl.LIGHT_MODEL_AMBIENT, []float32{daylightIntensity / 2.5, daylightIntensity / 2.5, daylightIntensity / 2.5, 1})
gl.Lightfv(gl.LIGHT0, gl.POSITION, []float32{30 * float32(math.Sin(ThePlayer.Heading()*math.Pi/180)), 60, 30 * float32(math.Cos(ThePlayer.Heading()*math.Pi/180)), 0})
gl.Lightfv(gl.LIGHT0, gl.AMBIENT, []float32{daylightIntensity, daylightIntensity, daylightIntensity, 1})
gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, []float32{daylightIntensity * 2, daylightIntensity * 2, daylightIntensity * 2, 1})
gl.Lightfv(gl.LIGHT0, gl.SPECULAR, []float32{daylightIntensity, daylightIntensity, daylightIntensity, 1})
gl.RenderMode(gl.RENDER)
var selectedBlockFace *BlockFace
if !pause.visible && !inventory.visible {
selectedBlockFace = viewport.SelectedBlockFace()
}
ThePlayer.Draw(center, selectedBlockFace)
TheWorld.Draw(center, selectedBlockFace)
if pause.visible {
pause.Draw(t)
} else if inventory.visible {
inventory.Draw(t)
} else {
picker.Draw(t)
}
if console.visible {
console.Draw(t)
}
gl.Finish()
gl.Flush()
sdl.GL_SwapBuffers()
console.framesDrawn++
}
开发者ID:caustin,项目名称:amberfell,代码行数:62,代码来源:amberfell.go
示例19: 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) /* Red */
gl.Vertex3f(0.0, 1.0, 0.0) /* Top Of Triangle (Front) */
gl.Color3f(0.0, 1.0, 0.0) /* Green */
gl.Vertex3f(-1.0, -1.0, 1.0) /* Left Of Triangle (Front) */
gl.Color3f(0.0, 0.0, 1.0) /* Blue */
gl.Vertex3f(1.0, -1.0, 1.0) /* Right Of Triangle (Front) */
gl.Color3f(1.0, 0.0, 0.0) /* Red */
gl.Vertex3f(0.0, 1.0, 0.0) /* Top Of Triangle (Right) */
gl.Color3f(0.0, 0.0, 1.0) /* Blue */
gl.Vertex3f(1.0, -1.0, 1.0) /* Left Of Triangle (Right) */
gl.Color3f(0.0, 1.0, 0.0) /* Green */
gl.Vertex3f(1.0, -1.0, -1.0) /* Right Of Triangle (Right) */
gl.Color3f(1.0, 0.0, 0.0) /* Red */
gl.Vertex3f(0.0, 1.0, 0.0) /* Top Of Triangle (Back) */
gl.Color3f(0.0, 1.0, 0.0) /* Green */
gl.Vertex3f(1.0, -1.0, -1.0) /* Left Of Triangle (Back) */
gl.Color3f(0.0, 0.0, 1.0) /* Blue */
gl.Vertex3f(-1.0, -1.0, -1.0) /* Right Of Triangle (Back) */
gl.Color3f(1.0, 0.0, 0.0) /* Red */
gl.Vertex3f(0.0, 1.0, 0.0) /* Top Of Triangle (Left) */
gl.Color3f(0.0, 0.0, 1.0) /* Blue */
gl.Vertex3f(-1.0, -1.0, -1.0) /* Left Of Triangle (Left) */
gl.Color3f(0.0, 1.0, 0.0) /* Green */
gl.Vertex3f(-1.0, -1.0, 1.0) /* Right Of Triangle (Left) */
gl.End() // finish drawing the triangle
// Move right 3 units
gl.LoadIdentity()
gl.Translatef(1.5, 0.0, -7.0)
gl.Rotatef(float32(rquad), 1.0, 1.0, 1.0) // rotate the quad on the X axis
gl.Begin(gl.QUADS) // draw quads
gl.Color3f(0.0, 1.0, 0.0) // Set The Color To Green
gl.Vertex3f(1.0, 1.0, -1.0) // Top Right Of The Quad (Top)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top Left Of The Quad (Top)
gl.Vertex3f(-1.0, 1.0, 1.0) // Bottom Left Of The Quad (Top)
gl.Vertex3f(1.0, 1.0, 1.0) // Bottom Right Of The Quad (Top)
gl.Color3f(1.0, 0.5, 0.0) // Set The Color To Orange
gl.Vertex3f(1.0, -1.0, 1.0) // Top Right Of The Quad (Bottom)
gl.Vertex3f(-1.0, -1.0, 1.0) // Top Left Of The Quad (Bottom)
gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Left Of The Quad (Bottom)
gl.Vertex3f(1.0, -1.0, -1.0) // Bottom Right Of The Quad (Bottom)
gl.Color3f(1.0, 0.0, 0.0) // Set The Color To Red
gl.Vertex3f(1.0, 1.0, 1.0) // Top Right Of The Quad (Front)
gl.Vertex3f(-1.0, 1.0, 1.0) // Top Left Of The Quad (Front)
gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom Left Of The Quad (Front)
gl.Vertex3f(1.0, -1.0, 1.0) // Bottom Right Of The Quad (Front)
gl.Color3f(1.0, 1.0, 0.0) // Set The Color To Yellow
gl.Vertex3f(1.0, -1.0, -1.0) // Bottom Left Of The Quad (Back)
gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Right Of The Quad (Back)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top Right Of The Quad (Back)
gl.Vertex3f(1.0, 1.0, -1.0) // Top Left Of The Quad (Back)
gl.Color3f(0.0, 0.0, 1.0) // Set The Color To Blue
gl.Vertex3f(-1.0, 1.0, 1.0) // Top Right Of The Quad (Left)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top Left Of The Quad (Left)
gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Left Of The Quad (Left)
gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom Right Of The Quad (Left)
gl.Color3f(1.0, 0.0, 1.0) // Set The Color To Violet
gl.Vertex3f(1.0, 1.0, -1.0) // Top Right Of The Quad (Right)
gl.Vertex3f(1.0, 1.0, 1.0) // Top Left Of The Quad (Right)
gl.Vertex3f(1.0, -1.0, 1.0) // Bottom Left Of The Quad (Right)
gl.Vertex3f(1.0, -1.0, -1.0) // Bottom Right Of The Quad (Right)
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:shogg,项目名称:opengl-go-tutorials,代码行数:97,代码来源:lesson05.go
示例20: 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(0.0, 0.0, -7.0)
gl.Rotatef(float32(xrot), 1.0, 0.0, 0.0) /* Rotate On The X Axis */
gl.Rotatef(float32(yrot), 0.0, 1.0, 0.0) /* Rotate On The Y Axis */
gl.Rotatef(float32(zrot), 0.0, 0.0, 1.0) /* Rotate On The Z Axis */
/* Select Our Texture */
gl.BindTexture(gl.TEXTURE_2D, uint(texture))
gl.Begin(gl.QUADS) // Draw a quad
/* Front Face */
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom left
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(1.0, -1.0, 1.0) // Bottom right
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(1.0, 1.0, 1.0) // Top right
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(-1.0, 1.0, 1.0) // Top left
/* Back Face */
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom right
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top right
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(1.0, 1.0, -1.0) // Top left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(1.0, -1.0, -1.0) // Bottom left
/* Top Face */
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(-1.0, 1.0, 1.0) // Bottom left
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(1.0, 1.0, 1.0) // Bottom right
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(1.0, 1.0, -1.0) // Top right
/* Bottom Face */
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(-1.0, -1.0, -1.0) // Top right
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(1.0, -1.0, -1.0) // Top left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(1.0, -1.0, 1.0) // Bottom left
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom right
/* Right face */
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(1.0, -1.0, -1.0) // Bottom right
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(1.0, 1.0, -1.0) // Top right
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(1.0, 1.0, 1.0) // Top left
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(1.0, -1.0, 1.0) // Bottom left
/* Left Face */
gl.TexCoord2f(1.0, 0.0)
gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom left
gl.TexCoord2f(0.0, 0.0)
gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom right
gl.TexCoord2f(0.0, 1.0)
gl.Vertex3f(-1.0, 1.0, 1.0) // Top right
gl.TexCoord2f(1.0, 1.0)
gl.Vertex3f(-1.0, 1.0, -1.0) // Top left
gl.End() // done drawing the quad
// Draw to the screen
sdl.GL_SwapBuffers()
xrot += 0.3 /* X Axis Rotation */
yrot += 0.2 /* Y Axis Rotation */
zrot += 0.4 /* Z Axis Rotation */
// 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,代码行数:96,代码来源:lesson06.go
注:本文中的github.com/banthar/Go-SDL/sdl.GL_SwapBuffers函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论