예제 #1
0
파일: gltoy.go 프로젝트: shogg/gltoy
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("dist-field-raycaster.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())
	}

	prg.Use()
}
예제 #2
0
파일: shader.go 프로젝트: simonz05/draw
func loadShader(typ gl.GLenum, filename string) (gl.Shader, error) {
	if !strings.HasPrefix(filename, ".glsl") {
		filename = filename + ".glsl"
	}

	src, e := ioutil.ReadFile(filename)

	if e != nil {
		logger.Println("read file:", e.Error())
		return 0, e
	}

	//logger.Print(filename,"\n", string(src))
	s := gl.CreateShader(typ)
	s.Source(string(src))
	s.Compile()

	if s.Get(gl.COMPILE_STATUS) != gl.TRUE {
		e := errors.New(s.GetInfoLog())
		s.Delete()
		return 0, e
	}

	return s, nil
}
예제 #3
0
func NewShader(isvert bool) *Shader {
	type_ := gl.GLenum(gl.FRAGMENT_SHADER)
	if isvert {
		type_ = gl.GLenum(gl.VERTEX_SHADER)
	}
	id := gl.CreateShader(type_)
	sh := &Shader{id, isvert}
	return sh
}