예제 #1
0
func glSetupShaderProg(shader *shaderProg, unif bool) {
	var glStatus gl.Int
	shader.glFragShader = gl.CreateShader(gl.FRAGMENT_SHADER)
	glSetShaderSource(shader.glFragShader, shader.srcFrag)
	gl.CompileShader(shader.glFragShader)
	if gl.GetShaderiv(shader.glFragShader, gl.COMPILE_STATUS, &glStatus); glStatus == 0 {
		panic("Frag shader compile error: " + glGetInfoLog(shader.glFragShader, true))
	}
	shader.glVertShader = gl.CreateShader(gl.VERTEX_SHADER)
	glSetShaderSource(shader.glVertShader, shader.srcVert)
	gl.CompileShader(shader.glVertShader)
	if gl.GetShaderiv(shader.glVertShader, gl.COMPILE_STATUS, &glStatus); glStatus == 0 {
		panic("Vert shader compile error: " + glGetInfoLog(shader.glFragShader, true))
	}
	shader.glProg = gl.CreateProgram()
	gl.AttachShader(shader.glProg, shader.glFragShader)
	gl.AttachShader(shader.glProg, shader.glVertShader)
	gl.LinkProgram(shader.glProg)
	if gl.GetProgramiv(shader.glProg, gl.LINK_STATUS, &glStatus); glStatus == 0 {
		panic("Shader program link error: " + glGetInfoLog(shader.glProg, false))
	}
	shader.attrPos = glGetLocation(shader.glProg, "aPos", true)
	if unif {
		shader.unifTex = gl.Int(glGetLocation(shader.glProg, "uTex", false))
	}
}
예제 #2
0
func AddCanvas(newVerts []gl.Float, width, height int, retroFactor float64) int {
	var canvas canvas.Canvas
	var l int
	canvas.TmpTex = TmpTexes[TmpTexIndex]
	canvas.Index = gl.Int(len(Canvases))
	canvas.Init(width, height, retroFactor)
	canvas.Shaders = Shaders
	Canvases = append(Canvases, &canvas)
	if l = len(Canvases); l == 1 {
		Canvas0 = &canvas
	}
	return l
}
예제 #3
0
파일: main.go 프로젝트: vron/fm
func display() {
	gl.ClearColor(0.19, 0.19, 0.21, 0)
	gl.ClearDepth(1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(theProgram)

	// Temporarily set the cam t clip
	id := gls.Identity()

	trans := getLookAtMatrix()
	//	log.Println(trans)
	gls.UniformMatrix4fv(wtcm_unif, 1, false, trans)

	gls.UniformMatrix4fv(mtwm_unif, 1, false, id)

	// And here we do the actual rendering

	// Generate a name for vufferobj and store it
	gl.GenBuffers(1, &positionBufferObject)
	// Bind it to a target
	gl.BindBuffer(gl.ARRAY_BUFFER, positionBufferObject)

	// Conver all nodes to a long array of vertexes!
	i := 0
	// TODO: Fix this, based on 4 per eleemnts
	vpos := make([]float32, len(elements)*4*4)
	elms := make(map[uint32]mS, len(elements))
	// Note that the order here is undefined!
	ii := 0
	for k, v := range elements {
		elms[k] = mS{ii, len(v.Nodes())}
		for _, vv := range v.Nodes() {
			ii++
			vpos[i] = float32(nodes[vv][0])
			i++
			vpos[i] = float32(nodes[vv][1])
			i++
			vpos[i] = float32(nodes[vv][2])
			i++
			vpos[i] = 1.0
			i++
		}
	}
	/*
		for _, v := range nodes {
			vpos[i] = float32(v[0])
			i++
			vpos[i] = float32(v[1])
			i++
			vpos[i] = float32(v[2])
			i++
		}
	*/
	gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(32/8*len(vpos)), (gl.Pointer)(&vpos[0]), gl.STATIC_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, positionBufferObject)
	gl.EnableVertexAttribArray(0)
	gl.VertexAttribPointer(0, 4, gl.FLOAT, gl.FALSE, 0, (gl.Pointer)(nil))

	/*	for _,v := range elms {

		}
	*/
	for _, v := range elms {
		gl.DrawArrays(gl.LINE_LOOP, gl.Int(v.Start), gl.Sizei(v.Length))
	}

	// Draw Coordinate acis
	/*for i := 9; i < 9+2*5; i += 2 {
		gl.DrawArrays(gl.LINE_STRIP, gl.Int(i), 2)
	}*/
}