CUGL 2.1
Cornell University Game Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::scene2::TexturedNode Class Referenceabstract

#include <CUTexturedNode.h>

Inheritance diagram for cugl::scene2::TexturedNode:
cugl::scene2::SceneNode cugl::scene2::PathNode cugl::scene2::PolygonNode cugl::scene2::WireNode cugl::scene2::SpriteNode

Public Member Functions

 TexturedNode ()
 
 ~TexturedNode ()
 
virtual void dispose () override
 
virtual bool init () override
 
virtual bool initWithFile (const std::string &filename)
 
virtual bool initWithTexture (const std::shared_ptr< Texture > &texture)
 
virtual bool initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override
 
virtual std::shared_ptr< SceneNodecopy (const std::shared_ptr< SceneNode > &dst) const override
 
void setTexture (const std::string &filename)
 
void setTexture (const std::shared_ptr< Texture > &texture)
 
std::shared_ptr< Texture > & getTexture ()
 
const std::shared_ptr< Texture > & getTexture () const
 
const std::shared_ptr< Gradient > & getGradient () const
 
void setGradient (const std::shared_ptr< Gradient > &gradient)
 
void shiftTexture (float dx, float dy)
 
void setBlendFunc (GLenum srcFactor, GLenum dstFactor)
 
GLenum getSourceBlendFactor () const
 
GLenum getDestinationBlendFactor () const
 
void setBlendEquation (GLenum equation)
 
GLenum getBlendEquation () const
 
void flipHorizontal (bool flag)
 
bool isFlipHorizontal () const
 
void flipVertical (bool flag)
 
bool isFlipVertical () const
 
virtual std::string toString (bool verbose=false) const override
 
bool isAbsolute () const
 
void setAbsolute (bool flag)
 
virtual void setAnchor (const Vec2 anchor) override
 
virtual void setAnchor (float x, float y) override
 
virtual void setContentSize (const Size size) override
 
virtual void setContentSize (float width, float height) override
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint) override=0
 
void refresh ()
 
- Public Member Functions inherited from cugl::scene2::SceneNode
 SceneNode ()
 
 ~SceneNode ()
 
virtual bool initWithPosition (const Vec2 pos)
 
bool initWithPosition (float x, float y)
 
virtual bool initWithBounds (const Size size)
 
virtual bool initWithBounds (float width, float height)
 
virtual bool initWithBounds (const Rect rect)
 
virtual bool initWithBounds (float x, float y, float width, float height)
 
unsigned int getTag () const
 
void setTag (unsigned int tag)
 
const std::string getName () const
 
void setName (const std::string name)
 
const std::string getClassName () const
 
 operator std::string () const
 
const Vec2 getPosition () const
 
void setPosition (const Vec2 &position)
 
void setPosition (float x, float y)
 
float getPositionX (void) const
 
void setPositionX (float x)
 
float getPositionY (void) const
 
void setPositionY (float y)
 
Vec2 getWorldPosition () const
 
const Size getContentSize () const
 
float getContentWidth () const
 
void setContentWidth (float width)
 
float getContentHeight () const
 
void setContentHeight (float height)
 
virtual Rect getLayoutBounds () const
 
Size getSize () const
 
float getWidth () const
 
float getHeight () const
 
Rect getBoundingBox () const
 
const Vec2 getAnchor () const
 
Vec2 getAnchorInPixels ()
 
Color4 getColor () const
 
virtual void setColor (Color4 color)
 
Color4 getAbsoluteColor ()
 
bool isVisible () const
 
void setVisible (bool visible)
 
bool hasRelativeColor () const
 
void setRelativeColor (bool flag)
 
std::shared_ptr< ScissorgetScissor () const
 
void setScissor (const std::shared_ptr< Scissor > &scissor)
 
void setScissor ()
 
const Vec2 getScale () const
 
float getScaleX () const
 
float getScaleY () const
 
void setScale (float scale)
 
void setScale (const Vec2 vec)
 
void setScale (float sx, float sy)
 
float getAngle ()
 
void setAngle (float angle)
 
const Affine2getTransform () const
 
const Affine2getAlternateTransform () const
 
void setAlternateTransform (const Affine2 &transform)
 
bool withAlternateTransform ()
 
void chooseAlternateTransform (bool active)
 
const Affine2getNodeToParentTransform () const
 
Affine2 getParentToNodeTransform () const
 
Affine2 getNodeToWorldTransform () const
 
Affine2 getWorldToNodeTransform () const
 
Vec2 screenToNodeCoords (const Vec2 screenPoint) const
 
Vec2 worldToNodeCoords (const Vec2 worldPoint) const
 
Vec2 nodeToScreenCoords (const Vec2 nodePoint) const
 
Vec2 nodeToWorldCoords (const Vec2 nodePoint) const
 
Vec2 parentToNodeCoords (const Vec2 parentPoint) const
 
Vec2 nodeToParentCoords (const Vec2 nodePoint) const
 
size_t getChildCount () const
 
std::shared_ptr< SceneNodegetChild (unsigned int pos)
 
const std::shared_ptr< SceneNode > & getChild (unsigned int pos) const
 
template<typename T >
std::shared_ptr< T > getChild (unsigned int pos) const
 
std::shared_ptr< SceneNodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< T > getChildByTag (unsigned int tag) const
 
std::shared_ptr< SceneNodegetChildByName (const std::string name) const
 
template<typename T >
std::shared_ptr< T > getChildByName (const std::string name) const
 
std::vector< std::shared_ptr< SceneNode > > getChildren ()
 
const std::vector< std::shared_ptr< SceneNode > > & getChildren () const
 
void addChild (const std::shared_ptr< SceneNode > &child)
 
void addChildWithTag (const std::shared_ptr< SceneNode > &child, unsigned int tag)
 
void addChildWithName (const std::shared_ptr< SceneNode > &child, const std::string name)
 
void swapChild (const std::shared_ptr< SceneNode > &child1, const std::shared_ptr< SceneNode > &child2, bool inherit=false)
 
SceneNodegetParent ()
 
const SceneNodegetParent () const
 
Scene2getScene ()
 
const Scene2getScene () const
 
void removeFromParent ()
 
virtual void removeChild (unsigned int pos)
 
void removeChild (const std::shared_ptr< SceneNode > &child)
 
void removeChildByTag (unsigned int tag)
 
void removeChildByName (const std::string name)
 
virtual void removeAllChildren ()
 
void setPriority (float priority)
 
float getPriority ()
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint)
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch)
 
const std::shared_ptr< Layout > & getLayout () const
 
void setLayout (const std::shared_ptr< Layout > &layout)
 
virtual void doLayout ()
 

Protected Member Functions

virtual void generateRenderData ()=0
 
virtual void updateTextureCoords ()=0
 
void clearRenderData ()
 
 CU_DISALLOW_COPY_AND_ASSIGN (TexturedNode)
 

Protected Attributes

std::shared_ptr< Texture_texture
 
std::shared_ptr< Gradient_gradient
 
bool _absolute
 
Vec2 _offset
 
bool _rendered
 
Mesh< SpriteVertex2_mesh
 
GLenum _blendEquation
 
GLenum _srcFactor
 
GLenum _dstFactor
 
bool _flipHorizontal
 
bool _flipVertical
 
- Protected Attributes inherited from cugl::scene2::SceneNode
Vec2 _position
 
Vec2 _anchor
 
Size _contentSize
 
Color4 _tintColor
 
bool _hasParentColor
 
bool _isVisible
 
std::shared_ptr< Scissor_scissor
 
Vec2 _scale
 
float _angle
 
Affine2 _transform
 
bool _useTransform
 
Affine2 _combined
 
std::vector< std::shared_ptr< SceneNode > > _children
 
SceneNode_parent
 
Scene2_graph
 
std::shared_ptr< Layout_layout
 
int _childOffset
 
unsigned int _tag
 
std::string _name
 
size_t _hashOfName
 
std::string _classname
 
float _priority
 
std::shared_ptr< JsonValue_json
 

Additional Inherited Members

- Static Public Member Functions inherited from cugl::scene2::SceneNode
static std::shared_ptr< SceneNodealloc ()
 
static std::shared_ptr< SceneNodeallocWithPosition (const Vec2 pos)
 
static std::shared_ptr< SceneNodeallocWithPosition (float x, float y)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Size size)
 
static std::shared_ptr< SceneNodeallocWithBounds (float width, float height)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Rect rect)
 
static std::shared_ptr< SceneNodeallocWithBounds (float x, float y, float width, float height)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 

Detailed Description

This class is an abstract scene graph node representing a textured shape.

This class cannot be instantiated directly. Instead, you must use one of the subclasses: PolygonNode, SpriteNode, PathNode, or WireNode.

This abstract class only manages texture. It has no shape. The shape/mesh of a textured node is determined by the appropriate subclass. However, for all subclasses, the shape is always specified in image coordinates. Image coordinates are different from texture coordinates. Their origin is at the bottom-left corner of the file, and each pixel is one unit. This design choice is intended to make irregular shapes easier to use.

This means that a solid polygon with vertices (0,0), (width,0), (width,height), and (0,height) would be identical to a sprite node. However, a solid polygon with vertices (0,0), (2*width,0), (2*width,2*height), and (0,2*height) would tile the sprite (given the wrap settings) twice both horizontally and vertically.

The content size of this node is defined by the size (but not the offset) of the bounding box. The anchor point is relative to this content size. The default anchor point in a TexturedNode is (0.5, 0.5). This means that a uniform translation of the the underlying shape (in contrast to the node itself) will not move the node on the the screen. Instead, it will just change the part of the texture it uses.

For example, suppose the texture has given width and height. We have one polygon with vertices (0,0), (width/2,0), (width/2,height/2), and (0,height/2). We have another polygon with vertices (width/2,height/2), (width,height/2), (width,height), and (width/2,height). Both polygons would create a rectangle of size (width/2,height/2). centered at the node position. However, the first would use the bottom left part of the texture, while the second would use the top right.

You can disable these features at any time by setting the attribute absolute to true. Do this will place the polygon vertices in their absolute positions in Node space. This will also disable anchor functions (setting the anchor as the bottom left corner), since anchors do not make sense when we are drawing vertices directly into the coordinate space.

Constructor & Destructor Documentation

◆ TexturedNode()

cugl::scene2::TexturedNode::TexturedNode ( )

Creates an empty scene graph node with the degenerate texture.

This constructor should never be called directly, as this is an abstract class.

◆ ~TexturedNode()

cugl::scene2::TexturedNode::~TexturedNode ( )
inline

Deletes this node, releasing all resources.

Member Function Documentation

◆ clearRenderData()

void cugl::scene2::TexturedNode::clearRenderData ( )
protected

Clears the render data, releasing all vertices and indices.

◆ copy()

virtual std::shared_ptr<SceneNode> cugl::scene2::TexturedNode::copy ( const std::shared_ptr< SceneNode > &  dst) const
overridevirtual

Performs a shallow copy of this Node into dst.

No children from this node are copied, and no children of dst are modified. In addition, the parents of both Nodes are unchanged. However, all other attributes of this node are copied.

Parameters
dstThe Node to copy into
Returns
A reference to dst for chaining.

Reimplemented from cugl::scene2::SceneNode.

Reimplemented in cugl::scene2::PolygonNode, cugl::scene2::WireNode, cugl::scene2::PathNode, and cugl::scene2::SpriteNode.

◆ CU_DISALLOW_COPY_AND_ASSIGN()

cugl::scene2::TexturedNode::CU_DISALLOW_COPY_AND_ASSIGN ( TexturedNode  )
protected

This macro disables the copy constructor (not allowed on scene graphs)

◆ dispose()

virtual void cugl::scene2::TexturedNode::dispose ( )
overridevirtual

Disposes all of the resources used by this node.

A disposed Node can be safely reinitialized. Any children owned by this node will be released. They will be deleted if no other object owns them.

It is unsafe to call this on a Node that is still currently inside of a scene graph.

Reimplemented from cugl::scene2::SceneNode.

◆ draw()

virtual void cugl::scene2::TexturedNode::draw ( const std::shared_ptr< SpriteBatch > &  batch,
const Affine2 transform,
Color4  tint 
)
overridepure virtual

Draws this Node via the given SpriteBatch.

This method only worries about drawing the current node. It does not attempt to render the children.

This is the method that you should override to implement your custom drawing code. You are welcome to use any OpenGL commands that you wish. You can even skip use of the SpriteBatch. However, if you do so, you must flush the SpriteBatch by calling end() at the start of the method. in addition, you should remember to call begin() at the start of the method.

This method provides the correct transformation matrix and tint color. You do not need to worry about whether the node uses relative color. This method is called by render() and these values are guaranteed to be correct. In addition, this method does not need to check for visibility, as it is guaranteed to only be called when the node is visible.

Parameters
batchThe SpriteBatch to draw with.
transformThe global transformation matrix.
tintThe tint to blend with the Node color.

Reimplemented from cugl::scene2::SceneNode.

Implemented in cugl::scene2::WireNode, cugl::scene2::PathNode, and cugl::scene2::PolygonNode.

◆ flipHorizontal()

void cugl::scene2::TexturedNode::flipHorizontal ( bool  flag)
inline

Flips the texture coordinates horizontally if flag is true.

Flipping the texture coordinates replaces each u coordinate with 1-u. Hence this operation is defined even if the texture coordinates are outside the range 0..1.

Parameters
flagwhether to flip the coordinates horizontally

◆ flipVertical()

void cugl::scene2::TexturedNode::flipVertical ( bool  flag)
inline

Flips the texture coordinates vertically if flag is true.

Flipping the texture coordinates replaces each v coordinate with 1-v. Hence this operation is defined even if the texture coordinates are outside the range 0..1.

Parameters
flagwhether to flip the coordinates vertically

◆ generateRenderData()

virtual void cugl::scene2::TexturedNode::generateRenderData ( )
protectedpure virtual

Allocates the render data necessary to render this node.

◆ getBlendEquation()

GLenum cugl::scene2::TexturedNode::getBlendEquation ( ) const
inline

Returns the blending equation for this textured node

By default this value is GL_FUNC_ADD. For other options, see

 https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml

This blending equation only affects the texture of the current node. It does not affect any children of the node.

Returns
the blending equation for this sprite batch

◆ getDestinationBlendFactor()

GLenum cugl::scene2::TexturedNode::getDestinationBlendFactor ( ) const
inline

Returns the destination blending factor

By default this value is GL_ONE_MINUS_SRC_ALPHA. For other options, see

 https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml

This blending factor only affects the texture of the current node. It does not affect any children of the node.

Returns
the destination blending factor

◆ getGradient()

const std::shared_ptr<Gradient>& cugl::scene2::TexturedNode::getGradient ( ) const
inline

Returns the gradient to use for this node.

Unlike colors, gradients are local. They do not apply to the children of this node. Gradients are independent of textures; a texture node may have both a gradient and a texture.

Returns
the gradient to use for this node.

◆ getSourceBlendFactor()

GLenum cugl::scene2::TexturedNode::getSourceBlendFactor ( ) const
inline

Returns the source blending factor

By default this value is GL_SRC_ALPHA. For other options, see

 https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml

This blending factor only affects the texture of the current node. It does not affect any children of the node.

Returns
the source blending factor

◆ getTexture() [1/2]

std::shared_ptr<Texture>& cugl::scene2::TexturedNode::getTexture ( )
inline

Returns the texture used by this node.

Returns
the texture used by this node

◆ getTexture() [2/2]

const std::shared_ptr<Texture>& cugl::scene2::TexturedNode::getTexture ( ) const
inline

Returns the texture used by this node.

Returns
the texture used by this node

◆ init()

virtual bool cugl::scene2::TexturedNode::init ( )
inlineoverridevirtual

Intializes a scene graph node with the degenerate texture.

This will make the texture be Texture#getBlank, which is suitable for drawing solid shapes. However, this is an abstract class, so it will not apply any geometry to the texture. You will need to use one of the appropriate subclasses.

Returns
true if the sprite is initialized properly, false otherwise.

Reimplemented from cugl::scene2::SceneNode.

◆ initWithData()

virtual bool cugl::scene2::TexturedNode::initWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
overridevirtual

Initializes a node with the given JSON specificaton.

This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attribute:

 "texture":  A string with the name of a previously loaded texture asset
 "gradient": A JSON object defining a gradient. See {@link Gradient}.
 "absolute": A boolean indicating whether to use absolute coordinates
 "blendeq":  A string matching a valid OpenGL blending equation.
             See glBlendEquation in the OpenGL documentation.
 "blendsrc": A string mathcing a valid OpenGL blending function. See
             glBlendFunc in the OpenGL documentation.
 "blenddst": A string mathcing a valid OpenGL blending function. See
             glBlendFunc in the OpenGL documentation.
 "flip":     One of "horizontal", "vertical", "both", or "none".

All attributes are optional. If the texture is missing, this node will use Texture#getBlank instead, which is suitable for drawing solid shapes.

Note that this is an abstract class, so it will not apply any geometry to the texture. You will need to use one of the appropriate subclasses.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
true if initialization was successful.

Reimplemented from cugl::scene2::SceneNode.

Reimplemented in cugl::scene2::PolygonNode, cugl::scene2::WireNode, cugl::scene2::PathNode, and cugl::scene2::SpriteNode.

◆ initWithFile()

virtual bool cugl::scene2::TexturedNode::initWithFile ( const std::string &  filename)
virtual

Intializes a scene graph node with the image filename.

This method will fail if the file does not exist or is not a valid image file. Even if the texture is successfully loaded, this is an an abstract class, so it will not apply any geometry to the texture. You will need to use one of the appropriate subclasses.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
Returns
true if the sprite is initialized properly, false otherwise.

Reimplemented in cugl::scene2::PolygonNode.

◆ initWithTexture()

virtual bool cugl::scene2::TexturedNode::initWithTexture ( const std::shared_ptr< Texture > &  texture)
virtual

Initializes a textured polygon from a Texture object.

If the texture is null, this node will use Texture#getBlank instead, which is suitable for drawing solid shapes. Regardless, this is an abstract class, so it will not apply any geometry to the texture. You will need to use one of the appropriate subclasses.

Parameters
textureA shared pointer to a Texture object.
Returns
true if the sprite is initialized properly, false otherwise.

Reimplemented in cugl::scene2::PolygonNode.

◆ isAbsolute()

bool cugl::scene2::TexturedNode::isAbsolute ( ) const
inline

Returns true if this node is using absolute positioning.

In absolute positioning, the vertices are draw in their correct position with respect to the node origin. We no longer try to offset the polygon with respect to the anchors. This is useful when you need a scene graph node that has an external relationship to a non-child node.

Setting this value to true will disable anchor functions (and set the anchor to the bottom left). That is because anchors do not make sense when we are using absolute positioning.

Returns
true if this node is using absolute positioning.

◆ isFlipHorizontal()

bool cugl::scene2::TexturedNode::isFlipHorizontal ( ) const
inline

Returns true if the texture coordinates are flipped horizontally.

Returns
true if the texture coordinates are flipped horizontally.

◆ isFlipVertical()

bool cugl::scene2::TexturedNode::isFlipVertical ( ) const
inline

Returns true if the texture coordinates are flipped vertically.

Returns
true if the texture coordinates are flipped vertically.

◆ refresh()

void cugl::scene2::TexturedNode::refresh ( )
inline

Refreshes this node to restore the render data.

◆ setAbsolute()

void cugl::scene2::TexturedNode::setAbsolute ( bool  flag)
inline

Sets whether this node is using absolute positioning.

In absolute positioning, the vertices are draw in their correct position with respect to the node origin. We no longer try to offset the polygon with respect to the anchors. This is useful when you need a scene graph node that has an external relationship to a non-child node.

Setting this value to true will disable anchor functions (and set the anchor to the bottom left). That is because anchors do not make sense when we are using absolute positioning.

Parameters
flagWhether if this node is using absolute positioning.

◆ setAnchor() [1/2]

virtual void cugl::scene2::TexturedNode::setAnchor ( const Vec2  anchor)
inlineoverridevirtual

Sets the anchor point in percentages.

The anchor point defines the relative origin of Node with respect to its parent. It is a "pin" where the Node is attached to its parent. In effect, the translation of a Node is defined by its position plus anchor point.

The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner. There are many anchor point constants defined in Vec2. However, there is nothing preventing an anchor point higher than (1,1) or lower than (0,0).

The default anchorPoint is (0.5,0.5), so it starts in the center of the node. Changing the anchor will not move the contents of the node in the parent space, but it will change the value of the Node position.

This function is disabled if the node is using absolute positioning. That is because anchors do not make sense when we are drawing polygons directly to the screen.

Parameters
anchorThe anchor point of node.

Reimplemented from cugl::scene2::SceneNode.

◆ setAnchor() [2/2]

virtual void cugl::scene2::TexturedNode::setAnchor ( float  x,
float  y 
)
inlineoverridevirtual

Sets the anchor point in percentages.

The anchor point defines the relative origin of Node with respect to its parent. It is a "pin" where the Node is attached to its parent. In effect, the translation of a Node is defined by its position plus anchor point.

The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner. There are many anchor point constants defined in Vec2. However, there is nothing preventing an anchor point higher than (1,1) or lower than (0,0).

The default anchorPoint is (0.5,0.5), so it starts in the center of the node. Changing the anchor will not move the contents of the node in the parent space, but it will change the value of the Node position.

This function is disabled if the node is using absolute positioning. That is because anchors do not make sense when we are drawing polygons directly to the screen.

Parameters
xThe horizontal anchor percentage.
yThe vertical anchor percentage.

Reimplemented from cugl::scene2::SceneNode.

◆ setBlendEquation()

void cugl::scene2::TexturedNode::setBlendEquation ( GLenum  equation)
inline

Sets the blending equation for this textured node

The enum must be a standard ones supported by OpenGL. See

 https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml

However, this setter does not do any error checking to verify that the input is valid. By default, the equation is GL_FUNC_ADD.

This blending equation only affects the texture of the current node. It does not affect any children of the node.

Parameters
equationSpecifies how source and destination colors are combined

◆ setBlendFunc()

void cugl::scene2::TexturedNode::setBlendFunc ( GLenum  srcFactor,
GLenum  dstFactor 
)
inline

Sets the blending function for this texture node.

The enums are the standard ones supported by OpenGL. See

 https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml

However, this setter does not do any error checking to verify that the enums are valid. By default, srcFactor is GL_SRC_ALPHA while dstFactor is GL_ONE_MINUS_SRC_ALPHA. This corresponds to non-premultiplied alpha blending.

This blending factor only affects the texture of the current node. It does not affect any children of the node.

Parameters
srcFactorSpecifies how the source blending factors are computed
dstFactorSpecifies how the destination blending factors are computed.

◆ setContentSize() [1/2]

virtual void cugl::scene2::TexturedNode::setContentSize ( const Size  size)
overridevirtual

Sets the untransformed size of the node.

The content size remains the same no matter how the node is scaled or rotated. All nodes must have a size, though it may be degenerate (0,0).

By default, the content size of a TexturedNode is the size of the bounding box of the defining polygon. Resizing a texture node will stretch the image to fill in the new size.

Parameters
sizeThe untransformed size of the node.

Reimplemented from cugl::scene2::SceneNode.

◆ setContentSize() [2/2]

virtual void cugl::scene2::TexturedNode::setContentSize ( float  width,
float  height 
)
inlineoverridevirtual

Sets the untransformed size of the node.

The content size remains the same no matter how the node is scaled or rotated. All nodes must have a size, though it may be degenerate (0,0).

By default, the content size of a TexturedNode is the size of the bounding box of the defining polygon. Resizing a texture node will stretch the image to fill in the new size.

Parameters
widthThe untransformed width of the node.
heightThe untransformed height of the node.

Reimplemented from cugl::scene2::SceneNode.

◆ setGradient()

void cugl::scene2::TexturedNode::setGradient ( const std::shared_ptr< Gradient > &  gradient)

Sets the gradient to use for this node.

Unlike colors, gradients are local. They do not apply to the children of this node. Gradients are independent of textures; a texture node may have both a gradient and a texture.

Parameters
gradientThe gradient to use for this node.

◆ setTexture() [1/2]

void cugl::scene2::TexturedNode::setTexture ( const std::shared_ptr< Texture > &  texture)

Sets the node texture to the one specified.

This method will have no effect on the underlying geometry. This class decouples the geometry from the texture. That is because we do not expect the vertices to match the texture perfectly.

Parameters
textureA shared pointer to a Texture object.

◆ setTexture() [2/2]

void cugl::scene2::TexturedNode::setTexture ( const std::string &  filename)
inline

Sets the node texture to a new one allocated from a filename.

This method will have no effect on the underlying geometry. This class decouples the geometry from the texture. That is because we do not expect the vertices to match the texture perfectly.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"

◆ shiftTexture()

void cugl::scene2::TexturedNode::shiftTexture ( float  dx,
float  dy 
)

Translates the texture image by the given amount.

This method has no effect on the shape or position of the node. It simply shifts the texture coordinates of the underlying mesh by the given amount (measured in pixels). Hence this method can be used for animation and filmstrips. This method is faster than redefining the shape.

If the node has a gradient, this will shift the gradient image by the same amount.

Parameters
dxThe amount to shift horizontally.
dyThe amount to shift horizontally.

◆ toString()

virtual std::string cugl::scene2::TexturedNode::toString ( bool  verbose = false) const
overridevirtual

Returns a string representation of this node for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this node for debuggging purposes.

Reimplemented from cugl::scene2::SceneNode.

◆ updateTextureCoords()

virtual void cugl::scene2::TexturedNode::updateTextureCoords ( )
protectedpure virtual

Updates the texture coordinates for this polygon

The texture coordinates are computed assuming that the polygon is defined in image space, with the origin in the bottom left corner of the texture.

Member Data Documentation

◆ _absolute

bool cugl::scene2::TexturedNode::_absolute
protected

Whether to disable anchors and draw the underlying shape in absolute coordinates

◆ _blendEquation

GLenum cugl::scene2::TexturedNode::_blendEquation
protected

The blending equation for this texture

◆ _dstFactor

GLenum cugl::scene2::TexturedNode::_dstFactor
protected

The destination factor for the blend function

◆ _flipHorizontal

bool cugl::scene2::TexturedNode::_flipHorizontal
protected

Whether or not to flip the texture horizontally

◆ _flipVertical

bool cugl::scene2::TexturedNode::_flipVertical
protected

Whether or not to flip the texture vertically

◆ _gradient

std::shared_ptr<Gradient> cugl::scene2::TexturedNode::_gradient
protected

The gradient to use for this node

◆ _mesh

Mesh<SpriteVertex2> cugl::scene2::TexturedNode::_mesh
protected

The render data for this node

◆ _offset

Vec2 cugl::scene2::TexturedNode::_offset
protected

Texture offset to for shifting the image

◆ _rendered

bool cugl::scene2::TexturedNode::_rendered
protected

Whether we have generated render data for this node

◆ _srcFactor

GLenum cugl::scene2::TexturedNode::_srcFactor
protected

The source factor for the blend function

◆ _texture

std::shared_ptr<Texture> cugl::scene2::TexturedNode::_texture
protected

Texture associated with this node


The documentation for this class was generated from the following file: