Hi,
I am trying to create a simple scene and render it to an image. The problem is
the image that is attached to the camera is always null. Can some one tell me
what is going on?
Thank you!
Cheers,
Rabbi
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=16152#16152
/* OpenSceneGraph example, osgprerendercubemap.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <osgViewer/Viewer>
#include <osg/Projection>
#include <osg/Geometry>
#include <osg/Texture>
#include <osg/TexGen>
#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osg/PolygonOffset>
#include <osg/CullFace>
#include <osg/TextureCubeMap>
#include <osg/TexMat>
#include <osg/MatrixTransform>
#include <osg/Light>
#include <osg/LightSource>
#include <osg/PolygonOffset>
#include <osg/CullFace>
#include <osg/Material>
#include <osg/PositionAttitudeTransform>
#include <osg/ArgumentParser>
#include <osg/Texture2D>
#include <osg/Camera>
#include <osg/TexGenNode>
#include <osgDB/WriteFile>
#include <iostream>
using namespace osg;
using namespace std;
Group* createSimpleScene();
Image* image;
class SnapCallback : public NodeCallback{
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv){
cout << image->s() << endl; //crashes because image is null
traverse(node,nv);
}
};
int main(int argc, char** argv){
// construct the viewer.
osgViewer::Viewer viewer;
Group* root = new Group;
//image
const unsigned short size = 256;
Image* image = new Image;
unsigned char* buffer = new unsigned char[size * size * 4];
image->setImage(size, size, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, buffer, Image::NO_DELETE);
//setup camera
Camera* camera = new Camera();
camera->setViewport(0, 0, size, size);
camera->setRenderOrder(osg::Camera::PRE_RENDER);
camera->setRenderTargetImplementation(Camera::FRAME_BUFFER_OBJECT);
camera->addChild(createSimpleScene());
camera->attach(osg::Camera::COLOR_BUFFER, image);
root->addChild(camera);
root->setUpdateCallback(new SnapCallback);
viewer.setSceneData(root);
//viewer.setCamera(camera);
return viewer.run();
}
class rotateCallback : public NodeCallback{
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv){
static float angle = 0;
PositionAttitudeTransform* pat = (PositionAttitudeTransform*)node;
pat->setAttitude(Quat(angle++/90, Vec3(0, 0, 1)));
traverse(node,nv);
}
};
Group* createSimpleScene(){
Group* group = new Group;
Geode* box = new Geode;
PositionAttitudeTransform* pat = new PositionAttitudeTransform;
pat->addChild(box);
box->addDrawable(new ShapeDrawable(new Box(Vec3(0.0f, 0.0f, 0.0f), 1, 1, 1)));
group->addChild(pat);
pat->setUpdateCallback(new rotateCallback);
return group;
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org