Пример #1
0
func (self *Picker) DrawPlayerItems(t int64) {

	gl.PushMatrix()
	gl.LoadIdentity()

	for i := 0; i < 5; i++ {

		item := ThePlayer.equippedItems[i]
		if item != ITEM_NONE {
			angle := -(float64(i) + 1.5) * math.Pi / 4
			gl.LoadIdentity()
			x := self.x - self.actionItemRadius*float32(math.Sin(angle))
			y := self.y + self.actionItemRadius*float32(math.Cos(angle))
			gl.Translatef(x, y, 0)

			gl.Rotatef(360*float32(math.Sin(float64(t)/1e10+float64(i))), 1.0, 0.0, 0.0)
			gl.Rotatef(360*float32(math.Cos(float64(t)/1e10+float64(i))), 0.0, 1.0, 0.0)
			gl.Rotatef(360*float32(math.Sin(float64(t)/1e10+float64(i))), 0.0, 0.0, 1.0)
			gl.Scalef(blockscale, blockscale, blockscale)
			gVertexBuffer.Reset()
			TerrainCube(gVertexBuffer, 0, 0, 0, [18]uint16{}, item, FACE_NONE)
			gVertexBuffer.RenderDirect(false)

			gl.LoadIdentity()
			gl.Translatef(x-17*PIXEL_SCALE, y-19*PIXEL_SCALE, 20)
			consoleFont.Print(fmt.Sprintf("%d", ThePlayer.inventory[item]))

		}
	}
	gl.PopMatrix()

}
Пример #2
0
func (s *Sprite) Draw(x, y, angle, scale float32, blend bool) {
	gl.Enable(gl.TEXTURE_2D)
	gl.Disable(gl.COLOR_MATERIAL)
	if blend {
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Enable(gl.BLEND)
	} else {
		gl.Disable(gl.BLEND)
		gl.BlendFunc(gl.ONE, gl.ZERO)
	}

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(x, y, 0)
	gl.Rotatef(angle*360/(2*math.Pi), 0, 0, 1)
	gl.Scalef(scale, scale, 1)
	s.tex.Bind(gl.TEXTURE_2D)
	gl.Begin(gl.QUADS)
	gl.Color3f(1, 1, 1)
	gl.TexCoord2d(0, 0)
	gl.Vertex3f(-0.5*s.width, -0.5*s.height, 0)
	gl.TexCoord2d(1, 0)
	gl.Vertex3f(0.5*s.width, -0.5*s.height, 0)
	gl.TexCoord2d(1, 1)
	gl.Vertex3f(0.5*s.width, 0.5*s.height, 0)
	gl.TexCoord2d(0, 1)
	gl.Vertex3f(-0.5*s.width, 0.5*s.height, 0)
	gl.End()
	gl.Disable(gl.TEXTURE_2D)
	gl.Disable(gl.BLEND)
}
Пример #3
0
func (self *Inventory) DrawItem(t int64, quantity uint16, itemid ItemId, x float64, y float64) {
	gl.PushMatrix()
	gl.LoadIdentity()

	// angle := -90.0
	const blocksize = float32(0.3)

	gl.Translated(x, y, 0)

	//gl.Rotated(angle, 1.0, 0.0, 0.0)
	gl.Rotated(90, 1.0, 0.0, 0.0)
	gl.Rotated(30*math.Sin(float64(t)/1e9+float64(itemid)/2), 0.0, 1.0, 0.0)
	gl.Scalef(blocksize, blocksize, blocksize)
	self.drawBuffer.Reset()

	if itemid < 256 {
		TerrainCube(self.drawBuffer, Vectori{}, [18]BlockId{BLOCK_DIRT, BLOCK_DIRT, BLOCK_DIRT, BLOCK_DIRT, BLOCK_AIR, BLOCK_DIRT, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR}, NewBlockDefault(BlockId(itemid)), FACE_NONE)
	} else {
		RenderItemFlat(self.drawBuffer, Vectori{}, BlockId(itemid))
	}
	self.drawBuffer.RenderDirect(false)

	gl.LoadIdentity()
	gl.Translated(x+2*PIXEL_SCALE-48*PIXEL_SCALE*float64(blocksize), y-7*PIXEL_SCALE-48*PIXEL_SCALE*float64(blocksize), 0)
	inventoryItemFont.Print(fmt.Sprintf("%d", quantity))

	gl.PopMatrix()

}
Пример #4
0
func reshape(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
	gl.Scalef(1, -1, 1)
	gl.Translatef(0, float32(-h), 0)
	gl.MatrixMode(gl.MODELVIEW)
}
Пример #5
0
func stroke_output(x, y float32, str string, font glut.StrokeFont) {
	gl.PushMatrix()
	gl.Translatef(x, y, 0)
	gl.Scalef(0.005, 0.005, 0.005)
	for _, ch := range str {
		font.Character(ch)
	}
	gl.PopMatrix()
}
Пример #6
0
Файл: simple.go Проект: tmc/glut
func reshape(w, h int) {
	/* Because Gil specified "screen coordinates" (presumably with an
	   upper-left origin), this short bit of code sets up the coordinate
	   system to correspond to actual window coodrinates.  This code
	   wouldn't be required if you chose a (more typical in 3D) abstract
	   coordinate system. */

	gl.Viewport(0, 0, w, h)                       /* Establish viewing area to cover entire window. */
	gl.MatrixMode(gl.PROJECTION)                  /* Start modifying the projection matrix. */
	gl.LoadIdentity()                             /* Reset project matrix. */
	gl.Ortho(0, float64(w), 0, float64(h), -1, 1) /* Map abstract coords directly to window coords. */
	gl.Scalef(1, -1, 1)                           /* Invert Y axis so increasing Y goes down. */
	gl.Translatef(0, float32(-h), 0)              /* Shift origin up to upper-left corner. */
}
Пример #7
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Food
	for coord, _ := range food {
		gl.LoadIdentity()
		gl.Scalef(0.05, 0.05, 1)
		gl.Translatef(float32(coord.x)-5, float32(coord.y)-5, -1)

		gl.Begin(gl.QUADS)
		gl.Color3f(0.5, float32(coord.x)/10, float32(coord.y)/10)
		gl.Vertex3f(0.25, 0.75, 0)
		gl.Vertex3f(0.75, 0.75, 0)
		gl.Color3f(0.3, float32(coord.x)/10-0.2, float32(coord.y)/10-0.2)
		gl.Vertex3f(0.75, 0.25, 0)
		gl.Vertex3f(0.25, 0.25, 0)
		gl.End()
	}

	//Snake
	for _, coord := range snake.coords {
		gl.LoadIdentity()
		gl.Scalef(0.05, 0.05, 1)
		gl.Translatef(float32(coord.x)-5, float32(coord.y)-5, -1)

		gl.Begin(gl.QUADS)
		gl.Color3f(float32(coord.y)/10, float32(coord.x)/10, 0.5)
		gl.Vertex3f(0, 1, 0)
		gl.Vertex3f(1, 1, 0)
		gl.Color3f(float32(coord.y)/10-0.2, float32(coord.x)/10-0.2, 0.3)
		gl.Vertex3f(1, 0, 0)
		gl.Vertex3f(0, 0, 0)
		gl.End()
	}

	glfw.SwapBuffers()
}
Пример #8
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()
}
Пример #9
0
func (self *Picker) DrawPlayerItems(t int64, drawQuantities bool) {

	gl.PushMatrix()
	gl.LoadIdentity()

	for i := 0; i < 5; i++ {

		itemid := ThePlayer.equippedItems[i]
		if itemid != ITEM_NONE {
			angle := -(float64(i) + 1.5) * math.Pi / 4
			gl.LoadIdentity()
			x := self.x - self.actionItemRadius*float32(math.Sin(angle))
			y := self.y + self.actionItemRadius*float32(math.Cos(angle))
			gl.Translatef(x, y, 0)

			gl.Rotated(90, 1.0, 0.0, 0.0)
			gl.Rotated(30*math.Sin(float64(t)/1e9+float64(itemid)/2), 0.0, 1.0, 0.0)

			gl.Scalef(BLOCK_SCALE, BLOCK_SCALE, BLOCK_SCALE)
			gGuiBuffer.Reset()
			if itemid < 256 {
				TerrainCube(gGuiBuffer, Vectori{}, [18]BlockId{BLOCK_DIRT, BLOCK_DIRT, BLOCK_DIRT, BLOCK_DIRT, BLOCK_AIR, BLOCK_DIRT, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR}, NewBlockDefault(BlockId(itemid)), FACE_NONE)
			} else {
				RenderItemFlat(gGuiBuffer, Vectori{}, BlockId(itemid))
			}
			gGuiBuffer.RenderDirect(false)

			if drawQuantities {
				gl.LoadIdentity()
				gl.Translatef(x-17*PIXEL_SCALE, y-19*PIXEL_SCALE, 20)
				consoleFont.Print(fmt.Sprintf("%d", ThePlayer.inventory[itemid]))
			}

		}
	}
	gl.PopMatrix()

}
Пример #10
0
func (self *Inventory) DrawItem(t int64, quantity uint16, blockid uint16, r Rect) {
	gl.PushMatrix()
	gl.LoadIdentity()

	const blocksize = float32(0.3)

	i := 1
	gl.Translated(r.x+r.sizex/2, r.y+r.sizey/2+4*PIXEL_SCALE, 0)

	gl.Rotatef(360*float32(math.Sin(float64(t)/1e10+float64(i))), 1.0, 0.0, 0.0)
	gl.Rotatef(360*float32(math.Cos(float64(t)/1e10+float64(i))), 0.0, 1.0, 0.0)
	gl.Rotatef(360*float32(math.Sin(float64(t)/1e10+float64(i))), 0.0, 0.0, 1.0)
	gl.Scalef(blocksize, blocksize, blocksize)
	gVertexBuffer.Reset()
	TerrainCube(gVertexBuffer, Vectori{}, [18]uint16{}, blockid, FACE_NONE)
	gVertexBuffer.RenderDirect(false)

	gl.LoadIdentity()
	gl.Translated(r.x+5*PIXEL_SCALE, r.y+2*PIXEL_SCALE, 0)
	inventoryItemFont.Print(fmt.Sprintf("%d", quantity))

	gl.PopMatrix()

}