20,741
edits
No edit summary |
|||
| Line 236: | Line 236: | ||
* http://trac.openscenegraph.org/projects/osg//wiki/Support/Tutorials/FileLoadingAndTransforms | * http://trac.openscenegraph.org/projects/osg//wiki/Support/Tutorials/FileLoadingAndTransforms | ||
* http://www.sm.luth.se/csee/courses/smm/011/l/t1.pdf | * http://www.sm.luth.se/csee/courses/smm/011/l/t1.pdf | ||
* http://www.stackedboxes.org/~lmb/en/computer-stuff/asittbpo-open-scene-graph/index | |||
* http://www.movesinstitute.org/Sullivan/OSGTutorials/index.htm | |||
{{Custom Canvas Element|baseclass=Image|elementName=Model|elementTitle=Canvas 3D model viewer|description=Stub for exposing OSG model loader as a dedicated Canvas element }} | {{Custom Canvas Element|baseclass=Image|elementName=Model|elementTitle=Canvas 3D model viewer|description=Stub for exposing OSG model loader as a dedicated Canvas element }} | ||
[[File:Custom-canvas-element.png|right|thumb|testing a custom canvas element]] | [[File:Custom-canvas-element.png|right|thumb|testing a custom canvas element]] | ||
Next, we need to set up a new camera for rendering our model to a texture - the usual way to accomplish this is to set up a FBO camera (analogous to how the ODGauge code works). First we will set up a texture: | |||
<syntaxhighlight lang="cpp"> | |||
int tex_width = 512, tex_height = 512; | |||
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D; | |||
texture->setTextureSize( tex_width, tex_height ); | |||
texture->setInternalFormat( GL_RGBA ); | |||
texture->setFilter( osg::Texture2D::MIN_FILTER, | |||
osg::Texture2D::LINEAR ); | |||
texture->setFilter( osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR ); | |||
</syntaxhighlight> | |||
Now we can set up a new camera and attach it to the texture for rendering: | |||
<syntaxhighlight lang="cpp"> | |||
osg::Camera* camera = new osg::Camera; | |||
// set up the background color and clear mask. | |||
camera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,0.0f)); | |||
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
// set viewport | |||
camera->setViewport(0,0,tex_width,tex_height); | |||
// set the camera to render before the main camera. | |||
camera->setRenderOrder(osg::Camera::PRE_RENDER); | |||
// use FBOs | |||
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT ); | |||
// attach the texture we set up to use for rendering | |||
camera->attach(osg::Camera::COLOR_BUFFER, texture.get() ); | |||
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); | |||
</syntaxhighlight> | |||
[[Category:Canvas development projects]] | [[Category:Canvas development projects]] | ||
[[Category:Core development projects]] | [[Category:Core development projects]] | ||