Пример #1
0
func initTriangleShaders() error {
	var v gl.GLfloat = 0.0
	data = []gl.GLfloat{
		0.0, 0.8,
		-0.8, -0.8,
		0.8, -0.8,
	}

	vboTri = gl.GenBuffer()
	// glGenBuffer(
	// specify the current target buffer
	vboTri.Bind(gl.ARRAY_BUFFER)

	// create and init a buffer data
	gl.BufferData(gl.ARRAY_BUFFER, len(data)*int(unsafe.Sizeof(v)), data, gl.STATIC_DRAW)

	p, e := createProgram("triangle1.v", "triangle1.f")

	if e != nil {
		return e
	}

	program = p
	return nil
}
Пример #2
0
func (v *Vbo) Create(usage gl.GLenum) {
	v.usage = usage
	if v.created {
		return
	}
	if len(v.P) == 0 {
		panic("No position data specified")
	}
	sizep := len(v.P) * 3 * 8 / 2
	sizen := len(v.N) * 3 * 8 / 2
	sizet := len(v.T) * 2 * 8 / 2
	sizei := len(v.I) * 1 * 4
	//refill in simpler slices:
	v.p = make([]float32, 0, len(v.P)*3)
	v.n = make([]float32, 0, len(v.N)*3)
	v.t = make([]float32, 0, len(v.T)*2)
	for _, x := range v.P {
		v.p = append(v.p, float32(x.X), float32(x.Y), float32(x.Z))
	}
	for _, x := range v.N {
		v.n = append(v.n, float32(x.X), float32(x.Y), float32(x.Z))
	}
	for _, x := range v.T {
		v.t = append(v.t, float32(x.X), float32(x.Y))
	}
	if v.idp == 0 {
		v.idp = gl.GenBuffer()
	}
	if v.idn == 0 {
		v.idn = gl.GenBuffer()
	}
	if v.idt == 0 {
		v.idt = gl.GenBuffer()
	}
	if v.idi == 0 {
		v.idi = gl.GenBuffer()
	}

	if v.idp*v.idn*v.idt*v.idi == 0 {
		panic("Some buffer could not be generated")
	}
	nilSlc := []int32{0}
	if len(v.I) > 0 {
		v.idi.Bind(gl.ELEMENT_ARRAY_BUFFER)
		gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, sizei, nilSlc, v.usage)
		gl.BufferSubData(gl.ELEMENT_ARRAY_BUFFER, 0, sizei, nilSlc)
		v.speci = true
	}
	UnbindIbo()
	if len(v.P) > 0 {
		v.idp.Bind(gl.ARRAY_BUFFER)
		gl.BufferData(gl.ARRAY_BUFFER, sizep, nilSlc, v.usage)
		gl.BufferSubData(gl.ARRAY_BUFFER, 0, sizep, (&v.p[0]))
		v.specp = true
	}
	if len(v.N) > 0 {
		v.idn.Bind(gl.ARRAY_BUFFER)
		gl.BufferData(gl.ARRAY_BUFFER, sizen, nilSlc, v.usage)
		gl.BufferSubData(gl.ARRAY_BUFFER, 0, sizen, (&v.n[0]))
		v.specn = true
	}
	if len(v.T) > 0 {
		v.idt.Bind(gl.ARRAY_BUFFER)
		gl.BufferData(gl.ARRAY_BUFFER, sizet, nilSlc, v.usage)
		gl.BufferSubData(gl.ARRAY_BUFFER, 0, sizet, (&v.t[0]))
		v.spect = true
	}
	UnbindVbo()
	v.created = true
}