Exemple #1
0
func (f *Furniture) Render(pos mathgl.Vec2, width float32) {
	var rgba [4]gl.Double
	gl.GetDoublev(gl.CURRENT_COLOR, &rgba[0])
	gl.PushAttrib(gl.CURRENT_BIT)
	if !f.Blocks_los || !f.alpha_enabled {
		f.alpha = 1
	}
	var tff gl.Double = 255
	gl.Color4ub(gl.Ubyte(tff*rgba[0]), gl.Ubyte(tff*rgba[1]), gl.Ubyte(tff*rgba[2]), gl.Ubyte(tff*rgba[3]*gl.Double(f.alpha)))
	orientation := f.Orientations[f.Rotation]
	dy := width * float32(orientation.Texture.Data().Dy()) / float32(orientation.Texture.Data().Dx())
	// orientation.Texture.Data().Render(float64(pos.X), float64(pos.Y), float64(width), float64(dy))
	orientation.Texture.Data().RenderAdvanced(float64(pos.X), float64(pos.Y), float64(width), float64(dy), 0, !f.Flip)
	gl.PopAttrib()
}
Exemple #2
0
func (sp *SpawnPoint) RenderOnFloor() {
	re := topSpawnRegexp()
	if re == nil || !re.MatchString(sp.Name) {
		return
	}

	var rgba [4]gl.Double
	gl.GetDoublev(gl.CURRENT_COLOR, &rgba[0])
	gl.PushAttrib(gl.CURRENT_BIT)
	gl.Disable(gl.TEXTURE_2D)

	// This just creates a color that is consistent among all spawn points whose
	// names match SpawnName-.*
	prefix := sp.Name
	for i := range prefix {
		if prefix[i] == '-' {
			prefix = prefix[0:i]
			break
		}
	}
	h := fnv.New32()
	h.Write([]byte(prefix))
	hs := h.Sum32()
	gl.Color4ub(gl.Ubyte(hs%256), gl.Ubyte((hs/256)%256), gl.Ubyte((hs/(256*256))%256), gl.Ubyte(255*rgba[3]))

	base.EnableShader("box")
	base.SetUniformF("box", "dx", float32(sp.Dx))
	base.SetUniformF("box", "dy", float32(sp.Dy))
	if !sp.temporary {
		base.SetUniformI("box", "temp_invalid", 0)
	} else if !sp.invalid {
		base.SetUniformI("box", "temp_invalid", 1)
	} else {
		base.SetUniformI("box", "temp_invalid", 2)
	}
	(&texture.Object{}).Data().Render(float64(sp.X), float64(sp.Y), float64(sp.Dx), float64(sp.Dy))
	base.EnableShader("")
	gl.PopAttrib()
}
Exemple #3
0
func (e *Entity) drawReticle(pos mathgl.Vec2, rgba [4]float64) {
	if !e.hovered && !e.selected && !e.controlled {
		return
	}
	gl.PushAttrib(gl.CURRENT_BIT)
	r := gl.Ubyte(rgba[0] * 255)
	g := gl.Ubyte(rgba[1] * 255)
	b := gl.Ubyte(rgba[2] * 255)
	a := gl.Ubyte(rgba[3] * 255)
	switch {
	case e.controlled:
		gl.Color4ub(0, 0, r, a)
	case e.selected:
		gl.Color4ub(r, g, b, a)
	default:
		gl.Color4ub(r, g, b, gl.Ubyte((int(a)*200)>>8))
	}
	glow := texture.LoadFromPath(filepath.Join(base.GetDataDir(), "ui", "glow.png"))
	dx := float64(e.last_render_width + 0.5)
	dy := float64(e.last_render_width * 150 / 100)
	glow.Render(float64(pos.X), float64(pos.Y), dx, dy)
	gl.PopAttrib()
}
Exemple #4
0
func (d *Dictionary) RenderString(s string, x, y, z, height float64, just Justification) {
	if len(s) == 0 {
		return
	}
	strbuf, ok := d.strs[s]
	if !ok {
		defer d.RenderString(s, x, y, z, height, just)
	}
	size := unsafe.Sizeof(dictVert{})
	scale := height / float64(d.data.Maxy-d.data.Miny)
	width := float32(d.figureWidth(s) * scale)
	x_pos := float32(x)
	switch just {
	case Center:
		x_pos -= width / 2
	case Right:
		x_pos -= width
	}
	if ok {
		gl.PushMatrix()
		defer gl.PopMatrix()
		gl.Translated(gl.Double(x_pos), gl.Double(y), gl.Double(z))
		gl.Scaled(gl.Double(scale), gl.Double(scale), 1)

		gl.PushAttrib(gl.COLOR_BUFFER_BIT)
		defer gl.PopAttrib()
		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

		gl.Enable(gl.TEXTURE_2D)
		gl.BindTexture(gl.TEXTURE_2D, gl.Uint(d.texture))

		gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(strbuf.vbuffer))

		gl.EnableClientState(gl.VERTEX_ARRAY)
		gl.VertexPointer(2, gl.FLOAT, gl.Sizei(size), nil)

		gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
		gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(size), gl.Pointer(unsafe.Offsetof(strbuf.vs[0].u)))

		gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(strbuf.ibuffer))
		gl.DrawElements(gl.TRIANGLES, gl.Sizei(len(strbuf.is)), gl.UNSIGNED_SHORT, nil)

		gl.DisableClientState(gl.VERTEX_ARRAY)
		gl.DisableClientState(gl.TEXTURE_COORD_ARRAY)
		return
	}
	x_pos = 0
	for _, r := range s {
		info := d.getInfo(r)
		xleft := x_pos + float32(info.Bounds.Min.X)
		xright := x_pos + float32(info.Bounds.Max.X)
		ytop := float32(d.data.Maxy - info.Bounds.Min.Y)
		ybot := float32(height) + float32(d.data.Miny-info.Bounds.Max.Y)
		start := uint16(len(strbuf.vs))
		strbuf.is = append(strbuf.is, start+0)
		strbuf.is = append(strbuf.is, start+1)
		strbuf.is = append(strbuf.is, start+2)
		strbuf.is = append(strbuf.is, start+0)
		strbuf.is = append(strbuf.is, start+2)
		strbuf.is = append(strbuf.is, start+3)
		strbuf.vs = append(strbuf.vs, dictVert{
			x: xleft,
			y: ybot,
			u: float32(info.Pos.Min.X) / float32(d.data.Dx),
			v: float32(info.Pos.Max.Y) / float32(d.data.Dy),
		})
		strbuf.vs = append(strbuf.vs, dictVert{
			x: xleft,
			y: ytop,
			u: float32(info.Pos.Min.X) / float32(d.data.Dx),
			v: float32(info.Pos.Min.Y) / float32(d.data.Dy),
		})
		strbuf.vs = append(strbuf.vs, dictVert{
			x: xright,
			y: ytop,
			u: float32(info.Pos.Max.X) / float32(d.data.Dx),
			v: float32(info.Pos.Min.Y) / float32(d.data.Dy),
		})
		strbuf.vs = append(strbuf.vs, dictVert{
			x: xright,
			y: ybot,
			u: float32(info.Pos.Max.X) / float32(d.data.Dx),
			v: float32(info.Pos.Max.Y) / float32(d.data.Dy),
		})
		x_pos += float32(info.Advance)
	}
	gl.GenBuffers(1, (*gl.Uint)(&strbuf.vbuffer))
	gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(strbuf.vbuffer))
	gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(int(size)*len(strbuf.vs)), gl.Pointer(&strbuf.vs[0].x), gl.STATIC_DRAW)

	gl.GenBuffers(1, (*gl.Uint)(&strbuf.ibuffer))
	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(strbuf.ibuffer))
	gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, gl.Sizeiptr(int(unsafe.Sizeof(strbuf.is[0]))*len(strbuf.is)), gl.Pointer(&strbuf.is[0]), gl.STATIC_DRAW)
	d.strs[s] = strbuf
}