예제 #1
0
파일: graphics.go 프로젝트: tanema/amore
// Point will draw a point on the screen at x, y position. The size of the point
// is dependant on the point size set with SetPointSize.
func Point(x, y float32) {
	prepareDraw(nil)
	bindTexture(gl_state.defaultTexture)
	useVertexAttribArrays(attribflag_pos)
	gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 0, gl.Ptr([]float32{x, y}))
	gl.DrawArrays(gl.POINTS, 0, 1)
}
예제 #2
0
파일: graphics.go 프로젝트: tanema/amore
// Circlep will draw a circle at x, y with a radius as specified.
// radiusx and radiusy will specify how much the width will be along those axis
// points specifies how many points should be generated in the arc.
// If it is lower it will look jagged. If it is higher it will hit performace.
// The drawmode specifies either a fill or line draw
func Ellipsep(mode DrawMode, x, y, radiusx, radiusy float32, points int) {
	two_pi := math.Pi * 2.0
	if points <= 0 {
		points = 1
	}

	angle_shift := float32(two_pi) / float32(points)
	phi := float32(0.0)

	coords := make([]float32, 2*(points+1))
	for i := 0; i < points; i++ {
		phi += angle_shift
		coords[2*i+0] = x + radiusx*float32(math.Cos(float64(phi)))
		coords[2*i+1] = y + radiusy*float32(math.Sin(float64(phi)))
	}

	coords[2*points+0] = coords[0]
	coords[2*points+1] = coords[1]

	if mode == LINE {
		PolyLine(coords)
	} else {
		prepareDraw(nil)
		bindTexture(gl_state.defaultTexture)
		useVertexAttribArrays(attribflag_pos)
		gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 0, gl.Ptr(coords))
		gl.DrawArrays(gl.TRIANGLE_FAN, 0, len(coords)/2-1)
	}
}
예제 #3
0
파일: polyline.go 프로젝트: tanema/amore
func (polyline *polyLine) drawTriangleStrip(is_looping bool) {
	prepareDraw(nil)
	bindTexture(gl_state.defaultTexture)
	useVertexAttribArrays(attribflag_pos)
	gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 0, gl.Ptr(polyline.vertices))
	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, len(polyline.vertices))
	if polyline.overdraw { // prepare colors:
		c := GetColor()
		overdraw := polyline.renderOverdraw(is_looping)
		colors := polyline.generateColorArray(len(overdraw), c)
		useVertexAttribArrays(attribflag_pos | attribflag_color)
		gl.VertexAttribPointer(attrib_color, 4, gl.UNSIGNED_BYTE, true, 0, gl.Ptr(colors))
		gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 0, gl.Ptr(overdraw))
		gl.DrawArrays(gl.TRIANGLE_STRIP, 0, len(overdraw))
		SetColorC(c)
	}
}
예제 #4
0
파일: texture.go 프로젝트: tanema/amore
// drawv will take in verticies from the public draw calls and draw the texture
// with the verticies and the model matrix
func (texture *Texture) drawv(model *mgl32.Mat4, vertices []float32) {
	prepareDraw(model)
	bindTexture(texture.getHandle())
	useVertexAttribArrays(attribflag_pos | attribflag_texcoord)

	gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 4*4, gl.Ptr(vertices))
	gl.VertexAttribPointer(attrib_texcoord, 2, gl.FLOAT, false, 4*4, gl.Ptr(&vertices[2]))

	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
}
예제 #5
0
파일: mesh.go 프로젝트: tanema/amore
// Draw satisfies the Drawable interface. Inputs are as follows
// x, y, r, sx, sy, ox, oy, kx, ky
// x, y are position
// r is rotation
// sx, sy is the scale, if sy is not given sy will equal sx
// ox, oy are offset
// kx, ky are the shear. If ky is not given ky will equal kx
func (mesh *Mesh) Draw(args ...float32) {
	prepareDraw(generateModelMatFromArgs(args))
	mesh.bindTexture()
	mesh.bindEnabledAttributes()
	min, max := mesh.GetDrawRange()
	if mesh.ibo != nil && mesh.elementCount > 0 {
		mesh.ibo.drawElements(uint32(mesh.mode), min, max-min+1)
	} else {
		gl.DrawArrays(gl.Enum(mesh.mode), min, max-min+1)
	}
}
예제 #6
0
파일: graphics.go 프로젝트: tanema/amore
// Polygon will draw a closed polygon with an array in the form of x1, y1, x2, y2, x3, y3, ..... xn, yn
// The drawmode specifies either a fill or line draw
func Polygon(mode DrawMode, coords []float32) {
	coords = append(coords, coords[0], coords[1])
	if mode == LINE {
		PolyLine(coords)
	} else {
		prepareDraw(nil)
		bindTexture(gl_state.defaultTexture)
		useVertexAttribArrays(attribflag_pos)
		gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 0, gl.Ptr(coords))
		gl.DrawArrays(gl.TRIANGLE_FAN, 0, len(coords)/2-1)
	}
}
예제 #7
0
파일: graphics.go 프로젝트: tanema/amore
// Arcp is like Arc except that you can define how many points you want to generate
// the arc.
// If it is lower it will look jagged. If it is higher it will hit performace.
// The drawmode specifies either a fill or line draw
func Arcp(mode DrawMode, x, y, radius, angle1, angle2 float32, points int) {
	// Nothing to display with no points or equal angles. (Or is there with line mode?)
	if points <= 0 || angle1 == angle2 {
		return
	}

	// Oh, you want to draw a circle?
	if math.Abs(float64(angle1-angle2)) >= (2.0 * math.Pi) {
		Circlep(mode, x, y, radius, points)
		return
	}

	angle_shift := (angle2 - angle1) / float32(points)
	// Bail on precision issues.
	if angle_shift == 0.0 {
		return
	}

	phi := angle1
	num_coords := (points + 3) * 2
	coords := make([]float32, num_coords)
	coords[0] = x
	coords[num_coords-2] = x
	coords[1] = y
	coords[num_coords-1] = y

	for i := 0; i <= points; i++ {
		phi = phi + angle_shift
		coords[2*(i+1)] = x + radius*float32(math.Cos(float64(phi)))
		coords[2*(i+1)+1] = y + radius*float32(math.Sin(float64(phi)))
	}

	if mode == LINE {
		PolyLine(coords)
	} else {
		prepareDraw(nil)
		bindTexture(gl_state.defaultTexture)
		useVertexAttribArrays(attribflag_pos)
		gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 0, gl.Ptr(coords))
		gl.DrawArrays(gl.TRIANGLE_FAN, 0, len(coords)/2-1)
	}
}