Ejemplo n.º 1
0
func (env *Environment) Load(ctx gl.Context) {
	env.prg.CreateAndLink(ctx,
		glutil.ShaderCompile(gl.VERTEX_SHADER, "env-vert.glsl", assets.VertexShader),
		glutil.ShaderCompile(gl.FRAGMENT_SHADER, "env-frag.glsl", assets.FragmentShader))

	env.uniforms.view = env.prg.Uniform(ctx, "view")
	env.uniforms.proj = env.prg.Uniform(ctx, "proj")
	env.uniforms.shadowColor = env.prg.Uniform(ctx, "shadowColor")
	env.uniforms.glyphs = env.prg.Uniform(ctx, "texglyph")
	env.uniforms.icons = env.prg.Uniform(ctx, "texicon")
	env.uniforms.glyphconf = env.prg.Uniform(ctx, "glyphconf")

	env.attribs.vertex = env.prg.Attrib(ctx, "vertex")
	env.attribs.color = env.prg.Attrib(ctx, "color")
	env.attribs.dist = env.prg.Attrib(ctx, "dist")
	env.attribs.texcoord = env.prg.Attrib(ctx, "texcoord")
	env.attribs.touch = env.prg.Attrib(ctx, "touch")

	env.buffers.indices = glutil.NewUintBuffer(ctx, []uint32{}, gl.STREAM_DRAW)
	env.buffers.verts = glutil.NewFloatBuffer(ctx, []float32{}, gl.STREAM_DRAW)
	env.buffers.colors = glutil.NewFloatBuffer(ctx, []float32{}, gl.STREAM_DRAW)
	env.buffers.dists = glutil.NewFloatBuffer(ctx, []float32{}, gl.STREAM_DRAW)
	env.buffers.texcoords = glutil.NewFloatBuffer(ctx, []float32{}, gl.STREAM_DRAW)
	env.buffers.touches = glutil.NewFloatBuffer(ctx, []float32{}, gl.STREAM_DRAW)
}
Ejemplo n.º 2
0
func New(ctx gl.Context, color Color) *Material {
	mtrl := &Material{
		BehaviorFlags: DescriptorRaised,
		icx:           -1,
		icy:           -1,
	}
	mtrl.cr, mtrl.cg, mtrl.cb, mtrl.ca = color.RGBA()

	// material has user-defined width and height, and precisely 1dp depth.
	mtrl.vbuf = glutil.NewFloatBuffer(ctx, []float32{
		0, 0, 0,
		0, 1, 0,
		1, 1, 0,
		1, 0, 0,
		0, 0, -1,
		0, 1, -1,
		1, 1, -1,
		1, 0, -1,
	}, gl.STATIC_DRAW)
	mtrl.ibuf = glutil.NewUintBuffer(ctx, []uint32{
		0, 2, 1, 0, 3, 2,
		2, 7, 6, 2, 3, 7,
		7, 3, 0, 7, 0, 4,
		4, 6, 7, 4, 5, 6,
		6, 1, 2, 6, 5, 1,
		1, 5, 4, 1, 4, 0,
	}, gl.STATIC_DRAW)

	n := float32(0.0234375)
	mtrl.uvbuf = glutil.NewFloatBuffer(ctx, []float32{
		0, n,
		0, 0,
		n, 0,
		n, n,
		0, n,
		0, 0,
		n, 0,
		n, n,
	}, gl.STATIC_DRAW)

	mtrl.reloadProgram(ctx)
	return mtrl
}