[osg-users] Build UserInterface
Ahmed Magdy Guda
Aboguda_110 at hotmail.com
Sun Apr 17 14:20:52 PDT 2011
ahmed89 wrote:
> Hi,
> i am currently using osg version 1.2 and i am trying to make user interface
> so user can submit commands .. etc
> i can use MFC or whatever technology that will help
>
> any advice that can help me doing this ?
>
> ...
>
> Thank you!
>
> Cheers,
> ahmed
you can use wxWidget wxGlCanavs which controls the render method
Code:
#include "wxglcanvassubclass.h"
#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgProducer/Viewer>
#include <osg/PositionAttitudeTransform>
#include <osgGA/TrackballManipulator>
BEGIN_EVENT_TABLE(wxGLCanvasSubClass, wxGLCanvas)
EVT_PAINT (wxGLCanvasSubClass::Paintit)
END_EVENT_TABLE()
wxGLCanvasSubClass::wxGLCanvasSubClass(wxFrame *parent)
:wxGLCanvas(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxT("GLCanvas")){
osg::setNotifyLevel(osg::ALWAYS);
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
viewer.getCullSettings().setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
float cx = GetSystemMetrics(SM_CXSCREEN);
cx/=10;
float cy = GetSystemMetrics(SM_CYSCREEN);
cy/=10;
int width = cx * 5.5;
int height = cy * 6;
int xPos = cx;
int yPos = cy * 2.7;
viewer.getCamera(0)->getRenderSurface()->setWindowRectangle(xPos,yPos,width,height);
#ifndef __linux
viewer.getCamera(0)->getRenderSurface()->fullScreen(false);
#endif
osg::Group* foregroundGroup = new osg::Group();
osg::Node* modelNode = osgDB::readNodeFile("H2SO4.3DS");
foregroundGroup->addChild(modelNode);
foregroundGroup->getOrCreateStateSet()->setMode(GL_LIGHT_MODEL_AMBIENT, osg::StateAttribute::OFF);
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild(foregroundGroup);
viewer.setSceneData(root.get());
viewer.realize();
}
void wxGLCanvasSubClass::Paintit(wxPaintEvent& WXUNUSED(event)){
Render();
}
void wxGLCanvasSubClass::Render()
{
SetCurrent();
wxPaintDC(this);
viewer.sync();
viewer.update();
viewer.frame();
}
that is it in the constructor you init the osg defaults
and in the render method put the code in the while(!viewer.done) loop in
osg
after that all you need is new wxGLCanvasSubClass(this); in the
wxFrame child class in your app
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38539#38539
Attachments:
http://forum.openscenegraph.org//files/wxosg_146.rar
More information about the osg-users
mailing list