CUGL 2.3
Cornell University Game Library
|
#include <CUScene2Texture.h>
Public Member Functions | |
Scene2Texture () | |
~Scene2Texture () | |
virtual void | dispose () override |
bool | init (const Size size) |
bool | init (float width, float height) |
bool | init (const Rect rect) |
bool | init (const Vec2 origin, const Size size) |
virtual bool | init (float x, float y, float width, float height) override |
virtual void | render (const std::shared_ptr< SpriteBatch > &batch) override |
std::shared_ptr< Texture > | getTexture () const |
Public Member Functions inherited from cugl::Scene2 | |
Scene2 () | |
~Scene2 () | |
virtual void | dispose () |
bool | init (const Size size) |
bool | init (float width, float height) |
bool | init (const Rect rect) |
bool | init (const Vec2 origin, const Size size) |
virtual bool | init (float x, float y, float width, float height) |
const std::string | getName () const |
void | setName (const std::string name) |
std::shared_ptr< Camera > | getCamera () |
const std::shared_ptr< Camera > | getCamera () const |
Color4 | getColor () |
void | setColor (Color4 color) |
virtual std::string | toString (bool verbose=false) const |
operator std::string () const | |
const Size | getSize () const |
void | setSize (const Size size) |
void | setSize (float width, float height) |
void | setWidth (float width) |
void | setHeight (float height) |
const Rect | getBounds () const |
void | setBounds (const Rect rect) |
void | setBounds (const Vec2 origin, const Size size) |
void | setBounds (float x, float y, float width, float height) |
void | setOffset (const Vec2 origin) |
Vec3 | screenToWorldCoords (const Vec2 screenCoords) const |
Vec2 | worldToScreenCoords (const Vec3 worldCoords) const |
size_t | getChildCount () const |
std::shared_ptr< scene2::SceneNode > | getChild (unsigned int pos) |
const std::shared_ptr< scene2::SceneNode > & | getChild (unsigned int pos) const |
template<typename T > | |
std::shared_ptr< T > | getChild (unsigned int pos) const |
std::shared_ptr< scene2::SceneNode > | getChildByTag (unsigned int tag) const |
template<typename T > | |
std::shared_ptr< T > | getChildByTag (unsigned int tag) const |
std::shared_ptr< scene2::SceneNode > | getChildByName (const std::string name) const |
template<typename T > | |
std::shared_ptr< T > | getChildByName (const std::string name) const |
std::vector< std::shared_ptr< scene2::SceneNode > > | getChildren () |
const std::vector< std::shared_ptr< scene2::SceneNode > > & | getChildren () const |
virtual void | addChild (const std::shared_ptr< scene2::SceneNode > &child) |
void | addChildWithTag (const std::shared_ptr< scene2::SceneNode > &child, unsigned int tag) |
void | addChildWithName (const std::shared_ptr< scene2::SceneNode > &child, const std::string name) |
void | swapChild (const std::shared_ptr< scene2::SceneNode > &child1, const std::shared_ptr< scene2::SceneNode > &child2, bool inherit=false) |
virtual void | removeChild (unsigned int pos) |
void | removeChild (const std::shared_ptr< scene2::SceneNode > &child) |
void | removeChildByTag (unsigned int tag) |
void | removeChildByName (const std::string name) |
virtual void | removeAllChildren () |
bool | isActive () const |
virtual void | setActive (bool value) |
virtual void | update (float timestep) |
virtual void | reset () |
virtual void | render (const std::shared_ptr< SpriteBatch > &batch) |
Static Public Member Functions | |
static std::shared_ptr< Scene2Texture > | alloc (const Size size) |
static std::shared_ptr< Scene2Texture > | alloc (float width, float height) |
static std::shared_ptr< Scene2Texture > | alloc (const Rect rect) |
static std::shared_ptr< Scene2Texture > | alloc (const Vec2 origin, const Size size) |
static std::shared_ptr< Scene2Texture > | alloc (float x, float y, float width, float height) |
Static Public Member Functions inherited from cugl::Scene2 | |
static std::shared_ptr< Scene2 > | alloc (const Size size) |
static std::shared_ptr< Scene2 > | alloc (float width, float height) |
static std::shared_ptr< Scene2 > | alloc (const Rect rect) |
static std::shared_ptr< Scene2 > | alloc (const Vec2 origin, const Size size) |
static std::shared_ptr< Scene2 > | alloc (float x, float y, float width, float height) |
Protected Attributes | |
std::shared_ptr< Texture > | _texture |
std::shared_ptr< RenderTarget > | _target |
Protected Attributes inherited from cugl::Scene2 | |
std::string | _name |
std::shared_ptr< OrthographicCamera > | _camera |
std::vector< std::shared_ptr< scene2::SceneNode > > | _children |
Color4 | _color |
GLenum | _blendEquation |
GLenum | _srcFactor |
GLenum | _dstFactor |
bool | _active |
This class provides the root node of an offscreen scene graph.
This subclass of Scene2
supports offscreen rendering to a texture. It has its own RenderTarget
, which is what it uses to render to. You can then access the result of the render with getTexture()
. The rendering process ensures that the origin of the scene is rendered to the bottom left corner of the texture (and not the top right, as is the default in OpenGL), making it consist with sprite-based images used by the scene graph.
As a result, this class provides support for simple multi-pass rendering. Simply render to a scene to a texture in one pass, and then use that texture in future passes.
cugl::Scene2Texture::Scene2Texture | ( | ) |
Creates a new degenerate Scene2Texture on the stack.
The scene has no camera and must be initialized.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.
|
inline |
Deletes this scene, disposing all resources
|
inlinestatic |
Returns a newly allocated Scene2Texture for the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
rect | The viewport bounding box |
|
inlinestatic |
Returns a newly allocated Scene2Texture for the given viewport.
The viewport origin is assumed to be (0,0).
size | The viewport size |
|
inlinestatic |
Returns a newly allocated Scene2Texture for the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
origin | The viewport offset |
size | The viewport size |
|
inlinestatic |
Returns a newly allocated Scene2Texture for the given viewport.
The viewport origin is assumed to be (0,0).
width | The viewport width |
height | The viewport height |
|
inlinestatic |
Returns a newly allocated Scene2Texture for the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
x | The viewport x offset |
y | The viewport y offset |
width | The viewport width |
height | The viewport height |
|
overridevirtual |
Disposes all of the resources used by this scene.
A disposed Scene2Texture can be safely reinitialized. Any children owned by this scene will be released. They will be deleted if no other object owns them.
Reimplemented from cugl::Scene2.
|
inline |
Returns the texture associated with this scene graph.
Rendering this scene graph will draw to the offscreen texture. This method returns that texture so that it can be used in subsequent passes.
|
inline |
Initializes a Scene2Texture with the given viewport.
Offseting the viewport origin has little affect on the scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset of the viewport in a larger canvas.
rect | The viewport bounding box |
|
inline |
Initializes a Scene2Texture with the given viewport.
The viewport origin is assumed to be (0,0).
size | The viewport size |
Initializes a Scene2Texture with the given viewport.
Offseting the viewport origin has little affect on the scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset of the viewport in a larger canvas.
origin | The viewport offset |
size | The viewport size |
|
inline |
Initializes a Scene2Texture with the given viewport.
The viewport origin is assumed to be (0,0).
width | The viewport width |
height | The viewport height |
|
overridevirtual |
Initializes a Scene2Texture with the given viewport.
Offseting the viewport origin has little affect on the scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset of the viewport in a larger canvas.
x | The viewport x offset |
y | The viewport y offset |
width | The viewport width |
height | The viewport height |
Reimplemented from cugl::Scene2.
|
overridevirtual |
Draws all of the children in this scene with the given SpriteBatch.
This method assumes that the sprite batch is not actively drawing. It will call both begin() and end().
Rendering happens by traversing the the scene graph using an "Pre-Order" tree traversal algorithm ( https://en.wikipedia.org/wiki/Tree_traversal#Pre-order ). That means that parents are always draw before (and behind children). To override this draw order, you should place an scene2::OrderedNode
in the scene graph to specify an alternative order.
This will render to the offscreen texture associated with this scene. That texture can then be used in subsequent render passes.
batch | The SpriteBatch to draw with. |
Reimplemented from cugl::Scene2.
|
protected |
The offscreen buffer for rendering the texture.
|
protected |
The texture created by this scene