[osg-users] Problem with make my own function

2015-07-29 Thread alvaro ginestar rodriguez
hi everyone !! i would like make a class and function for make a window in osg, 
i have this source, but when i tried them separately, it have errors.The file 
DemoVentana.cppit does well, but the other one no.

  #include Ventana.h

osg::Camera* createCamera(int x, int y, int w, int h)
{
	osg::ref_ptrosg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits;
	traits-x = x;
	traits-y = y;
	traits-width = w;
	traits-height = h;
	traits-doubleBuffer = true;
	traits-windowName = Funcion de Ventana;
	traits-windowDecoration = true;

	osg::ref_ptrosg::GraphicsContext gc = osg::GraphicsContext::createGraphicsContext(traits.get());

	osg::ref_ptrosg::Camera camera = new osg::Camera;
	camera-setGraphicsContext(gc.get());
	camera-setViewport(new osg::Viewport(0, 0, traits-width, traits-height));
	return camera.release();
}#ifndef H_VENTANA
#define H_VENTANA

#include osg/Group
#include osgViewer/Viewer

class Ventana 
{

public:
osg::Camera* createCamera(int x, int y, int w, int h);

};
#endif#include osg/Group
#include osgDB/ReadFile
#include osgViewer/Viewer

osg::Camera* createCamera(int x, int y, int w, int h)
{
	osg::ref_ptrosg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits;
	traits-x = x;
	traits-y = y;
	traits-width = w;
	traits-height = h;
	traits-doubleBuffer = true;
	traits-windowName = Funcion de Ventana;
	traits-windowDecoration = true;

	osg::ref_ptrosg::GraphicsContext gc =	osg::GraphicsContext::createGraphicsContext(traits.get());

	osg::ref_ptrosg::Camera camera = new osg::Camera;
	camera-setGraphicsContext(gc.get());
	camera-setViewport(new osg::Viewport(0, 0, traits-width, traits-height));
	return camera.release();
}

int main(int argc, char** argv)
{
	osg::ArgumentParser arguments(argc, argv);
	osg::Node* model = osgDB::readNodeFiles(arguments);
	if (!model) model = osgDB::readNodeFile(cow.osg);

	osgViewer::Viewer viewer;
	viewer.addSlave(createCamera(300, 100, 900, 600));//, osg::Matrixd::translate( 1.0,-1.0,0.0), osg::Matrixd(),false );
	viewer.setSceneData(model);
	return viewer.run();
}#include osgDB/ReadFile

#include Ventana.h

int main(int argc, char** argv)
{
	osg::ArgumentParser arguments(argc, argv);
	osg::Node* model = osgDB::readNodeFiles(arguments);
	if (!model) model = osgDB::readNodeFile(cow.osg);

	osgViewer::Viewer viewer;
	viewer.addSlave(createCamera(300, 100, 900, 600));
	viewer.setSceneData(model);
	return viewer.run();
}___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Problem with make my own function

2015-07-29 Thread Christian Schulte

  
  
Hello Alvaro (?),
  
  this isn't an OSG problem, it is a pure c++ coding problem...
  In your header file you declare a class with a public method, but
  you define a function that is not member of your class in your
  cpp. 
  You should define
  osg::Camera* Ventana::createCamera(int x, int y, int w, int h)
  instead of 
  osg::Camera* createCamera(int x, int y, int w, int h)
  
  Furthermore, you don't even instantiate your class Ventana in your
  main.
  In your main you should create an instance of Ventana 
  Ventana* myInstance = new Ventana();
  As you didn't define any constructor it will use a default
  generated constructor for your class.
  After this you can call 
  viewer-addSlave(myInstance-createCamera(300, 100, 900,
  600));
  This should make it work.
  You should consider review your coding basics...
  
  Regards,
  
  Christian
  
  
  Le 29/07/2015 13:36, alvaro ginestar rodriguez a crit:


  
  hi everyone !! i would like make a class and
function for make a window in osg, i have this source, but when
i tried them separately, it have errors.
The file "DemoVentana.cpp"it does well, but the other one
  no.




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




-- 
SCHULTE Christian
Ingnieur Recherche
Responsable du Laboratoire de Simulation
ONERA - DCSD/PSEV
Dpartement Commande des Systmes et Dynamique du Vol
ONERA - Centre de Salon de Provence
BA 701
13661 SALON AIR Cedex - France
Tel :04.90.17.01.45
  

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