MCPcopy
hub / github.com/g3n/engine / NewSprite

Function NewSprite

graphic/sprite.go:22–56  ·  view source on GitHub ↗

NewSprite creates and returns a pointer to a sprite with the specified dimensions and material

(width, height float32, imat material.IMaterial)

Source from the content-addressed store, hash-verified

20
21// NewSprite creates and returns a pointer to a sprite with the specified dimensions and material
22func 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.
59func (s *Sprite) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) {

Callers

nothing calls this directly

Calls 11

AppendMethod · 0.95
AppendMethod · 0.95
SetIndicesMethod · 0.95
AddVBOMethod · 0.95
NewGeometryFunction · 0.92
NewArrayF32Function · 0.92
NewArrayU32Function · 0.92
NewVBOFunction · 0.92
AddAttribMethod · 0.45
InitMethod · 0.45
AddMaterialMethod · 0.45

Tested by

no test coverage detected