<html><head/><body><html><head><meta name="viewport" content="width=device-width" /><meta http-equiv="Content-Type" content="text/vnd.ui.insecure+html;charset=utf-8" /></head><body style="overflow-wrap:break-word; word-break: break-word;"><div class="mail_android_message" style="line-height: 1; padding: 0.5em">Hi. Sorry I don't on my computer right now, but it seems you are not providing vertex shaders. I'm not sure, but that might cause trouble. I'll get back to the issue tommorow or on Monday. <br>
<br>
Cheers<br>
Sebastian<br>
-- <br>
Sent from my Android phone with GMX Mail. Please excuse my brevity.</div><div class="mail_android_quote" style="line-height: 1; padding: 0.3em">On 9/2/17, 21:36 antiro black <antiro42@gmail.com> wrote:<blockquote class="gmail_quote" style="margin: 0.8ex 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<p dir="ltr">Hi Sebastian,</p>
<p dir="ltr">I'm compiling under debian jessie 64 bits and am running a NVIDIA GTX 970. The drivers have been updates recently and I am running version 384.69 now.</p>
<p dir="ltr">I included a compilable minimal example based on the osgmultiplerendertargets example. Without VertexAttributeAliasing it generates two texture using MRT, a red and a green one, it then combines these in a second pass to generate the final texture (yellow). (The red and green intermediate textures are shown in small quads to the side.)</p>
<p dir="ltr">When I enable the attribute aliasing (as in the included code), the two textures generated in the MRT pass turn into gradients, as if something has gone wrong with the mapping.</p>
<p dir="ltr">Screenshots:<br />
The expected result (which I get without attribute aliasing): <a href="https://ibb.co/kHEogv">https://ibb.co/kHEogv</a><br />
The result with aliasing: <a href="https://ibb.co/d9cfuF">https://ibb.co/d9cfuF</a><br /></p>
<p dir="ltr">Code:<br />
/* OpenSceneGraph example, osgmultiplerendertargets.<br />
*<br />
* Permission is hereby granted, free of charge, to any person obtaining a copy<br />
* of this software and associated documentation files (the "Software"), to deal<br />
* in the Software without restriction, including without limitation the rights<br />
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br />
* copies of the Software, and to permit persons to whom the Software is<br />
* furnished to do so, subject to the following conditions:<br />
*<br />
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br />
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br />
* THE SOFTWARE.<br />
*/</p>
<p dir="ltr">#include <osg/GLExtensions><br />
#include <osg/Node><br />
#include <osg/Geometry><br />
#include <osg/Notify><br />
#include <osg/MatrixTransform><br />
#include <osg/Texture2D><br />
#include <osg/TextureRectangle><br />
#include <osg/ColorMask><br />
#include <osg/Material><br />
#include <osg/Capability></p>
<p dir="ltr">#include <osgGA/TrackballManipulator><br />
#include <osgGA/FlightManipulator><br />
#include <osgGA/DriveManipulator></p>
<p dir="ltr">#include <osgViewer/Viewer></p>
<p dir="ltr">#include <iostream><br />
#include <stdio.h></p>
<p dir="ltr">#include <osg/PolygonMode><br />
//#include "RenderingUtility.h" //to easily view intermediate textures<br />
//<br />
// Below is relatively straight forward example of using the OpenGL multiple render targets (MRT) extension<br />
// to FrameBufferObjects/GLSL shaders.<br />
//<br />
// Another, more sophisticated MRT example can be found in the osgstereomatch example.<br />
//</p>
<p dir="ltr">osg::Geode *createScreenQuad(float width,<br />
float height,<br />
float scale,<br />
osg::Vec3 corner)<br />
{<br />
osg::Geometry* geom = osg::createTexturedQuadGeometry(<br />
corner,<br />
osg::Vec3(width, 0, 0),<br />
osg::Vec3(0, height, 0),<br />
0,<br />
0,<br />
scale,<br />
scale);<br />
osg::ref_ptr<osg::Geode> quad = new osg::Geode;<br />
quad->addDrawable(geom);<br />
int values = osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED;<br />
quad->getOrCreateStateSet()->setAttribute(<br />
new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK,<br />
osg::PolygonMode::FILL),<br />
values);<br />
quad->getOrCreateStateSet()->setMode(GL_LIGHTING, values);<br />
return quad.release();<br />
}<br /></p>
<p dir="ltr">osg::Camera *createHUDCamera(double left=0,<br />
double right=1,<br />
double bottom=0,<br />
double top=1)<br />
{<br />
osg::ref_ptr<osg::Camera> camera = new osg::Camera;<br />
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);<br />
camera->setClearMask(GL_DEPTH_BUFFER_BIT);<br />
camera->setRenderOrder(osg::Camera::POST_RENDER);<br />
camera->setAllowEventFocus(false);<br />
camera->setProjectionMatrix(osg::Matrix::ortho2D(left, right, bottom, top));<br />
camera->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);<br />
return camera.release();<br />
}</p>
<p dir="ltr">osg::ref_ptr<osg::Camera> createTextureDisplayQuad(<br />
const osg::Vec3 &pos,<br />
osg::StateAttribute *tex,<br />
float scale,<br />
float width=0.3,<br />
float height=0.2)<br />
{<br />
osg::ref_ptr<osg::Camera> hc = createHUDCamera();<br />
hc->addChild(createScreenQuad(width, height, scale, pos));<br />
hc->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex);<br />
return hc;<br />
}<br /></p>
<p dir="ltr">// The callback modifies an input image.<br />
struct MyCameraPostDrawCallback : public osg::Camera::DrawCallback<br />
{<br />
MyCameraPostDrawCallback(osg::Image* image):<br />
_image(image)<br />
{<br />
}</p>
<p dir="ltr">virtual void operator () (const osg::Camera& /*camera*/) const<br />
{<br />
if (_image && _image->getPixelFormat()==GL_RGBA && _image->getDataType()==GL_UNSIGNED_BYTE)<br />
{<br />
// we'll pick out the center 1/2 of the whole image,<br />
int column_start = _image->s()/4;<br />
int column_end = 3*column_start;</p>
<p dir="ltr">int row_start = _image->t()/4;<br />
int row_end = 3*row_start;</p>
<p dir="ltr">// and then halve their contribution<br />
for(int r=row_start; r<row_end; ++r)<br />
{<br />
unsigned char* data = _image->data(column_start, r);<br />
for(int c=column_start; c<column_end; ++c)<br />
{<br />
(*data) = (*data)/2; ++data;<br />
(*data) = (*data)/2; ++data;<br />
(*data) = (*data)/2; ++data;<br />
(*data) = 255; ++data;<br />
}<br />
}</p>
<p dir="ltr">_image->dirty();<br />
}<br />
else if (_image && _image->getPixelFormat()==GL_RGBA && _image->getDataType()==GL_FLOAT)<br />
{<br />
// we'll pick out the center 1/2 of the whole image,<br />
int column_start = _image->s()/4;<br />
int column_end = 3*column_start;</p>
<p dir="ltr">int row_start = _image->t()/4;<br />
int row_end = 3*row_start;</p>
<p dir="ltr">// and then halve their contribution<br />
for(int r=row_start; r<row_end; ++r)<br />
{<br />
float* data = (float*)_image->data(column_start, r);<br />
for(int c=column_start; c<column_end; ++c)<br />
{<br />
(*data) = (*data)/2.0; ++data;<br />
(*data) = (*data)/2.0; ++data;<br />
(*data) = (*data)/2.0; ++data;<br />
(*data) = 1.0f; ++data;<br />
}<br />
}</p>
<p dir="ltr">_image->dirty();</p>
<p dir="ltr">//print out the first three values<br />
float* data = (float*)_image->data(0, 0);<br />
fprintf(stderr,"Float pixel data: r %e g %e b %e\n", data[0], data[1], data[2]);<br />
}<br />
}</p>
<p dir="ltr">osg::Image* _image;<br />
};</p>
<p dir="ltr">#define NUM_TEXTURES 2</p>
<p dir="ltr">// The quad geometry is used by the render to texture camera to generate multiple textures.<br />
osg::Group* createRTTQuad(unsigned int tex_width, unsigned int tex_height, bool useHDR)<br />
{<br />
osg::Group *top_group = new osg::Group;</p>
<p dir="ltr">osg::ref_ptr<osg::Geode> quad_geode = new osg::Geode;</p>
<p dir="ltr">osg::ref_ptr<osg::Vec3Array> quad_coords = new osg::Vec3Array; // vertex coords<br />
// counter-clockwise<br />
quad_coords->push_back(osg::Vec3d(0, 0, -1));<br />
quad_coords->push_back(osg::Vec3d(1, 0, -1));<br />
quad_coords->push_back(osg::Vec3d(1, 1, -1));<br />
quad_coords->push_back(osg::Vec3d(0, 1, -1));</p>
<p dir="ltr">osg::ref_ptr<osg::Vec2Array> quad_tcoords = new osg::Vec2Array; // texture coords<br />
quad_tcoords->push_back(osg::Vec2(0, 0));<br />
quad_tcoords->push_back(osg::Vec2(tex_width, 0));<br />
quad_tcoords->push_back(osg::Vec2(tex_width, tex_height));<br />
quad_tcoords->push_back(osg::Vec2(0, tex_height));</p>
<p dir="ltr">osg::ref_ptr<osg::Geometry> quad_geom = new osg::Geometry;<br />
osg::ref_ptr<osg::DrawArrays> quad_da = new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4);</p>
<p dir="ltr">osg::ref_ptr<osg::Vec4Array> quad_colors = new osg::Vec4Array;<br />
quad_colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));</p>
<p dir="ltr">quad_geom->setVertexArray(quad_coords.get());<br />
quad_geom->setTexCoordArray(0, quad_tcoords.get());<br />
quad_geom->addPrimitiveSet(quad_da.get());<br />
quad_geom->setColorArray(quad_colors.get(), osg::Array::BIND_OVERALL);</p>
<p dir="ltr">osg::StateSet *stateset = quad_geom->getOrCreateStateSet();<br />
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);</p>
<p dir="ltr">stateset->addUniform(new osg::Uniform("width", (int)tex_width));</p>
<p dir="ltr">// Attach shader, glFragData is used to create data for multiple render targets</p>
<p dir="ltr">if (useHDR) {<br />
static const char *shaderSource = {<br />
"uniform int width;"<br />
"void main(void)\n"<br />
"{\n"<br />
" gl_FragData[0] = vec4(-1e-12,0,0,1);\n"<br />
" gl_FragData[1] = vec4(0,1e-12,0,1);\n"<br />
" gl_FragData[2] = vec4(0,0,1e-12,1);\n"<br />
" gl_FragData[3] = vec4(0,0,1e-12,1);\n"<br />
"}\n"<br />
};</p>
<p dir="ltr">osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT , shaderSource);<br />
osg::ref_ptr<osg::Program> program = new osg::Program;<br />
program->addShader(fshader.get());<br />
stateset->setAttributeAndModes(program.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );<br />
} else {<br />
static const char *shaderSource = {<br />
"uniform int width;"<br />
"void main(void)\n"<br />
"{\n"<br />
" gl_FragData[0] = vec4(1,0,0,1);\n"<br />
" gl_FragData[1] = vec4(0,1,0,1);\n"<br />
" gl_FragData[2] = vec4(0,0,1,1);\n"<br />
" gl_FragData[3] = vec4(0,0,1,1);\n"<br />
"}\n"<br />
};</p>
<p dir="ltr">osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT , shaderSource);<br />
osg::ref_ptr<osg::Program> program = new osg::Program;<br />
program->addShader(fshader.get());<br />
stateset->setAttributeAndModes(program.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );<br />
}</p>
<p dir="ltr">quad_geode->addDrawable(quad_geom.get());</p>
<p dir="ltr">top_group->addChild(quad_geode.get());</p>
<p dir="ltr">return top_group;<br />
}<br /></p>
<p dir="ltr"> osg::TextureRectangle* textureRect[NUM_TEXTURES] = {0,0}; //moved to global scope to easily view intermediate textures<br />
// Here a scene consisting of a single quad is created. This scene is viewed by the screen camera.<br />
// The quad is textured using a shader and the multiple textures generated in the RTT stage.<br />
osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned int tex_height, bool useHDR, bool useImage, bool useMultiSample)<br />
{<br />
if (!cam_subgraph) return 0;</p>
<p dir="ltr">// create a group to contain the quad and the pre render camera.<br />
osg::Group* parent = new osg::Group;</p>
<p dir="ltr">// textures to render to and to use for texturing of the final quad<br />
//osg::TextureRectangle* textureRect[NUM_TEXTURES] = {0,0,0,0};</p>
<p dir="ltr">for (int i=0;i<NUM_TEXTURES;i++) {<br />
textureRect[i] = new osg::TextureRectangle;<br />
textureRect[i]->setTextureSize(tex_width, tex_height);<br />
textureRect[i]->setInternalFormat(GL_RGBA);<br />
textureRect[i]->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);<br />
textureRect[i]->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);</p>
<p dir="ltr">if (useHDR)<br />
{<br />
// Default HDR format<br />
textureRect[i]->setInternalFormat(GL_RGBA32F_ARB);</p>
<p dir="ltr">// GL_FLOAT_RGBA32_NV might be supported on pre 8-series GPUs<br />
//textureRect[i]->setInternalFormat(GL_FLOAT_RGBA32_NV);</p>
<p dir="ltr">// GL_RGBA16F_ARB can be used with this example,<br />
// but modify e-12 and e12 in the shaders accordingly<br />
//textureRect[i]->setInternalFormat(GL_RGBA16F_ARB);</p>
<p dir="ltr">textureRect[i]->setSourceFormat(GL_RGBA);<br />
textureRect[i]->setSourceType(GL_FLOAT);<br />
}<br />
}</p>
<p dir="ltr">// first create the geometry of the quad<br />
{<br />
osg::Geometry* polyGeom = new osg::Geometry();</p>
<p dir="ltr">polyGeom->setSupportsDisplayList(false);</p>
<p dir="ltr">osg::Vec3Array* vertices = new osg::Vec3Array;<br />
osg::Vec2Array* texcoords = new osg::Vec2Array;</p>
<p dir="ltr">vertices->push_back(osg::Vec3d(0,0,0));<br />
texcoords->push_back(osg::Vec2(0,0));</p>
<p dir="ltr">vertices->push_back(osg::Vec3d(1,0,0));<br />
texcoords->push_back(osg::Vec2(tex_width,0));</p>
<p dir="ltr">vertices->push_back(osg::Vec3d(1,0,1));<br />
texcoords->push_back(osg::Vec2(tex_width,tex_height));</p>
<p dir="ltr">vertices->push_back(osg::Vec3d(0,0,1));<br />
texcoords->push_back(osg::Vec2(0,tex_height));</p>
<p dir="ltr">polyGeom->setVertexArray(vertices);<br />
polyGeom->setTexCoordArray(0,texcoords);</p>
<p dir="ltr">osg::Vec4Array* colors = new osg::Vec4Array;<br />
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));<br />
polyGeom->setColorArray(colors, osg::Array::BIND_OVERALL);</p>
<p dir="ltr">polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,vertices->size()));</p>
<p dir="ltr">// now we need to add the textures (generated by RTT) to the Drawable.<br />
osg::StateSet* stateset = new osg::StateSet;<br />
for (int i=0;i<NUM_TEXTURES;i++){<br />
stateset->setTextureAttributeAndModes(i, textureRect[i], osg::StateAttribute::ON);<br />
}</p>
<p dir="ltr">polyGeom->setStateSet(stateset);</p>
<p dir="ltr">// Attach a shader to the final quad to combine the input textures.<br />
if (useHDR) {<br />
static const char *shaderSource = {<br />
"uniform sampler2DRect textureID0;\n"<br />
"uniform sampler2DRect textureID1;\n"<br />
"uniform sampler2DRect textureID2;\n"<br />
"uniform sampler2DRect textureID3;\n"<br />
"uniform float width;\n"<br />
"uniform float height; \n"<br />
"void main(void)\n"<br />
"{\n"<br />
" gl_FragData[0] = \n"<br />
" vec4( -1e12 * texture2DRect( textureID0, gl_TexCoord[0].st ).rgb, 1) + \n"<br />
" vec4( 1e12 * texture2DRect( textureID1, gl_TexCoord[0].st ).rgb, 1) + \n"<br />
" vec4( 1e12 * texture2DRect( textureID2, gl_TexCoord[0].st ).rgb, 1) + \n"<br />
" vec4(-0.5e12 * texture2DRect( textureID3, gl_TexCoord[0].st ).rgb, 1); \n"<br />
"}\n"<br />
};<br />
osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT , shaderSource);<br />
osg::ref_ptr<osg::Program> program = new osg::Program;<br />
program->addShader( fshader.get());<br />
stateset->setAttributeAndModes( program.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );<br />
} else {<br />
static const char *shaderSource = {<br />
"uniform sampler2DRect textureID0;\n"<br />
"uniform sampler2DRect textureID1;\n"<br />
"uniform sampler2DRect textureID2;\n"<br />
"uniform sampler2DRect textureID3;\n"<br />
"void main(void)\n"<br />
"{\n"<br />
" gl_FragData[0] = \n"<br />
" vec4(texture2DRect( textureID0, gl_TexCoord[0].st ).rgb, 1) + \n"<br />
" vec4(texture2DRect( textureID1, gl_TexCoord[0].st ).rgb, 1) + \n"<br />
" vec4(texture2DRect( textureID2, gl_TexCoord[0].st ).rgb, 1) + \n"<br />
" -0.5*vec4(texture2DRect( textureID3, gl_TexCoord[0].st ).rgb, 1); \n"<br />
"}\n"<br />
};<br />
osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT , shaderSource);<br />
osg::ref_ptr<osg::Program> program = new osg::Program;<br />
program->addShader( fshader.get());<br />
stateset->setAttributeAndModes( program.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );</p>
<p dir="ltr">}</p>
<p dir="ltr">stateset->addUniform(new osg::Uniform("textureID0", 0));<br />
stateset->addUniform(new osg::Uniform("textureID1", 1));<br />
stateset->addUniform(new osg::Uniform("textureID2", 2));<br />
stateset->addUniform(new osg::Uniform("textureID3", 3));</p>
<p dir="ltr">//stateset->setDataVariance(osg::Object::DYNAMIC);</p>
<p dir="ltr">osg::Geode* geode = new osg::Geode();<br />
geode->addDrawable(polyGeom);</p>
<p dir="ltr">parent->addChild(geode);<br />
}</p>
<p dir="ltr">// now create the camera to do the multiple render to texture<br />
{<br />
osg::Camera* camera = new osg::Camera;</p>
<p dir="ltr">// set up the background color and clear mask.<br />
camera->setClearColor(osg::Vec4(0.1f,0.1f,0.3f,1.0f));<br />
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);</p>
<p dir="ltr">// the camera is going to look at our input quad<br />
camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1));<br />
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);<br />
camera->setViewMatrix(osg::Matrix::identity());</p>
<p dir="ltr">// set viewport<br />
camera->setViewport(0, 0, tex_width, tex_height);</p>
<p dir="ltr">// set the camera to render before the main camera.<br />
camera->setRenderOrder(osg::Camera::PRE_RENDER);</p>
<p dir="ltr">// tell the camera to use OpenGL frame buffer objects<br />
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);</p>
<p dir="ltr">// attach the textures to use<br />
for (int i=0; i<NUM_TEXTURES; i++) {<br />
if (useMultiSample)<br />
camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i), textureRect[i], 0, 0, false, 4, 4);<br />
else<br />
camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i), textureRect[i]);<br /></p>
<p dir="ltr">}</p>
<p dir="ltr">#if 0<br />
// test for new glEnablei/glDisablei functionality.<br />
camera->getOrCreateStateSet()->setAttribute(new osg::Enablei(GL_BLEND, 0));<br />
camera->getOrCreateStateSet()->setAttribute(new osg::Disablei(GL_BLEND, 1));<br />
#endif</p>
<p dir="ltr">// we can also read back any of the targets as an image, modify this image and push it back<br />
if (useImage) {<br />
// which texture to get the image from<br />
const int tex_to_get = 0;</p>
<p dir="ltr">osg::Image* image = new osg::Image;<br />
if (useHDR) {<br />
image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_FLOAT);<br />
} else {<br />
image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE);<br />
}</p>
<p dir="ltr">// attach the image so its copied on each frame.<br />
camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0 + tex_to_get), image);</p>
<p dir="ltr">camera->setPostDrawCallback(new MyCameraPostDrawCallback(image));</p>
<p dir="ltr">// push back the image to the texture<br />
textureRect[tex_to_get]->setImage(0, image);<br />
}</p>
<p dir="ltr">// add the subgraph to render<br />
camera->addChild(cam_subgraph);</p>
<p dir="ltr">parent->addChild(camera);<br />
}</p>
<p dir="ltr">return parent;<br />
}</p>
<p dir="ltr">int main( int argc, char **argv )<br />
{<br />
// use an ArgumentParser object to manage the program arguments.<br />
osg::ArgumentParser arguments(&argc,argv);</p>
<p dir="ltr">// set up the usage document, in case we need to print out how to use this program.<br />
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName() + " demonstrates the use of multiple render targets (MRT) with frame buffer objects (FBOs). A render to texture (RTT) camera is used to render to four textures using a single shader. The four textures are then combined to texture the viewed geometry.");<br />
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] ...");<br />
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information.");<br />
arguments.getApplicationUsage()->addCommandLineOption("--width","Set the width of the render to texture.");<br />
arguments.getApplicationUsage()->addCommandLineOption("--height","Set the height of the render to texture.");<br />
arguments.getApplicationUsage()->addCommandLineOption("--image","Render one of the targets to an image, then apply a post draw callback to modify it and use this image to update the final texture. Print some texture values when using HDR.");<br />
arguments.getApplicationUsage()->addCommandLineOption("--hdr","Use high dynamic range (HDR). Create floating point textures to render to.");</p>
<p dir="ltr">// construct the viewer.<br />
osgViewer::Viewer viewer(arguments);</p>
<p dir="ltr">// if user request help write it out to cout.<br />
if (arguments.read("-h") || arguments.read("--help"))<br />
{<br />
arguments.getApplicationUsage()->write(std::cout);<br />
return 1;<br />
}</p>
<p dir="ltr">unsigned tex_width = 512;<br />
unsigned tex_height = 512;<br />
while (arguments.read("--width", tex_width)) {}<br />
while (arguments.read("--height", tex_height)) {}</p>
<p dir="ltr">bool useHDR = false;<br />
while (arguments.read("--hdr")) { useHDR = true; }</p>
<p dir="ltr">bool useImage = false;<br />
while (arguments.read("--image")) { useImage = true; }</p>
<p dir="ltr">bool useMultiSample = false;<br />
while (arguments.read("--ms")) { useMultiSample = true; }</p>
<p dir="ltr">osg::Group* subGraph = createRTTQuad(tex_width, tex_height, useHDR);</p>
<p dir="ltr">osg::Group* rootNode = new osg::Group();<br />
rootNode->addChild(createScene(subGraph, tex_width, tex_height, useHDR, useImage, useMultiSample));</p>
<p dir="ltr"> rootNode->addChild(createScene(subGraph, tex_width, tex_height, useHDR, useImage, useMultiSample));<br /></p>
<p dir="ltr"> //Some code to view the intermediate textures<br />
osg::ref_ptr<osg::Camera> testTex =<br />
createTextureDisplayQuad(osg::Vec3(0, 0.7, 0),<br />
textureRect[0],<br />
tex_width);<br />
osg::ref_ptr<osg::Camera> testTex2 =<br />
createTextureDisplayQuad(osg::Vec3(0, 0.35, 0),<br />
textureRect[1],<br />
tex_width);</p>
<p dir="ltr">rootNode->addChild(testTex);<br />
rootNode->addChild(testTex2);</p>
<p dir="ltr"> // add model to the viewer.<br />
viewer.setSceneData( rootNode );<br />
viewer.realize();<br />
viewer.getCamera()->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(true);</p>
<p dir="ltr"> return <a href="http://viewer.run">viewer.run</a>();<br />
}<br /><br /><br /><br /><br /></p>
<p dir="ltr">Thank you!!</p>
<p dir="ltr">Cheers,<br />
antiro[/code]</p>
<p dir="ltr">------------------<br />
Read this topic online here:<br />
<a href="http://forum.openscenegraph.org/viewtopic.php?p=71613#71613">http://forum.openscenegraph.org/viewtopic.php?p=71613#71613</a><br /><br /><br /><br /></p>
<p dir="ltr">_______________________________________________<br />
osg-users mailing list<br />
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br />
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br />
</p>
</blockquote></div></body></html></body></html>