示例#1
0
func createProgram(shdrList []gl.Shader) gl.Program {
	prog := gl.CreateProgram()

	for _, shd := range shdrList {
		prog.AttachShader(shd)
	}

	prog.BindFragDataLocation(0, "outputColor")
	fmt.Println("frag data:", gl.GetError())
	prog.Link()
	status := prog.Get(gl.LINK_STATUS)
	if status == gl.FALSE {
		log := prog.GetInfoLog()
		panic("linker: " + log)
	}

	for _, shd := range shdrList {
		prog.DetachShader(shd)
	}

	return prog
}
示例#2
0
func initGraphics() {
	//opengl stuff
	if gl.Init() != 0 {
		panic("gl error")
	}

	lines = make([]line, 0, 10)
	ents = make([]ent, 0, 10)

	near = 1
	far = 100

	mu = sync.Mutex{}

	fmt.Println("opengl stuff")
	fmt.Println(gl.GetString(gl.VERSION))

	cameraMatrix[0] = 0.001
	cameraMatrix[5] = 0.001
	cameraMatrix[10] = 1
	cameraMatrix[15] = 1

	OrthProj(true)

	vertShdr := `
#version 150

uniform mat4 viewMatrix, projMatrix;

in vec4 Position;
 
void main()
{
gl_Position = projMatrix * viewMatrix * Position;
}`

	fragShdr := `
#version 150

uniform vec4 baseColor;

out vec4 outputColor;

void main()
{
	outputColor = baseColor;
}`

	fmt.Println(gl.GetError())
	fmt.Println("shader")

	shdrList := []gl.Shader{
		createShader(gl.VERTEX_SHADER, vertShdr),
		createShader(gl.FRAGMENT_SHADER, fragShdr),
	}
	fmt.Println(gl.GetError())
	fmt.Println("prog")
	uniColor.prog = createProgram(shdrList)
	fmt.Println("1", gl.GetError())
	uniColor.vLoc = uniColor.prog.GetAttribLocation("Position")
	uniColor.cLoc = uniColor.prog.GetUniformLocation("baseColor")
	uniColor.viewLoc = uniColor.prog.GetUniformLocation("viewMatrix")
	uniColor.projLoc = uniColor.prog.GetUniformLocation("projMatrix")

	fmt.Println(".", gl.GetError())
	for _, shd := range shdrList {
		shd.Delete()
	}

	fmt.Println(".", gl.GetError())
	fmt.Println("done")

	gl.ClearColor(0.5, 0.5, 0.5, 0.5)

	initMeshes()
	fmt.Println("post init:", gl.GetError())
}