[osg-users] Billboard with two layer

2011-03-05 Thread Heiko Thiel
Hi,

currently I create a healthbar for a minion. So I use a billboard for it. But 
now I have a problem: I want give the billboard a background. So I have 
following both gemoetries:

A colored border, filled with another which is a little bit transparent.

Code:

||
|  |
||




And the healthbar:


Code:

☐☐




Combined it should look like this:


Code:

||
|☐☐|
||




But how to combine it without flickering?

Currently I have (_createHealthGemoetry ist nearly the same like 
_createBackgroundGemoetry, but smaller so it fit into the other):


Code:
HealthBar::HealthBar()
{
this-setMode(osg::Billboard::POINT_ROT_EYE);

_health = 1;
_maxHealth = 1;
this-_setBillBoardStateSet();
this-addDrawable(_createBackgroundGemoetry());
this-addDrawable(_createHealthGemoetry());
}

void HealthBar::_setBillBoardStateSet()
{
osg::StateSet* billBoardStateSet = new osg::StateSet(); 
billBoardStateSet-setMode( GL_LIGHTING, osg::StateAttribute::OFF );
billBoardStateSet-setAttributeAndModes( new osg::BlendFunc, 
osg::StateAttribute::ON );
billBoardStateSet-setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

// Make sure the geometry has the correct state
this-setStateSet(billBoardStateSet);
}

osg::Drawable* HealthBar::_createBackgroundGemoetry()
{
float width = 0.8f;
float height = 0.12f;

osg::Geometry* backgroundGeometry = new osg::Geometry();

osg::Texture2D* backgroundTexture = 
AssetLibrary::instance()-getTexture(healthbar/test.png);

// Declare and initialize geometry
backgroundGeometry = new osg::Geometry();

//add vertices and texture
osg::Vec3Array* verts = new osg::Vec3Array(4);  
(*verts)[0] = osg::Vec3( -width/2, 0, -height/2);
(*verts)[1] = osg::Vec3( +width/2, 0, -height/2);
(*verts)[2] = osg::Vec3( +width/2, 0, +height/2);
(*verts)[3] = osg::Vec3( -width/2, 0, +height/2);
backgroundGeometry-setVertexArray(verts);


osg::Vec2Array* texCoords = new osg::Vec2Array(4);
(*texCoords)[0].set(0.0f, 0.0f);
(*texCoords)[1].set(1.0f, 0.0f);
(*texCoords)[2].set(1.0f, 1.0f);
(*texCoords)[3].set(0.0f, 1.0f);
backgroundGeometry-setTexCoordArray(0, texCoords);

osg::StateSet* stateSet = new osg::StateSet();
stateSet-setTextureAttributeAndModes(0, backgroundTexture, 
osg::StateAttribute::ON);
backgroundGeometry-setStateSet(stateSet);

// Add a primitive set (QUADS) to the geometry
backgroundGeometry-addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));

osg::Vec4Array* colors = new osg::Vec4Array;
colors-push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
backgroundGeometry-setColorArray(colors);
backgroundGeometry-setColorBinding(osg::Geometry::BIND_OVERALL);

return backgroundGeometry;
}



Thank you!

Cheers,
Heiko

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=37364#37364





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Billboard with two layer

2011-03-05 Thread Sergey Polischuk
Hi, Heiko

You can use PolygonOffset state attribute on one of your drawables to beat 
flickering.

Cheers, Sergey.

05.03.2011, 14:18, Heiko Thiel osgfo...@tevs.eu:
 Hi,

 currently I create a healthbar for a minion. So I use a billboard for it. But 
 now I have a problem: I want give the billboard a background. So I have 
 following both gemoetries:

 A colored border, filled with another which is a little bit transparent.

 Code:

 ||
 |  |
 ||

 And the healthbar:

 Code:

 ☐☐

 Combined it should look like this:

 Code:

 ||
 |☐☐    |
 ||

 But how to combine it without flickering?

 Currently I have (_createHealthGemoetry ist nearly the same like 
 _createBackgroundGemoetry, but smaller so it fit into the other):

 Code:
 HealthBar::HealthBar()
 {
 this-setMode(osg::Billboard::POINT_ROT_EYE);

 _health = 1;
 _maxHealth = 1;
 this-_setBillBoardStateSet();
 this-addDrawable(_createBackgroundGemoetry());
 this-addDrawable(_createHealthGemoetry());
 }

 void HealthBar::_setBillBoardStateSet()
 {
 osg::StateSet* billBoardStateSet = new osg::StateSet();
 billBoardStateSet-setMode( GL_LIGHTING, osg::StateAttribute::OFF );
 billBoardStateSet-setAttributeAndModes( new osg::BlendFunc, 
 osg::StateAttribute::ON );
 billBoardStateSet-setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

 // Make sure the geometry has the correct state
 this-setStateSet(billBoardStateSet);
 }

 osg::Drawable* HealthBar::_createBackgroundGemoetry()
 {
 float width = 0.8f;
 float height = 0.12f;

 osg::Geometry* backgroundGeometry = new osg::Geometry();

 osg::Texture2D* backgroundTexture = 
 AssetLibrary::instance()-getTexture(healthbar/test.png);

 // Declare and initialize geometry
 backgroundGeometry = new osg::Geometry();

 //add vertices and texture
 osg::Vec3Array* verts = new osg::Vec3Array(4);
 (*verts)[0] = osg::Vec3( -width/2, 0, -height/2);
 (*verts)[1] = osg::Vec3( +width/2, 0, -height/2);
 (*verts)[2] = osg::Vec3( +width/2, 0, +height/2);
 (*verts)[3] = osg::Vec3( -width/2, 0, +height/2);
 backgroundGeometry-setVertexArray(verts);

 osg::Vec2Array* texCoords = new osg::Vec2Array(4);
 (*texCoords)[0].set(0.0f, 0.0f);
 (*texCoords)[1].set(1.0f, 0.0f);
 (*texCoords)[2].set(1.0f, 1.0f);
 (*texCoords)[3].set(0.0f, 1.0f);
 backgroundGeometry-setTexCoordArray(0, texCoords);

 osg::StateSet* stateSet = new osg::StateSet();
 stateSet-setTextureAttributeAndModes(0, backgroundTexture, 
 osg::StateAttribute::ON);
 backgroundGeometry-setStateSet(stateSet);

 // Add a primitive set (QUADS) to the geometry
 backgroundGeometry-addPrimitiveSet(new 
 osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));

 osg::Vec4Array* colors = new osg::Vec4Array;
 colors-push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
 backgroundGeometry-setColorArray(colors);
 backgroundGeometry-setColorBinding(osg::Geometry::BIND_OVERALL);

 return backgroundGeometry;
 }

 Thank you!

 Cheers,
 Heiko

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=37364#37364

 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org