func NewSprite(vertices []float32, program *gg.Program, texture *gg.Texture) (*Sprite, error) { buf := new(bytes.Buffer) if err := binary.Write(buf, binary.LittleEndian, vertices); err != nil { return nil, err } pvbo := gg.CreateBuffer() gg.BindBuffer(gg.ARRAY_BUFFER, pvbo) gg.BufferData(gg.ARRAY_BUFFER, buf.Bytes(), gg.STATIC_DRAW) texVertices := []float32{ 0, 0, 0, 1, 1, 1, 1, 0, } buf.Reset() if err := binary.Write(buf, binary.LittleEndian, texVertices); err != nil { return nil, err } tvbo := gg.CreateBuffer() gg.BindBuffer(gg.ARRAY_BUFFER, tvbo) gg.BufferData(gg.ARRAY_BUFFER, buf.Bytes(), gg.STATIC_DRAW) return &Sprite{ pvbo: pvbo, tvbo: tvbo, program: program, tex: texture, }, nil }
func NewTriangle(vertices []float32, program *gg.Program) (*Triangle, error) { buf := new(bytes.Buffer) if err := binary.Write(buf, binary.LittleEndian, vertices); err != nil { return nil, err } vbo := gg.CreateBuffer() gg.BindBuffer(gg.ARRAY_BUFFER, vbo) gg.BufferData(gg.ARRAY_BUFFER, buf.Bytes(), gg.STATIC_DRAW) return &Triangle{ vbo: vbo, program: program, }, nil }
func NewSprite(width, height float32, program *gg.Program, texture *gg.Texture) *Sprite { s := &Sprite{ scale: 1, width: width, height: height, tex: texture, program: program, } pvertices := []float32{ 0, 0, 0, 0, s.height, 0, s.width, s.height, 0, s.width, 0, 0, } buf := new(bytes.Buffer) if err := binary.Write(buf, binary.LittleEndian, pvertices); err != nil { panic(err) } s.pbuf = gg.CreateBuffer() gg.BindBuffer(gg.ARRAY_BUFFER, s.pbuf) gg.BufferData(gg.ARRAY_BUFFER, buf.Bytes(), gg.STATIC_DRAW) tvertices := []float32{ 0, 0, 0, 1, 1, 1, 1, 0, } buf.Reset() if err := binary.Write(buf, binary.LittleEndian, tvertices); err != nil { panic(err) } s.tbuf = gg.CreateBuffer() gg.BindBuffer(gg.ARRAY_BUFFER, s.tbuf) gg.BufferData(gg.ARRAY_BUFFER, buf.Bytes(), gg.STATIC_DRAW) return s }