Exemplo n.º 1
0
func DrawStarTex(t *data.Star) {

	// Find the center point of the texture to rotate around
	xav := (t.X1 + t.X2) / 2
	yav := (t.Y1 + t.Y2) / 2

	//Translate there, rotate, translate back
	gl.MatrixMode(gl.MODELVIEW)
	gl.Translatef(xav, yav, 0)
	gl.Rotatef(gl.Float(t.Theta), 0, 0, 1)
	gl.Translatef(-xav, -yav, 0)

	//Bind our texture to be drawn by id
	gl.Color3f(1, 1, 1)
	gl.Enable(gl.TEXTURE_2D)
	gl.BindTexture(gl.TEXTURE_2D, t.TexId)

	// Draw a rectangle with the texture stretched to the corners
	gl.Begin(gl.QUADS)

	// Stretch the texture to its 4 corners.
	gl.TexCoord2d(0, 0)
	gl.Vertex2f(t.X1, t.Y1)

	gl.TexCoord2d(0, 1)
	gl.Vertex2f(t.X1, t.Y2)

	gl.TexCoord2d(1, 1)
	gl.Vertex2f(t.X2, t.Y2)

	gl.TexCoord2d(1, 0)
	gl.Vertex2f(t.X2, t.Y1)

	gl.End()

	// Unbind the texture in case something else wants to draw
	gl.Disable(gl.TEXTURE_2D)

	// Reset the matrix
	gl.LoadIdentity()

}
Exemplo n.º 2
0
func setupTextureList() {
	textureListSync.Do(func() {
		render.Queue(func() {
			textureList = gl.GenLists(1)
			gl.NewList(textureList, gl.COMPILE)
			gl.Begin(gl.QUADS)
			gl.TexCoord2d(0, -1)
			gl.Vertex2i(0, 0)

			gl.TexCoord2d(0, 0)
			gl.Vertex2i(0, 1)

			gl.TexCoord2d(1, 0)
			gl.Vertex2i(1, 1)

			gl.TexCoord2d(1, -1)
			gl.Vertex2i(1, 0)
			gl.End()
			gl.EndList()
		})
	})
}
Exemplo n.º 3
0
func (e *Entity) Render(pos mathgl.Vec2, width float32) {
	var rgba [4]float64
	gl.GetDoublev(gl.CURRENT_COLOR, &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(tx, -ty)
		gl.Vertex2f(pos.X, pos.Y)
		gl.TexCoord2d(tx, -ty2)
		gl.Vertex2f(pos.X, pos.Y+dy*width/dx)
		gl.TexCoord2d(tx2, -ty2)
		gl.Vertex2f(pos.X+width, pos.Y+dy*width/dx)
		gl.TexCoord2d(tx2, -ty)
		gl.Vertex2f(pos.X+width, pos.Y)
		gl.End()
	}
}
Exemplo n.º 4
0
func (sb *spriteBox) Draw(region gui.Region) {
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4d(sb.r, sb.g, sb.b, 1)
	gl.Begin(gl.QUADS)
	gl.Vertex2i(int32(region.X+region.Dx/3), int32(region.Y))
	gl.Vertex2i(int32(region.X+region.Dx/3), int32(region.Y+region.Dy))
	gl.Vertex2i(int32(region.X+region.Dx/3*2), int32(region.Y+region.Dy))
	gl.Vertex2i(int32(region.X+region.Dx/3*2), int32(region.Y))
	gl.End()
	if sb.s != nil {
		gl.Enable(gl.TEXTURE_2D)
		tx, ty, tx2, ty2 := sb.s.Bind()
		// fmt.Printf("Tex: %f %f %f %f\n", tx, ty, tx2, ty2)
		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Color4f(1, 1, 1, 1)
		gl.Begin(gl.QUADS)
		x := int32(region.X + region.Dx/2)
		y := int32(region.Y + region.Dy/2)
		gl.TexCoord2d(tx, -ty)
		gl.Vertex2i(x-50, y-75)
		gl.TexCoord2d(tx, -ty2)
		gl.Vertex2i(x-50, y+75)
		gl.TexCoord2d(tx2, -ty2)
		gl.Vertex2i(x+50, y+75)
		gl.TexCoord2d(tx2, -ty)
		gl.Vertex2i(x+50, y-75)
		gl.End()
		gl.Color4d(1, 1, 1, 1)
		text := fmt.Sprintf("%d : %s : %s", sb.s.Facing(), sb.s.Anim(), sb.s.AnimState())
		if sb.top {
			dict.RenderString(text, float64(region.X), float64(region.Y+region.Dy)-dict.MaxHeight(), 0, dict.MaxHeight(), gui.Left)
		} else {
			dict.RenderString(text, float64(region.X), float64(region.Y), 0, dict.MaxHeight(), gui.Left)
		}
	}
}