Docs

Points

Inherits: Object
C++ type: Points

Description

Renders a collection of 3D billboard points (sprites). Each point is a camera-facing quad with an individual position, colour, size, rotation, and optional texture atlas frame. Useful for particle-like effects, star fields, or any situation where a large number of individually controlled sprites is needed.

Like Lines, Points uses a dynamic GPU buffer. Call updatePoints() after modifying point data.

Properties

Type Name Default Langs
unsigned int maxPoints 100 C++ | Lua
bool transparent false C++ | Lua
bool autoTransparency true C++ | Lua

Methods

Type Name Langs
bool load C++ | Lua
void addPoint C++ | Lua
PointData getPoint C++ | Lua
void updatePoint C++ | Lua
void removePoint C++ | Lua
bool isPointVisible C++ | Lua
void setPointVisible C++ | Lua
void updatePoints C++ | Lua
size_t getNumPoints C++ | Lua
void clearPoints C++ | Lua
void addSpriteFrame C++ | Lua
void removeSpriteFrame C++ | Lua
void setTexture C++ | Lua

Property details

maxPoints

  • Setter: void setMaxPoints(unsigned int maxPoints)
  • Getter: unsigned int getMaxPoints() const

Pre-allocates GPU buffer space for this many points.


transparent / autoTransparency

  • Setter/Getter: void setTransparent(bool) / bool isTransparent()
  • Setter/Getter: void setAutoTransparency(bool) / bool isAutoTransparency()

Controls transparency rendering for this points object. See Mesh for details.


Method details

load

  • bool load()

Initialises the GPU buffer. Must be called once.


addPoint

Several overloads:

  • void addPoint(PointData point)
  • void addPoint(Vector3 position)
  • void addPoint(Vector3 position, Vector4 color)
  • void addPoint(Vector3 position, Vector4 color, float size)
  • void addPoint(Vector3 position, Vector4 color, float size, float rotation)
  • void addPoint(Vector3 position, Vector4 color, float size, float rotation, Rect textureRect)

Adds a new billboard point. The most complete overload specifies all visual attributes.

Points stars(&scene);
stars.setTexture("particles/star.png");
stars.setMaxPoints(500);
stars.load();

for (int i = 0; i < 500; i++) {
    stars.addPoint(
        Vector3(rand() % 200 - 100, rand() % 200 - 100, 0),
        Vector4(1, 1, 1, 1), 2.0f
    );
}
stars.updatePoints();
local stars = Points(scene)
stars:setTexture("particles/star.png")
stars:setMaxPoints(500)
stars:load()

for i = 1, 500 do
    stars:addPoint(
        Vector3(math.random(-100, 100), math.random(-100, 100), 0),
        Vector4(1, 1, 1, 1), 2.0
    )
end
stars:updatePoints()

getPoint

Returns a reference to the PointData at index. Modify in-place then call updatePoints().


updatePoint

Overloads mirror addPoint(). Replaces data at index.


removePoint

  • void removePoint(size_t index)

Removes the point at index.


isPointVisible / setPointVisible

  • bool isPointVisible(size_t index)
  • void setPointVisible(size_t index, bool visible) const

Show or hide individual points without removing them from the buffer.


updatePoints

  • void updatePoints()

Uploads changes to the GPU. Must be called after any modification.


getNumPoints

  • size_t getNumPoints()

Returns the current number of points.


clearPoints

  • void clearPoints()

Removes all points.


addSpriteFrame

  • void addSpriteFrame(int id, const std::string& name, Rect rect)
  • void addSpriteFrame(const std::string& name, float x, float y, float width, float height)
  • void addSpriteFrame(float x, float y, float width, float height)
  • void addSpriteFrame(Rect rect)
  • void removeSpriteFrame(int id)
  • void removeSpriteFrame(const std::string& name)

Defines a named atlas frame for use with the textureRect field of PointData. This enables different points to show different sub-regions of the same texture atlas.


setTexture

  • void setTexture(const std::string& path)
  • void setTexture(const std::string& id, TextureData data)
  • void setTexture(Framebuffer* framebuffer)

Sets the texture used for all points. When using a texture atlas, call addSpriteFrame to define the atlas regions.