NewSprite creates and returns a pointer to a sprite with the specified dimensions and material
(width, height float32, imat material.IMaterial)
| 20 | |
| 21 | // NewSprite creates and returns a pointer to a sprite with the specified dimensions and material |
| 22 | func NewSprite(width, height float32, imat material.IMaterial) *Sprite { |
| 23 | |
| 24 | s := new(Sprite) |
| 25 | |
| 26 | // Creates geometry |
| 27 | geom := geometry.NewGeometry() |
| 28 | w := width / 2 |
| 29 | h := height / 2 |
| 30 | |
| 31 | // Builds array with vertex positions and texture coordinates |
| 32 | positions := math32.NewArrayF32(0, 12) |
| 33 | positions.Append( |
| 34 | -w, -h, 0, 0, 0, |
| 35 | w, -h, 0, 1, 0, |
| 36 | w, h, 0, 1, 1, |
| 37 | -w, h, 0, 0, 1, |
| 38 | ) |
| 39 | // Builds array of indices |
| 40 | indices := math32.NewArrayU32(0, 6) |
| 41 | indices.Append(0, 1, 2, 0, 2, 3) |
| 42 | |
| 43 | // Set geometry buffers |
| 44 | geom.SetIndices(indices) |
| 45 | geom.AddVBO( |
| 46 | gls.NewVBO(positions). |
| 47 | AddAttrib(gls.VertexPosition). |
| 48 | AddAttrib(gls.VertexTexcoord), |
| 49 | ) |
| 50 | |
| 51 | s.Graphic.Init(s, geom, gls.TRIANGLES) |
| 52 | s.AddMaterial(s, imat, 0, 0) |
| 53 | |
| 54 | s.uniMVPM.Init("MVP") |
| 55 | return s |
| 56 | } |
| 57 | |
| 58 | // RenderSetup sets up the rendering of the sprite. |
| 59 | func (s *Sprite) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) { |
nothing calls this directly
no test coverage detected