Пример #1
0
// MakeTextShader creates a new shader program
// for text rendering purposes.
func MakeTextShader() gl.Program {
	vertSource := loadTextVertexShader()
	fragSource := loadTextFragmentShader()

	return glh.NewProgram(
		glh.Shader{Type: gl.VERTEX_SHADER, Program: string(vertSource)},
		glh.Shader{Type: gl.FRAGMENT_SHADER, Program: string(fragSource)},
	)
}
Пример #2
0
func MakeProgram(vertFname, fragFname string) gl.Program {
	vertSource, err := ioutil.ReadFile(vertFname)
	if err != nil {
		panic(err)
	}

	fragSource, err := ioutil.ReadFile(fragFname)
	if err != nil {
		panic(err)
	}
	return glh.NewProgram(glh.Shader{gl.VERTEX_SHADER, string(vertSource)}, glh.Shader{gl.FRAGMENT_SHADER, string(fragSource)})
}
Пример #3
0
func shaderLoad() {
	shaderUnload()

	vssource, _ := ioutil.ReadFile("data/shaders/vs_zdistance.glsl")
	fssource, _ := ioutil.ReadFile("data/shaders/fs_zdistance.glsl")
	fsShader := glh.Shader{gl.FRAGMENT_SHADER, string(fssource)}
	vsShader := glh.Shader{gl.VERTEX_SHADER, string(vssource)}
	raytraceProgram = glh.NewProgram(vsShader, fsShader)
	raytraceProgram.Use()

	mInput = raytraceProgram.GetUniformLocation("M")
	vInput = raytraceProgram.GetUniformLocation("V")
	pInput = raytraceProgram.GetUniformLocation("P")

	vssource, _ = ioutil.ReadFile("data/shaders/vs.glsl")
	fssource, _ = ioutil.ReadFile("data/shaders/fs_compose.glsl")
	fsShader = glh.Shader{gl.FRAGMENT_SHADER, string(fssource)}
	vsShader = glh.Shader{gl.VERTEX_SHADER, string(vssource)}
	composeProgram = glh.NewProgram(vsShader, fsShader)
	composeProgram.Use()

	mInputC = composeProgram.GetUniformLocation("M")
	vInputC = composeProgram.GetUniformLocation("V")
	pInputC = composeProgram.GetUniformLocation("P")
	frontTextureInput = composeProgram.GetUniformLocation("frontTexture")
	backTextureInput = composeProgram.GetUniformLocation("backTexture")
	volumeTextureInput = composeProgram.GetUniformLocation("volumeData")
	palleteTextureInput = composeProgram.GetUniformLocation("palleteData")
	composeProgram.Use()
	frontTextureInput.Uniform1i(1)
	backTextureInput.Uniform1i(0)
	volumeTextureInput.Uniform1i(2)
	palleteTextureInput.Uniform1i(3)

	programLoaded = true

}
Пример #4
0
func NewGlDrawer(vshader, fshader string) *GlDrawer {
	vao := gl.GenVertexArray()
	vao.Bind()

	vbo := gl.GenBuffer()
	vbo.Bind(gl.ARRAY_BUFFER)

	ebo := gl.GenBuffer()
	ebo.Bind(gl.ELEMENT_ARRAY_BUFFER)

	vsh := ShaderFromFile(gl.VERTEX_SHADER, vshader)
	fsh := ShaderFromFile(gl.FRAGMENT_SHADER, fshader)

	program := glh.NewProgram(vsh, fsh)
	program.BindFragDataLocation(0, "outColor")
	program.Use()

	return &GlDrawer{
		program: program,
		vao:     vao,
		vbo:     vbo,
		ebo:     ebo,
	}
}