Example #1
0
func (e *Entity) Render(pos mathgl.Vec2, width float32) {
	var rgba [4]float64
	gl.GetDoublev(gl.CURRENT_COLOR, (*gl.Double)(&rgba[0]))
	e.last_render_width = width
	gl.Enable(gl.TEXTURE_2D)
	e.drawReticle(pos, rgba)
	if e.sprite.sp != nil {
		dxi, dyi := e.sprite.sp.Dims()
		dx := float32(dxi)
		dy := float32(dyi)
		tx, ty, tx2, ty2 := e.sprite.sp.Bind()
		gl.Begin(gl.QUADS)
		gl.TexCoord2d(gl.Double(tx), gl.Double(-ty))
		gl.Vertex2f(gl.Float(pos.X), gl.Float(pos.Y))
		gl.TexCoord2d(gl.Double(tx), gl.Double(-ty2))
		gl.Vertex2f(gl.Float(pos.X), gl.Float(pos.Y+dy*width/dx))
		gl.TexCoord2d(gl.Double(tx2), gl.Double(-ty2))
		gl.Vertex2f(gl.Float(pos.X+width), gl.Float(pos.Y+dy*width/dx))
		gl.TexCoord2d(gl.Double(tx2), gl.Double(-ty))
		gl.Vertex2f(gl.Float(pos.X+width), gl.Float(pos.Y))
		gl.End()
	}
}
Example #2
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
}
Example #3
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()
}