func (m Mesh) draw() { gl.EnableVertexAttribArray(0) gl.EnableVertexAttribArray(1) gl.EnableVertexAttribArray(2) if m.vbo == 0 { panic("attempt to set array buffer with VBO=0") } gl.BindBuffer(gl.ARRAY_BUFFER, m.vbo) gl.VertexAttribPointer(0, 3, gl.FLOAT, false, VertexSize*4, gl.PtrOffset(0)) gl.VertexAttribPointer(1, 2, gl.FLOAT, false, VertexSize*4, gl.PtrOffset(12)) gl.VertexAttribPointer(2, 3, gl.FLOAT, false, VertexSize*4, gl.PtrOffset(20)) if m.vbo == 0 { panic("attempt to set element array buffer with VBO=0") } gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, m.ibo) if m.size == 0 { panic("attempt to draw elements with mesh size = 0") } gl.DrawElements(gl.TRIANGLES, m.size, gl.UNSIGNED_INT, gl.PtrOffset(0)) gl.DisableVertexAttribArray(0) gl.DisableVertexAttribArray(1) gl.DisableVertexAttribArray(2) }
func (c *Context) VertexAttribPointer(p Program, location string, size int, dataType DataType, normalize bool, stride int, offset int) { _ = c.runOnContextThread(func() error { l := c.locationCache.GetAttribLocation(c, p, location) gl.VertexAttribPointer(uint32(l), int32(size), uint32(dataType), normalize, int32(stride), gl.PtrOffset(offset)) return nil }) }
func (c *Context) VertexAttribPointer(p Program, location string, signed bool, normalize bool, stride int, size int, v int) { l := GetAttribLocation(c, p, location) t := gl.SHORT if !signed { t = gl.UNSIGNED_SHORT } gl.VertexAttribPointer(uint32(l), int32(size), uint32(t), normalize, int32(stride), gl.PtrOffset(v)) }
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)) }
func (*backend) VertexAttribPointer(a *gg.Attribute, size int, typ gg.Enum, normalized bool, stride, offset int) { gl.VertexAttribPointer( a.Value.(uint32), int32(size), uint32(typ), normalized, int32(stride), gl.PtrOffset(offset), ) }
func onDisplay(program uint32) { coords := uint32(attributeCoord2d) vcolor := uint32(attributeVColor) gl.ClearColor(1.0, 1.0, 1.0, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT) gl.UseProgram(program) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Uniform1f(uniformFade, curFade) gl.EnableVertexAttribArray(coords) gl.EnableVertexAttribArray(vcolor) gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangle) gl.VertexAttribPointer(coords, 2, gl.FLOAT, false, 5*floatSize, nil) gl.VertexAttribPointer(vcolor, 3, gl.FLOAT, false, 5*floatSize, gl.PtrOffset(2*floatSize)) gl.DrawArrays(gl.TRIANGLES, 0, 3) gl.DisableVertexAttribArray(vcolor) gl.DisableVertexAttribArray(coords) }
func onDisplay(program uint32, coords uint32) { gl.ClearColor(1.0, 1.0, 1.0, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT) gl.UseProgram(program) gl.EnableVertexAttribArray(coords) triangleVertices := []float32{ 0.0, 0.8, -0.8, -0.8, 0.8, -0.8} gl.VertexAttribPointer(coords, 2, gl.FLOAT, false, 0, gl.Ptr(triangleVertices)) gl.DrawArrays(gl.TRIANGLES, 0, 3) gl.DisableVertexAttribArray(coords) }
func onDisplay(program uint32, coords uint32) { gl.ClearColor(1.0, 1.0, 1.0, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.UseProgram(program) gl.EnableVertexAttribArray(coords) gl.VertexAttribPointer(coords, 2, gl.FLOAT, false, 0, nil) gl.DrawArrays(gl.TRIANGLES, 0, 3) gl.DisableVertexAttribArray(coords) }
func (vao *VAO) Enable(elements int, buffer *Buffer, attrib Attrib, opts ...VAOOption) { opt := vaoOption{ stride: 0, offset: 0, normalize: false, } for _, o := range opts { o(&opt) } gl.BindVertexArray(vao.id) defer gl.BindVertexArray(0) gl.BindBuffer(gl.ARRAY_BUFFER, buffer.id) defer gl.BindBuffer(gl.ARRAY_BUFFER, 0) gl.EnableVertexAttribArray(attrib.Location()) gl.VertexAttribPointer( attrib.Location(), int32(elements), buffer.data.typ, opt.normalize, int32(opt.stride*buffer.data.siz), gl.PtrOffset(opt.offset*buffer.data.siz)) }
// VertexAttribPointer uses a bound buffer to define vertex attribute data. // // Direct use of VertexAttribPointer to load data into OpenGL is not // supported via the Go bindings. Instead, use BindBuffer with an // ARRAY_BUFFER and then fill it using BufferData. // // The size argument specifies the number of components per attribute, // between 1-4. The stride argument specifies the byte offset between // consecutive vertex attributes. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttribPointer.xhtml func VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride int, offset unsafe.Pointer) { gl.VertexAttribPointer(uint32(dst.Value), int32(size), uint32(ty), normalized, int32(stride), offset) }
// VertexAttribPointer uses a bound buffer to define vertex attribute data. // // Direct use of VertexAttribPointer to load data into OpenGL is not // supported via the Go bindings. Instead, use BindBuffer with an // ARRAY_BUFFER and then fill it using BufferData. // // The size argument specifies the number of components per attribute, // between 1-4. The stride argument specifies the byte offset between // consecutive vertex attributes. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttribPointer.xhtml func VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int) { gl.VertexAttribPointer(uint32(dst.Value), int32(size), uint32(ty), normalized, int32(stride), gl.PtrOffset(offset)) }
func (c *Context) VertexAttribPointer(index, size, typ int, normal bool, stride int, offset int) { gl.VertexAttribPointer(uint32(index), int32(size), uint32(typ), normal, int32(stride), gl.PtrOffset(offset)) }