Esempio n. 1
0
func (polyline *polyLine) drawTriangles(is_looping bool) {
	var overdraw []mgl32.Vec2
	if polyline.overdraw {
		overdraw = polyline.renderOverdraw(is_looping)
	}

	numindices := int(math.Max(float64(len(polyline.vertices)/4), float64(len(overdraw)/4)))
	indices := newAltQuadIndices(numindices)

	prepareDraw(nil)
	bindTexture(gl_state.defaultTexture)
	useVertexAttribArrays(attribflag_pos)
	gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 0, gl.Ptr(polyline.vertices))
	gl.DrawElements(gl.TRIANGLES, (len(polyline.vertices)/4)*6, gl.UNSIGNED_SHORT, gl.Ptr(indices))
	if polyline.overdraw {
		c := GetColor()
		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.DrawElements(gl.TRIANGLES, (len(overdraw)/4)*6, gl.UNSIGNED_SHORT, gl.Ptr(indices))
		SetColorC(c)
	}

	indices.Release()
}
Esempio n. 2
0
// 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)
}
Esempio n. 3
0
// 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)
}
Esempio n. 4
0
// 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)
	}
}
Esempio n. 5
0
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)
	}
}
Esempio n. 6
0
File: mesh.go Progetto: tanema/amore
// bindEnabledAttributes will take the enabled attrib flags and use them to enable
// all the attributes that we need.
func (mesh *Mesh) bindEnabledAttributes() {
	useVertexAttribArrays(mesh.enabledattribs)

	mesh.vbo.bind()
	defer mesh.vbo.unbind()

	offset := 0
	if (mesh.enabledattribs & attribflag_pos) > 0 {
		gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, mesh.vertexStride*4, gl.PtrOffset(offset))
		offset += 2 * 4
	}
	if (mesh.enabledattribs & attribflag_texcoord) > 0 {
		gl.VertexAttribPointer(attrib_texcoord, 2, gl.FLOAT, false, mesh.vertexStride*4, gl.PtrOffset(offset))
		offset += 2 * 4
	}
	if (mesh.enabledattribs & attribflag_color) > 0 {
		gl.VertexAttribPointer(attrib_color, 4, gl.FLOAT, false, mesh.vertexStride*4, gl.PtrOffset(offset))
	}
}
Esempio n. 7
0
// 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 (sprite_batch *SpriteBatch) Draw(args ...float32) {
	if sprite_batch.count == 0 {
		return
	}

	prepareDraw(generateModelMatFromArgs(args))
	bindTexture(sprite_batch.texture.getHandle())
	useVertexAttribArrays(attribflag_pos | attribflag_texcoord | attribflag_color)

	sprite_batch.array_buf.bind()
	defer sprite_batch.array_buf.unbind()

	gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 8*4, gl.PtrOffset(0))
	gl.VertexAttribPointer(attrib_texcoord, 2, gl.FLOAT, false, 8*4, gl.PtrOffset(2*4))
	gl.VertexAttribPointer(attrib_color, 4, gl.FLOAT, false, 8*4, gl.PtrOffset(4*4))

	min, max := sprite_batch.GetDrawRange()
	sprite_batch.quad_indices.drawElements(gl.TRIANGLES, min, max-min+1)
}
Esempio n. 8
0
// 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)
	}
}
Esempio n. 9
0
// 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)
	}
}