Re: [osg-users] Using multiples texture for a geometry

2016-05-04 Thread Florian GOLESTIN
Hi Robert,

I tried without the SmoothingVisitor but it does not change anything.


However during my tests today I put a "Axes" object (the axes.osgt model from 
the OpenSceneGraph examples) and some part of the texture on the block below 
the object just appeared but really dark.
So it it make me think that it's not a texture problem but maybe a light 
problem.

I've tried then to use a full ambiant light:

Code:

osg::ref_ptr createLightSource( unsigned int num,
  const osg::Vec3& trans,
  const osg::Vec4& color )
{
  osg::ref_ptr light = new osg::Light;
  light->setLightNum( num );
  light->setDiffuse( color );

  /* full scene lightened: */
  light->setAmbient(osg::Vec4(1.0,1.0,1.0,1.0));
  light->setSpecular(osg::Vec4(1,1,1,1));  // some examples don't have this one

  
  light->setPosition( osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f) );
  osg::ref_ptr lightSource = new
osg::LightSource;
  lightSource->setLight( light );
  osg::ref_ptr sourceTrans = new osg::MatrixTransform;
  sourceTrans->setMatrix( osg::Matrix::translate(trans) );
  sourceTrans->addChild( lightSource.get() );
  return sourceTrans;
}

int main(int argc, char **argv)
{
  osg::ArgumentParser arguments(,argv);
  
  osg::ref_ptr root = new osg::Group;

  root->addChild(createLightSource(0, osg::Vec3(0, -2.0, 0), osg::Vec4(1.0, 
1.0, 1.0, 1.0)));
  root->addChild(createLightSource(1, osg::Vec3(0, -16.0, 10.0), osg::Vec4(1.0, 
1.0, 1.0, 1.0)));

  root->getOrCreateStateSet()->setMode( GL_LIGHT0, osg::StateAttribute::ON );
  root->getOrCreateStateSet()->setMode( GL_LIGHT1, osg::StateAttribute::ON );





Now the texture appears but are really dark such as there is no light.

Is it something related to states and inheritance?

Thanks,
Florian

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





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


Re: [osg-users] some problem about hud and window size

2016-05-04 Thread Trajce Nikolov NICK
wrong :-) .. In the update callback get a handle of the main camera :-)

Cheers,
Nick

On Wed, May 4, 2016 at 6:17 PM, Trajce Nikolov NICK <
trajce.nikolov.n...@gmail.com> wrote:

> hi,
>
> you can do an UpdateCallback for your ortho camera that will set the
> proper dimensions based on the Viewport
>
> something like this:
> struct UpdateOrthoCameraCallback : public osg::NodeCallback
> {
> virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
> {
> osg::Camera* camera = dynamic_cast(node);
> if (camera)
> {
> osg::Viewport* vp = camera->getViewport();
> camera->setProjectionMatrix(osg::Matrixd::ortho2D(0, vp->width(), 0,
> vp->height()));
> }
> }
> };
> myOrthoCamera->setUpdateCallback(new UpdateOrthoCameraCallback);
>
> On Tue, May 3, 2016 at 11:35 AM, John Lee <357059...@qq.com> wrote:
>
>> Hi,
>>
>> First, I drew some tags dynamically using HUD camera on the render window
>> size which is 1100X679, but when I change the length-width ratio of the
>> render window size, the tags positions changed and it was wrong.
>> Can anyone tell me how can i solve this problem.
>>
>> Thank you!
>>
>> Cheers,
>> Lee
>>
>> --
>> Read this topic online here:
>> http://forum.openscenegraph.org/viewtopic.php?p=67044#67044
>>
>>
>>
>>
>> Attachments:
>> http://forum.openscenegraph.org//files/2_198.png
>> http://forum.openscenegraph.org//files/1_180.png
>>
>>
>> ___
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>
>
> --
> trajce nikolov nick
>



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


Re: [osg-users] some problem about hud and window size

2016-05-04 Thread Trajce Nikolov NICK
hi,

you can do an UpdateCallback for your ortho camera that will set the proper
dimensions based on the Viewport

something like this:
struct UpdateOrthoCameraCallback : public osg::NodeCallback
{
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
{
osg::Camera* camera = dynamic_cast(node);
if (camera)
{
osg::Viewport* vp = camera->getViewport();
camera->setProjectionMatrix(osg::Matrixd::ortho2D(0, vp->width(), 0,
vp->height()));
}
}
};
myOrthoCamera->setUpdateCallback(new UpdateOrthoCameraCallback);

On Tue, May 3, 2016 at 11:35 AM, John Lee <357059...@qq.com> wrote:

> Hi,
>
> First, I drew some tags dynamically using HUD camera on the render window
> size which is 1100X679, but when I change the length-width ratio of the
> render window size, the tags positions changed and it was wrong.
> Can anyone tell me how can i solve this problem.
>
> Thank you!
>
> Cheers,
> Lee
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=67044#67044
>
>
>
>
> Attachments:
> http://forum.openscenegraph.org//files/2_198.png
> http://forum.openscenegraph.org//files/1_180.png
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



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


[osg-users] some problem about hud and window size

2016-05-04 Thread John Lee
Hi,

First, I drew some tags dynamically using HUD camera on the render window size 
which is 1100X679, but when I change the length-width ratio of the render 
window size, the tags positions changed and it was wrong.
Can anyone tell me how can i solve this problem.

Thank you!

Cheers,
Lee

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




Attachments: 
http://forum.openscenegraph.org//files/2_198.png
http://forum.openscenegraph.org//files/1_180.png


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


[osg-users] some problem about hud and window size

2016-05-04 Thread John Lee
Hi,

First i drew some tags by HUD on the window size which is 1100X679, and it was 
correct. But when i change the window's length-width ratio the tag's position 
changed and it became wrong.
Can anyone tell me how i can solve this problem?

Thank you!

Cheers,
John

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





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


Re: [osg-users] Using multiples texture for a geometry

2016-05-04 Thread Robert Osfield
HI Florian,

I can't any obvious mistakes, but the use of the SmoothingVisitor looks
redudent to me as you are providing your own normals.  Try comment it out.

Robert.

On 3 May 2016 at 21:13, Florian GOLESTIN  wrote:

> Hi Robert,
>
> Sorry my mistake, I wanted to put only the interesting part but this is
> not efficient.
> No more censure!
>
>
> Code:
>
> namespace Soleil
> {
>
>   LevelReader::LevelReader()
>   {
> //supportsExtension("level", "Text map format for Donjon");
>   }
>
>   LevelReader::~LevelReader()
>   {
>   }
>
>
>   osg::ref_ptr  LevelReader::readFile(const std::string ) const
>   {
> std::string fileName = osgDB::findDataFile(file);
> if (fileName.empty()) return nullptr; // TODO throw e?
>
> errno = 0;
> std::cout << "Stream: " << fileName.c_str() << "\n";
> std::ifstream stream;
> stream.exceptions(std::ifstream::failbit); //  | std::ifstream::badbit
> stream.open(fileName.c_str(), std::ios::in);
> if (!stream) return nullptr; // TODO throw e
>
> return readStream(stream);
>   }
>
>   osg::ref_ptr LevelReader::readStream(std::istream ) const
>   {
> charblock;  // current reading block
> float   x = 0;  // Current position on x
> float   y = 0;  // Current position on y
> int wallCount = 0;  // Number of cubes
> float   maxX = 0;   // Max size of the map in X
>
>
> osg::ref_ptr level = new Soleil::Level();
> std::string line;
> while(std::getline(stream, line))
>   {
> std::stringstream linestream(line);
>
> while (linestream >> block)
>   {
> /* TODO Configurable size for the blocks */
> float posx = 1.0 * x;
> float posy = 1.0 * y;
> float endx = posx + 1.0;
> float endy = posy + 1.0;
>
> bool blockFound = false;
> switch (block)
>   {
>   case '.':
> break;
>   case 'D':
> level->_startingPosition = osg::Vec3(posx + .5, posy + .5,
> .3);
> blockFound = true;
> break;
>   case 'd':
> level->_startingOrientation = osg::Vec3(posx + .5, posy +
> .5, .3);
> blockFound = true;
> break;
>   case 'x':
> if (wallCount % 2)
>   {
> std::cout << "1" << "\n";
> createCube(level.get(), *level->texcoords,
> *level->texcoords2, posx, posy, endx, endy);
>   }
> else
>   {
> std::cout << "2" << "\n";
> createCube(level.get(), *level->texcoords2,
> *level->texcoords, posx, posy, endx, endy);
>   }
> blockFound = true;
> wallCount++;
> break;
> // default:
> //  blockFound = levelConfiguration(block);
> //  break;
>   }
> if (blockFound == false)
>   std::cout << "Unexpected character: " <<  block << std::endl;
>
> x += 1.0;
> maxX = std::max(x, maxX);
>   }
> x  = 0;
> y -= 1.0; // TODO Cube size
>   }
> // TODO read failed?
>
> // Floor -
> level->vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
> level->vertices->push_back(osg::Vec3(maxX, 0.0f, 0.0f));
> level->vertices->push_back(osg::Vec3(maxX, y, 0.0f));
> level->vertices->push_back(osg::Vec3(0, y, 0.0f));
>
> level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
> level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
> level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
> level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
>
> level->texcoords->push_back( osg::Vec2(0.0f, 0.0f) ); // 0
> level->texcoords->push_back( osg::Vec2(0.0f, 1.0f) ); // 1
> level->texcoords->push_back( osg::Vec2(1.0f, 1.0f) ); // 2
> level->texcoords->push_back( osg::Vec2(1.0f, 0.0f) ); // 3
>
>
> osg::ref_ptr geom = new osg::Geometry;
> geom->setVertexArray(level->vertices);
> geom->setNormalArray(level->normals,
> osg::Array::Binding::BIND_PER_VERTEX);
> geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0,
> 24*wallCount+4)); // +4 for the floor texture coordinates
> osgUtil::SmoothingVisitor::smooth(*geom);
> //
>
> //
> osg::ref_ptr geode = new osg::Geode;
> geode->addDrawable(geom);
>
>
> /* I added this in the hope to have the second texture appearing */
> // osg::Material* material = new osg::Material;
> // material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
> // material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1,
> 1, 1));
> //