<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style type="text/css">
<!--
/*
The original subSilver Theme for phpBB version 2+
Created by subBlue design
http://www.subBlue.com
NOTE: These CSS definitions are stored within the main page body so that you can use the phpBB2
theme administration centre. When you have finalised your style you could cut the final CSS code
and place it in an external file, deleting this section to save bandwidth.
*/
/* General page style. The scroll bar colours only visible in IE5.5+ */
body {
background-color: #E5E5E5;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11;
color: #000000;
}
/* General font families for common tags */
font,th,td,p { font-family: Verdana, Arial, Helvetica, sans-serif }
p, td { font-size : 11; color : #000000; }
a:link,a:active,a:visited { color : #006699; }
a:hover { text-decoration: underline; color : #DD6900; }
hr { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
h1,h2 { font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; font-size : 22px; font-weight : bold; text-decoration : none; line-height : 120%; color : #000000;}
/* This is the border line & background colour round the entire page */
.bodyline { background-color: #FFFFFF; border: 1px #98AAB1 solid; }
/* General text */
.gen { font-size : 12px; }
.genmed { font-size : 11px; }
.gensmall { font-size : 10px; line-height: 12px}
.gen,.genmed,.gensmall { color : #000000; }
a.gen,a.genmed,a.gensmall { color: #006699; text-decoration: none; }
a.gen:hover,a.genmed:hover,a.gensmall:hover { color: #DD6900; text-decoration: underline; }
/* Forum title: Text and link to the forums used in: index.php */
.forumlink { font-weight: bold; font-size: 12px; color : #006699; }
a.forumlink { text-decoration: none; color : #006699; }
a.forumlink:hover{ text-decoration: underline; color : #DD6900; }
/* The content of the posts (body of text) */
.postbody { font-size : 12px; line-height: 18px}
a.postlink:link { text-decoration: none; color : #006699 }
a.postlink:visited { text-decoration: none; color : #5493B4; }
a.postlink:hover { text-decoration: underline; color : #DD6900}
/* Quote & Code blocks */
.code {
font-family: Courier, 'Courier New', sans-serif; font-size: 11px; color: #006600;
background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
.quote {
font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #444444; line-height: 125%;
background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
-->
</style>
</head>
<body>
<div class="postbody">Hi Everyone,<br />
<br />
This might be a very n00b question to ask here, but alas, I'm stuck! I'm trying to create a background image for a prototype and so far I've been unsuccessful. I tried to search for an answer and none of them have been helpful so far. Here's the end result of what I have:<br />
<br />
</span><table class="bodyline" width="90%" cellspacing="1" cellpadding="3" border="0" align="center"><tr> <td class="helpline"><span class="genmed"><b>Code:</b><br />
<script type="text/javascript" src="./templates/select_expand_bbcodes.js"></script><br />
<script type="text/javascript"><br />
<br />
<!--<br />
<br />
var id = 'SXBB' + (1000 + Math.floor(Math.random() * 5000));<br />
SXBB[id] = new _SXBB(id);<br />
SXBB[id].T['select'] = 'Select';<br />
SXBB[id].T['expand'] = 'Expand';<br />
SXBB[id].T['contract'] = 'Contract';<br />
SXBB[id].writeCmd();<br />
<br />
//--><br />
<br />
</script><br />
</span></td><br />
</tr><br />
<tr><br />
<td class="code"><br />
<script type="text/javascript"><br />
<br />
<!--<br />
<br />
SXBB[id].writeDiv();<br />
<br />
//--><br />
<br />
</script><br />
// create a camera to set up the projection and model view matrices, and the subgraph to draw in the HUD<br />
osg::ref_ptr<osg::Camera> camera = new osg::Camera();<br />
<br />
// set the projection matrix<br />
camera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1280, 0, 1024));<br />
<br />
// set the view matrix<br />
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);<br />
camera->setViewMatrix(osg::Matrix::identity());<br />
<br />
// only clear the depth buffer<br />
//camera->setClearMask(GL_DEPTH_BUFFER_BIT);<br />
camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);<br />
<br />
// draw subgraph after main camera view.<br />
camera->setRenderOrder(osg::Camera::PRE_RENDER);<br />
<br />
// we don't want the camera to grab event focus from the viewers main camera(s).<br />
camera->setAllowEventFocus(false);<br />
<br />
osg::StateSet* cameraStateSet = camera->getOrCreateStateSet();<br />
cameraStateSet->setRenderBinDetails(1, "RenderBin");<br />
cameraStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);<br />
<br />
// add to this camera a subgraph to render<br />
{<br />
<br />
osg::Geode* geode = new osg::Geode();<br />
// turn lighting off for the text and disable depth test to ensure it's always ontop.<br />
osg::StateSet* stateset = geode->getOrCreateStateSet();<br />
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);<br />
{<br />
osg::BoundingBox bb;<br />
for (unsigned int i = 0; i < geode->getNumDrawables(); ++i)<br />
{<br />
bb.expandBy(geode->getDrawable(i)->getBound());<br />
}<br />
<br />
osg::Geometry* geom = new osg::Geometry();<br />
<br />
osg::Vec3Array* vertices = new osg::Vec3Array;<br />
float depth = bb.zMin() - 0.1;<br />
vertices->push_back(osg::Vec3(bb.xMin(), bb.yMax(), depth));<br />
vertices->push_back(osg::Vec3(bb.xMin(), bb.yMin(), depth));<br />
vertices->push_back(osg::Vec3(bb.xMax(), bb.yMin(), depth));<br />
vertices->push_back(osg::Vec3(bb.xMax(), bb.yMax(), depth));<br />
geom->setVertexArray(vertices);<br />
<br />
osg::Vec3Array* normals = new osg::Vec3Array;<br />
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));<br />
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);<br />
<br />
osg::Vec4Array* colors = new osg::Vec4Array;<br />
colors->push_back(osg::Vec4(1.0f, 1.0, 0.8f, 0.2f));<br />
geom->setColorArray(colors, osg::Array::BIND_OVERALL);<br />
<br />
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));<br />
<br />
osg::Vec2Array* uvCoords = new osg::Vec2Array();<br />
uvCoords->push_back(osg::Vec2(0.0f, 1.0f));<br />
uvCoords->push_back(osg::Vec2(0.0f, 0.0f));<br />
uvCoords->push_back(osg::Vec2(1.0f, 0.0f));<br />
uvCoords->push_back(osg::Vec2(1.0f, 1.0f));<br />
geom->setTexCoordArray(0, uvCoords);<br />
<br />
osg::StateSet* stateset = geom->getOrCreateStateSet();<br />
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);<br />
//stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON);<br />
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);<br />
<br />
auto backgroundImage = osgDB::readImageFile("data/images/bg_image_01.bmp");<br />
auto texture = new osg::Texture2D(backgroundImage);<br />
stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);<br />
<br />
geode->addDrawable(geom);<br />
}<br />
<br />
camera->addChild(geode);<br />
}<br />
osgViewer::Viewer::Windows windows;<br />
viewer.getWindows(windows);<br />
<br />
if (windows.empty())<br />
{<br />
return;<br />
}<br />
<br />
// set up cameras to render on the first window available.<br />
auto window = windows[0];<br />
camera->setGraphicsContext(window);<br />
auto windowTraits = window->getTraits();<br />
camera->setViewport(0, 0, windowTraits->width, windowTraits->height);<br />
<br />
if (viewer.addSlave(camera.get(), false))<br />
{<br />
osg::notify(osg::NotifySeverity::INFO) << "Successfully added camera as slave!" << std::endl;<br />
}<br />
else<br />
{<br />
osg::notify(osg::NotifySeverity::WARN) << "Failed to add camera as slave!" << std::endl;<br />
}<br />
<br />
<script type="text/javascript"><br />
<br />
<!--<br />
<br />
document.write('</div>');<br />
<br />
//--><br />
<br />
</script><br />
</td><br />
</tr></table><span class="postbody"><br />
<br />
The image gets loaded fine (due to the message I see in the console) and I see that the camera was added as a slave to the viewer. I based my code on the viewer example and on HUD examples.<br />
<br />
Any help to get this resolved will be much appreciated!<br />
<br />
Many thanks!<br />
<br />
Cheers,<br />
Vite Falcon</span><table class="bodyline" width="90%" cellspacing="1" cellpadding="3" border="0" align="center"><tr> <td class="helpline"><span class="genmed"><b>Code:</b><br />
<script type="text/javascript" src="./templates/select_expand_bbcodes.js"></script><br />
<script type="text/javascript"><br />
<br />
<!--<br />
<br />
var id = 'SXBB' + (1000 + Math.floor(Math.random() * 5000));<br />
SXBB[id] = new _SXBB(id);<br />
SXBB[id].T['select'] = 'Select';<br />
SXBB[id].T['expand'] = 'Expand';<br />
SXBB[id].T['contract'] = 'Contract';<br />
SXBB[id].writeCmd();<br />
<br />
//--><br />
<br />
</script><br />
</span></td><br />
</tr><br />
<tr><br />
<td class="code"><br />
<script type="text/javascript"><br />
<br />
<!--<br />
<br />
SXBB[id].writeDiv();<br />
<br />
//--><br />
<br />
</script><br />
<script type="text/javascript"><br />
<br />
<!--<br />
<br />
document.write('</div>');<br />
<br />
//--><br />
<br />
</script><br />
</td><br />
</tr></table><span class="postbody"></div>
<br /><div class="gensmall">------------------<br />
Read this topic online here:<br />
<a href="http://forum.openscenegraph.org/viewtopic.php?p=65639#65639" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=65639#65639</a><br />
<br />
</div>
</body>
</html>