Ejemplo n.º 1
0
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)
	}
}
Ejemplo n.º 2
0
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)
	}
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
// 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
	}
}
Ejemplo n.º 5
0
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()
	}
}
Ejemplo n.º 6
0
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()
}
Ejemplo n.º 7
0
// 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
	}
}
Ejemplo n.º 8
0
// 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
}
Ejemplo n.º 9
0
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
		}
	}
}
Ejemplo n.º 10
0
// 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
	}
}
Ejemplo n.º 11
0
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
}
Ejemplo n.º 12
0
// 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
	}
}
Ejemplo n.º 13
0
Archivo: main.go Proyecto: shogg/glvox
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()
	}
}
Ejemplo n.º 14
0
Archivo: gltoy.go Proyecto: shogg/gltoy
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()
	}
}
Ejemplo n.º 15
0
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()
	}
}
Ejemplo n.º 16
0
// 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
	}
}
Ejemplo n.º 17
0
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()
}
Ejemplo n.º 18
0
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++
}
Ejemplo n.º 19
0
// 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
	}
}
Ejemplo n.º 20
0
// 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
	}
}
Ejemplo n.º 21
0
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.BindTexture(gl.TEXTURE_2D, uint(texture))

	for loop, star := range stars {
		gl.LoadIdentity()
		gl.Translatef(0.0, 0.0, float32(zoom))
		gl.Rotatef(float32(tilt), 1.0, 0.0, 0.0)
		gl.Rotatef(float32(star.angle), 0.0, 1.0, 0.0)
		gl.Translatef(float32(star.dist), 0.0, 0.0)
		gl.Rotatef(float32(-star.angle), 0.0, 1.0, 0.0)
		gl.Rotatef(float32(-tilt), 1.0, 0.0, 0.0)

		if twinkle {
			other := stars[(num-loop)-1]
			gl.Color4ub(uint8(other.r), uint8(other.g), uint8(other.b), 255)
			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 0.0)
			gl.Vertex3f(1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 1.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 1.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()
		}

		gl.Rotatef(float32(spin), 0.0, 0.0, 1.0)
		gl.Color4ub(uint8(star.r), uint8(star.g), uint8(star.b), 255)
		gl.Begin(gl.QUADS)
		gl.TexCoord2f(0.0, 0.0)
		gl.Vertex3f(-1.0, -1.0, 0.0)
		gl.TexCoord2f(1.0, 0.0)
		gl.Vertex3f(1.0, -1.0, 0.0)
		gl.TexCoord2f(1.0, 1.0)
		gl.Vertex3f(1.0, 1.0, 0.0)
		gl.TexCoord2f(0.0, 1.0)
		gl.Vertex3f(-1.0, 1.0, 0.0)
		gl.End()

		spin += 0.01
		star.angle += gl.GLfloat(loop) / gl.GLfloat(num)
		star.dist -= 0.01

		if star.dist < 0.0 {
			star.dist += 5.0
			star.r = gl.GLubyte(rand.Float32() * 255)
			star.g = gl.GLubyte(rand.Float32() * 255)
			star.b = gl.GLubyte(rand.Float32() * 255)
		}
	}

	// 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
	}
}
Ejemplo n.º 22
0
func main() {
	var running bool = true
	var width int = 800
	var height int = 600
	var t float32

	if sdl.Init(sdl.INIT_VIDEO) != 0 {
		panic(sdl.GetError())
	}

	sdl.WM_SetCaption("Horde3d Go SDL Example", "")

	//set sdl video mode
	if sdl.SetVideoMode(width, height, 32, sdl.OPENGL) == nil {
		panic(sdl.GetError())
	}

	if !horde3d.Init() {
		fmt.Println("Error initializing Horde3D")
		horde3d.DumpMessages()
		return
	}

	//horde3d.SetOption(horde3d.Options_DebugViewMode, 1)
	//horde3d.SetOption(horde3d.Options_WireframeMode, 1)
	fmt.Println("Version: ", horde3d.VersionString())

	//pipeline
	pipeRes := horde3d.AddResource(horde3d.ResTypes_Pipeline, "forward.pipeline.xml", 0)
	modelRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph, "platform.scene.xml", 0)

	horde3d.LoadResourcesFromDisk("../content|" +
		"../content/pipelines|" +
		"../content/models|" +
		"../content/materials|" +
		"../content/shaders|" +
		"../content/textures|" +
		"../content/animations|" +
		"../content/particles|" +
		"../content/models/platform|" +
		"../content/effects")

	//add camera
	cam := horde3d.RootNode.AddCameraNode("Camera", pipeRes)
	//Setup Camera Viewport
	cam.SetNodeParamI(horde3d.Camera_ViewportXI, 0)
	cam.SetNodeParamI(horde3d.Camera_ViewportYI, 0)
	cam.SetNodeParamI(horde3d.Camera_ViewportWidthI, width)
	cam.SetNodeParamI(horde3d.Camera_ViewportHeightI, height)

	//add model
	model := horde3d.RootNode.AddNodes(modelRes)
	model.SetTransform(0, -30, -150, 0, 0, 0, 1, 1, 1)
	//add light
	light := horde3d.RootNode.AddLightNode("Light1", 0, "LIGHTING", "SHADOWMAP")
	light.SetTransform(0, 20, 0, 0, 0, 0, 1, 1, 1)
	light.SetNodeParamF(horde3d.Light_RadiusF, 0, 150)
	light.SetNodeParamF(horde3d.Light_FovF, 0, 90)
	//horde3d.SetNodeParamI(light, horde3d.Light_ShadowMapCountI, 3)
	light.SetNodeParamF(horde3d.Light_ShadowSplitLambdaF, 0, 0.9)
	//horde3d.SetNodeParamF(light, horde3d.Light_ShadowMapBiasF, 0, 0.001)
	light.SetNodeParamF(horde3d.Light_ColorF3, 0, 1.9)
	light.SetNodeParamF(horde3d.Light_ColorF3, 1, 1.7)
	light.SetNodeParamF(horde3d.Light_ColorF3, 2, 1.75)

	for running {
		t = 0
		//increase anim time
		t = t + 10.0*(1/60)
		//process SDL events / input
		switch event := sdl.PollEvent(); event.(type) {
		case *sdl.QuitEvent:
			running = false
			break
		}
		//horde3d.SetNodeTransform(model,
		//t*10, 0, 0,
		//0, 0, 0,
		//1, 1, 1)
		horde3d.Render(cam)
		horde3d.FinalizeFrame()
		horde3d.DumpMessages()
		sdl.GL_SwapBuffers()
	}
	horde3d.Release()
	sdl.Quit()

}
Ejemplo n.º 23
0
Archivo: tess.go Proyecto: 0xfaded/glu
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")
	}

	gl.MatrixMode(gl.PROJECTION)

	gl.Viewport(0, 0, int(screen.W), int(screen.H))
	gl.LoadIdentity()
	gl.Ortho(-5, 5, -2.5, 2.5, -1.0, 1.0)

	gl.ClearColor(0, 0, 0, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)

	tess := glu.NewTess()

	tess.SetBeginCallback(tessBeginHandler)
	tess.SetVertexCallback(tessVertexHandler)
	tess.SetEndCallback(tessEndHandler)
	tess.SetErrorCallback(tessErrorHandler)
	tess.SetEdgeFlagCallback(tessEdgeFlagHandler)
	tess.SetCombineCallback(tessCombineHandler)

	tess.Normal(0, 0, 1)

	var running = true

	for running {

		gl.MatrixMode(gl.MODELVIEW)
		gl.LoadIdentity()
		gl.Translated(-2.5, 0, 0)

		tess.BeginPolygon(nil)
		tess.BeginContour()

		for v := range OuterContour {
			tess.Vertex(OuterContour[v], &OuterContour[v])
		}

		tess.EndContour()
		tess.BeginContour()

		for v := range InnerContour {
			tess.Vertex(InnerContour[v], &InnerContour[v])
		}

		tess.EndContour()
		tess.EndPolygon()

		gl.Translated(5, 0, 0)

		tess.BeginPolygon(nil)
		tess.BeginContour()

		for v := range StarContour {
			tess.Vertex(StarContour[v], &StarContour[v])
		}

		tess.EndContour()
		tess.EndPolygon()

		sdl.GL_SwapBuffers()
		sdl.Delay(25)
	}

	tess.Delete()
	sdl.Quit()

}
Ejemplo n.º 24
0
func testPlot(dimension, order int) {
	var (
		iterations float64   = 0
		start_t              = time.Now()
		split      time.Time = start_t
		total      time.Duration
		fps        float64 = 1.0

		new_attractor, redraw bool = true, true
		npoints               int  = 1e5

		coeffs []float64
		//offsets, offset_coeffs []float64
		start Matrix = MakeMatrix(1, int(math.Max(3, float64(dimension))))
		points, points2/*, points3*/ Matrix

	//attractor = gl.GenLists(1);
	)

	//offsets = make([]float64, ncoeffs(order))
	//offset_coeffs = make([]float64, ncoeffs(order))
	//coeffs = make([]float64, dimension + nCoeffs(order, dimension) * dimension)

	//for i := range offsets { offsets[i] += rand.Float64() }

	for handleEvents(&new_attractor, &redraw, &npoints) {

		xoff += xvel / fps
		yoff += yvel / fps
		zoff += zvel / fps
		xrot += xrotvel / fps
		yrot += yrotvel / fps
		zrot += zrotvel / fps
		scale += svel / fps

		if new_attractor {
			coeffs, start = find_map_with_L(dimension, order, 0.1, 0.4)
			redraw = true
			new_attractor = false
		}
		if redraw {
			points = MakePointMatrix(makeMapFn(dimension, order, coeffs), start, 500, npoints)
			points2 = MakeMatrix(npoints, points.Height())
			//points3 = MakeMatrix(npoints, points.Height())
			redraw = false
			fmt.Println("Redraw", npoints, "points")
		}

		//points2 = points
		//RotationXW(xwrot).Apply(points, points2)
		//RotationYW(xwrot + 0.25).Apply(points2, points3)
		//RotationZW(xwrot + 0.50).Apply(points3, points2)

		if dimension == 4 {
			RotationZW(xwrot).Apply(points, points2)
			xwrot += 0.05
			ApplyW(points2, points2)
		} else {
			points2 = points
		}

		gl.Enable(gl.BLEND)
		gl.Enable(gl.POINT_SMOOTH)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

		gl.PointSize(1.0)
		gl.LoadIdentity()
		gl.Rotated(xrot, 1, 0, 0)
		gl.Rotated(yrot, 0, 1, 0)
		gl.Rotated(zrot, 0, 0, 1)
		gl.Scaled(scale, scale, scale)
		gl.Translated(xoff, yoff, zoff)

		gl.Color4d(1, 1, 1, 0.25)

		gl.EnableClientState(gl.VERTEX_ARRAY)
		if dimension > 3 {
			gl.VertexPointer(3, (dimension-3)*32, points2.FlatCols())
		} else {
			gl.VertexPointer(3, 0, points2.FlatCols())
		}
		gl.DrawArrays(gl.POINTS, 0, points2.Width())
		gl.DisableClientState(gl.VERTEX_ARRAY)

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

		iterations++
		if time.Since(split).Seconds() > 1.0 {
			total = time.Since(start_t)
			fps = iterations / total.Seconds()
			fmt.Println(iterations, "iterations in", total.Seconds(), "gives",
				fps, "fps")
			split = time.Now()
		}
	}
}
Ejemplo n.º 25
0
func (this *Window) flip() { sdl.GL_SwapBuffers() }