Exemple #1
0
func newProgram() gl.Program {

	vs := `
		uniform float[] foo;
		attribute int bar;

		void main()
		{
			gl_Position = gl_Vertex * foo[0] * bar;
		}`

	fs := `
		void main()
		{
			gl_FragColor = vec4(1.0);
		}`

	// vertex shader
	vshader := gl.CreateShader(gl.VERTEX_SHADER)
	vshader.Source(vs)
	vshader.Compile()
	if vshader.Get(gl.COMPILE_STATUS) != gl.TRUE {
		panic("vertex shader error: " + vshader.GetInfoLog())
	}

	// fragment shader
	fshader := gl.CreateShader(gl.FRAGMENT_SHADER)
	fshader.Source(fs)
	fshader.Compile()
	if fshader.Get(gl.COMPILE_STATUS) != gl.TRUE {
		panic("fragment shader error: " + fshader.GetInfoLog())
	}

	// program
	prg := gl.CreateProgram()
	prg.AttachShader(vshader)
	prg.AttachShader(fshader)
	prg.Link()
	if prg.Get(gl.LINK_STATUS) != gl.TRUE {
		panic("linker error: " + prg.GetInfoLog())
	}

	prg.Use()
	return prg
}
Exemple #2
0
func initShaders() {

	// Compile vertex shader
	vshader := gl.CreateShader(gl.VERTEX_SHADER)
	vshader.Source(vertexShaderSrc)
	vshader.Compile()
	if vshader.Get(gl.COMPILE_STATUS) != gl.TRUE {
		panic("vertex shader compile error: " + vshader.GetInfoLog())
	}

	// Compile fragment shader
	fshader := gl.CreateShader(gl.FRAGMENT_SHADER)
	fragSrc, err := readShader("vox.glsl")
	if err != nil {
		panic(err)
	}

	fshader.Source(fragSrc)
	fshader.Compile()
	if fshader.Get(gl.COMPILE_STATUS) != gl.TRUE {
		panic("fragment shader compile error: " + fshader.GetInfoLog())
	}

	// Link program
	prg = gl.CreateProgram()
	prg.AttachShader(vshader)
	prg.AttachShader(fshader)
	prg.Link()
	if prg.Get(gl.LINK_STATUS) != gl.TRUE {
		panic("linker error: " + prg.GetInfoLog())
	}

	fmt.Println(prg.GetInfoLog())

	prg.Use()
}