Esempio n. 1
0
func initResources() (uint32, int32) {
	vs := CreateShader("triangle.v.glsl", gl.VERTEX_SHADER)
	fs := CreateShader("triangle.f.glsl", gl.FRAGMENT_SHADER)

	var linkOk int32
	program := gl.CreateProgram()
	gl.AttachShader(program, vs)
	gl.AttachShader(program, fs)
	gl.LinkProgram(program)
	gl.GetProgramiv(program, gl.LINK_STATUS, &linkOk)
	if linkOk == 0 {
		log.Fatal("gl.LinkProgram")
	}

	gl.GenBuffers(1, &vboTriangle)
	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangle)
	gl.BufferData(gl.ARRAY_BUFFER, 4*len(triangleVertices), gl.Ptr(triangleVertices), gl.STATIC_DRAW)

	attribName := "coord2d\x00"
	attribCoord2d := gl.GetAttribLocation(program, gl.Str(attribName))
	if attribCoord2d == -1 {
		log.Fatal("failed to bind attribute")
	}
	return program, attribCoord2d
}
Esempio n. 2
0
func initResources() uint32 {
	vs := CreateShader("triangle.v.glsl", gl.VERTEX_SHADER)
	fs := CreateShader("triangle.f.glsl", gl.FRAGMENT_SHADER)

	var linkOk int32
	program := gl.CreateProgram()
	gl.AttachShader(program, vs)
	gl.AttachShader(program, fs)
	gl.LinkProgram(program)
	gl.GetProgramiv(program, gl.LINK_STATUS, &linkOk)
	if linkOk == 0 {
		log.Fatal("gl.LinkProgram")
	}

	gl.GenBuffers(1, &vboTriangle)
	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangle)
	gl.BufferData(gl.ARRAY_BUFFER, floatSize*len(triangleAttributes), gl.Ptr(triangleAttributes), gl.STATIC_DRAW)

	attributeCoord2d = gl.GetAttribLocation(program, gl.Str("coord2d\x00"))
	if attributeCoord2d == -1 {
		log.Fatal("failed to bind attribute")
	}

	attributeVColor = gl.GetAttribLocation(program, gl.Str("v_color\x00"))
	if attributeVColor == -1 {
		log.Fatal("could not bind attribute v_color")
	}

	uniformFade = gl.GetUniformLocation(program, gl.Str("fade\x00"))
	if uniformFade == -1 {
		log.Fatal("could not bind uniform fade")
	}

	return program
}
Esempio n. 3
0
func (v *Video) initGL() {
	if err := gl.Init(); err != nil {
		panic(err)
	}

	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)

	v.prog = createProgram(vertShaderSrcDef, fragShaderSrcDef)
	posAttrib := uint32(gl.GetAttribLocation(v.prog, gl.Str("vPosition"+"\x00")))
	texCoordAttr := uint32(gl.GetAttribLocation(v.prog, gl.Str("vTexCoord"+"\x00")))
	v.textureUni = gl.GetAttribLocation(v.prog, gl.Str("texture"+"\x00"))

	var texture uint32
	gl.GenTextures(1, &texture)
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, texture)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	gl.UseProgram(v.prog)
	gl.EnableVertexAttribArray(posAttrib)
	gl.EnableVertexAttribArray(texCoordAttr)
	//posAttrib.EnableArray()
	//texCoordAttr.EnableArray()

	var vbo uint32
	gl.GenBuffers(1, &vbo)
	gl.BindBuffer(gl.ARRAY_BUFFER, vbo)
	verts := []float32{-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0}
	gl.BufferData(gl.ARRAY_BUFFER, len(verts)*int(unsafe.Sizeof(verts[0])), gl.Ptr(verts), gl.STATIC_DRAW)

	var textCoorBuf uint32
	gl.GenBuffers(1, &textCoorBuf)
	gl.BindBuffer(gl.ARRAY_BUFFER, textCoorBuf)
	texVerts := []float32{0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}
	gl.BufferData(gl.ARRAY_BUFFER, len(texVerts)*int(unsafe.Sizeof(texVerts[0])), gl.Ptr(texVerts), gl.STATIC_DRAW)

	gl.VertexAttribPointer(posAttrib, 2, gl.FLOAT, false, 0, gl.PtrOffset(0))
	gl.VertexAttribPointer(texCoordAttr, 2, gl.FLOAT, false, 0, gl.PtrOffset(0))
	//posAttrib.AttribPointer(2, gl.FLOAT, false, 0, uintptr(0))
	//texCoordAttr.AttribPointer(2, gl.FLOAT, false, 0, uintptr(0))
}
Esempio n. 4
0
File: vbo.go Progetto: fmd/gogol
func NewVbo(length int) *Vbo {
	v := &Vbo{
		Vertices: make([]float32, length),
	}

	gl.GenBuffers(1, &v.Id)
	gl.BindBuffer(gl.ARRAY_BUFFER, v.Id)
	gl.BufferData(gl.ARRAY_BUFFER, length*FloatSize, gl.Ptr(v.Vertices), gl.STATIC_DRAW)
	return v
}
Esempio n. 5
0
func newMultitouchTestBoxWidget(pos mgl64.Vec2, color int) MultitouchTestBoxWidget {
	var buffer uint32
	gl.GenBuffers(1, &buffer)
	gl.BindBuffer(gl.ARRAY_BUFFER, buffer)
	vertices := []float32{
		0, 0,
		0, 200,
		200, 200,
		200, 0,
	}
	gl.BufferData(gl.ARRAY_BUFFER, len(vertices)*4, gl.Ptr(vertices), gl.STATIC_DRAW)

	return MultitouchTestBoxWidget{pos: pos, color: color, buffer: buffer}
}
Esempio n. 6
0
func NewBuffer(idata interface{}, opts ...BufferOption) (*Buffer, error) {
	opt := bufferOption{
		freq:      STATIC,
		nature:    DRAW,
		bindpoint: gl.ARRAY_BUFFER,
	}
	for _, o := range opts {
		o(&opt)
	}
	var usage uint32
	switch int(opt.freq) | int(opt.nature) {
	case int(STATIC) | int(DRAW):
		usage = gl.STATIC_DRAW
	case int(STATIC) | int(READ):
		usage = gl.STATIC_READ
	case int(STATIC) | int(COPY):
		usage = gl.STATIC_COPY
	case int(STREAM) | int(DRAW):
		usage = gl.STREAM_DRAW
	case int(STREAM) | int(READ):
		usage = gl.STREAM_READ
	case int(STREAM) | int(COPY):
		usage = gl.STREAM_COPY
	case int(DYNAMIC) | int(DRAW):
		usage = gl.DYNAMIC_DRAW
	case int(DYNAMIC) | int(READ):
		usage = gl.DYNAMIC_READ
	case int(DYNAMIC) | int(COPY):
		usage = gl.DYNAMIC_COPY
	default:
		panic(fmt.Errorf("Could not resolve buffer usage from options"))
	}
	data, err := resolveData(idata)
	if err != nil {
		return nil, err
	}

	var id uint32
	gl.GenBuffers(1, &id)

	buffer := &Buffer{
		id:        id,
		data:      data.iDataDesc,
		usage:     usage,
		bindpoint: opt.bindpoint,
	}

	buffer.Upload(idata)
	return buffer, nil
}
Esempio n. 7
0
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage BufferUsage) Buffer {
	var b uint32
	gl.GenBuffers(1, &b)
	gl.BindBuffer(uint32(bufferType), b)
	size := 0
	ptr := v
	switch v := v.(type) {
	case int:
		size = v
		ptr = nil
	case []uint16:
		size = 2 * len(v)
	case []float32:
		size = 4 * len(v)
	default:
		panic("not reach")
	}
	gl.BufferData(uint32(bufferType), size, gl.Ptr(ptr), uint32(bufferUsage))
	return Buffer(b)
}
Esempio n. 8
0
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage BufferUsage) Buffer {
	var buffer Buffer
	_ = c.runOnContextThread(func() error {
		var b uint32
		gl.GenBuffers(1, &b)
		gl.BindBuffer(uint32(bufferType), b)
		switch v := v.(type) {
		case int:
			gl.BufferData(uint32(bufferType), v, nil, uint32(bufferUsage))
		case []uint16:
			// TODO: What about the endianness?
			gl.BufferData(uint32(bufferType), 2*len(v), gl.Ptr(v), uint32(bufferUsage))
		default:
			panic("not reach")
		}
		buffer = Buffer(b)
		return nil
	})
	return buffer
}
Esempio n. 9
0
// CreateBuffer creates a buffer object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenBuffers.xhtml
func CreateBuffer() Buffer {
	var b Buffer
	gl.GenBuffers(1, &b.Value)
	return b
}
Esempio n. 10
0
func (c *Context) CreateBuffer() *Buffer {
	var loc uint32
	gl.GenBuffers(1, &loc)
	return &Buffer{loc}
}
Esempio n. 11
0
func (m *Mesh) initMeshData() {
	gl.GenBuffers(1, &m.vbo)
	gl.GenBuffers(1, &m.ibo)
	m.size = 0
}
Esempio n. 12
0
File: gg.go Progetto: dmac/gg
func (*backend) CreateBuffer() *gg.Buffer {
	var b uint32
	gl.GenBuffers(1, &b)
	return &gg.Buffer{Value: b}
}