コード例 #1
0
ファイル: environment.go プロジェクト: dskinner/material
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)
}
コード例 #2
0
ファイル: material.go プロジェクト: lamproae/material
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
}
コード例 #3
0
ファイル: waveform.go プロジェクト: dskinner/snd
// TODO just how many samples do we want/need to display something useful?
func NewWaveform(ctx gl.Context, n int, in snd.Sound) (*Waveform, error) {
	wf := &Waveform{Material: env.NewMaterial(ctx), Sound: in}
	wf.Drawer = wf.Draw

	wf.outs = make([][]float64, n)
	for i := range wf.outs {
		wf.outs[i] = make([]float64, in.BufferLen()*in.Channels())
	}
	wf.samples = make([]float64, in.BufferLen()*in.Channels()*n)
	wf.verts = make([]float32, len(wf.samples)*2)

	wf.prg.CreateAndLink(ctx,
		glutil.ShaderAsset(gl.VERTEX_SHADER, "basic-vert.glsl"),
		glutil.ShaderAsset(gl.FRAGMENT_SHADER, "basic-frag.glsl"))

	wf.vbuf = glutil.NewFloatBuffer(ctx, wf.verts, gl.STREAM_DRAW)
	wf.uw = wf.prg.Uniform(ctx, "world")
	wf.uv = wf.prg.Uniform(ctx, "view")
	wf.up = wf.prg.Uniform(ctx, "proj")
	wf.uc = wf.prg.Uniform(ctx, "color")
	wf.ap = wf.prg.Attrib(ctx, "position")
	return wf, nil
}