Exemple #1
0
func (vb *VertexBuffer) Render(position Point3) {
	gl.PushMatrix()
	gl.Translated(
		gl.Double(position.X),
		gl.Double(position.Y),
		gl.Double(position.Z))

	gl.VertexPointer(
		gl.Int(3),
		gl.DOUBLE,
		0,
		gl.Pointer(&vb.VertexData[0]))
	gl.ColorPointer(
		gl.Int(4),
		gl.DOUBLE,
		0,
		gl.Pointer(&vb.ColorData[0]))
	gl.TexCoordPointer(
		gl.Int(2),
		gl.DOUBLE,
		0,
		gl.Pointer(&vb.TexCoordData[0]))

	for i := range vb.RenderSteps {
		rs := &vb.RenderSteps[i]
		gl.DrawElements(
			rs.Mode,
			gl.Sizei(len(rs.Indices)),
			gl.UNSIGNED_INT,
			gl.Pointer(&rs.Indices[0]))
	}
	gl.PopMatrix()
}
Exemple #2
0
func glInit(width, height int) {
	gl.Init()
	gl.Enable(gl.TEXTURE_2D)
	gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1)
	gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, gl.Double(width), gl.Double(height), 0, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.EnableClientState(gl.VERTEX_ARRAY)
	gl.EnableClientState(gl.COLOR_ARRAY)
	gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
	gl.VertexPointer(2, gl.FLOAT, 0, gl.Pointer(&vs[0]))
	gl.ColorPointer(3, gl.UNSIGNED_BYTE, 0, gl.Pointer(&cs[0]))
	gl.TexCoordPointer(2, gl.FLOAT, 0, gl.Pointer(&ts[0]))
}