All,
I am hoping someone with a little more experience could help me out. I
have an application that I am working on to learn how to program using
OSG.
I have used Virtual Planet Builder (VPB) to generate a model of the
earth using the BMNG data. I start my application and use File->Open
and navigate to the location of my earth.ive file. When the model is
displayed, it is not displayed inside my application window, but as a
full screen view in a osgViewer.
I know why is it doing this, but I am not familiar with using the
drawing context to correct the problem. I have attached the .h and .ccp
files from my program where the problem exists. I have a
osgViewer::Viewer m_Viewer object defined in the header. The Read
function is what I use to display the model and the function is as
follows:
void KMapView::open(QString filename)
{
m_Viewer.setSceneData(osgDB::readNodeFile(filename));
m_Viewer.run();
}
This I believe is my problem. The m_Viewer is not part of the
GraphicsWindow object and is getting started as a seperate thread than
my application.
First, am I on the right track that this is my problem? If so, how do I
pass the data in the earth.ive file to a graphic window object to be
rendered? I am new to graphics programming so please forgive the newbie
type question.
Thanks,
Michael
/***************************************************************************
* Copyright (C) 2007 by Michael W. Hall *
* [EMAIL PROTECTED] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "kmapview.h"
#include <qpainter.h>
#include <qlayout.h>
#include <kurl.h>
#include <ktrader.h>
#include <klibloader.h>
#include <kmessagebox.h>
#include <krun.h>
#include <klocale.h>
#include <osgDB/ReadFile>
KMapView::KMapView(QWidget *parent)
: QGLWidget(parent),
DCOPObject("KMapIface")
{
// Get a graphics context.
m_gw = new osgViewer::GraphicsWindowEmbedded(0,0,width(),height());
// Set the viewport.
getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
// Set the Projection Matrix.
getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width())/static_cast<double>(height()), 1.0f, 10000.0f);
// Set the graphics context.
getCamera()->setGraphicsContext(getGraphicsWindow());
// Set our threading model.
setThreadingModel(osgViewer::Viewer::SingleThreaded);
// Create our world
// createWorld();
}
KMapView::~KMapView()
{
}
osgViewer::GraphicsWindow* KMapView::getGraphicsWindow()
{
return m_gw.get();
}
bool createWorld(const std::string& left_hemisphere, const std::string& right_hemisphere, const std::string& baseName, unsigned int numLevels)
{
osgDB::ReaderWriter* readerWriter = osgDB::Registry::instance()->getReaderWriterForExtension("gdal");
}
void KMapView::print(QPainter *p, int height, int width)
{
// do the actual printing, here
// p->drawText(etc..)
}
QString KMapView::currentURL()
{
return m_html->url().url();
}
void KMapView::open(QString filename)
{
m_Viewer.setSceneData(osgDB::readNodeFile(filename));
m_Viewer.run();
}
//void KMapView::openURL(const KURL& url)
//{
// m_html->openURL(url);
//}
void KMapView::slotOnURL(const QString& url)
{
emit signalChangeStatusbar(url);
}
void KMapView::slotSetTitle(const QString& title)
{
emit signalChangeCaption(title);
}
#include "kmapview.moc"
/***************************************************************************
* Copyright (C) 2007 by Michael W. Hall *
* [EMAIL PROTECTED] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _KMAPVIEW_H_
#define _KMAPVIEW_H_
#include <qwidget.h>
#include <kparts/part.h>
#include <kmapiface.h>
#include <qgl.h>
#include <osgViewer/Viewer>
class QPainter;
class KURL;
/**
* This is the main view class for KMap. Most of the non-menu,
* non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
* here.
*
* The KMapView class creates our osgViewer::Viewer for displaying
* our 3D graphics.
*
* @short Main view
* @author Michael W. Hall <[EMAIL PROTECTED]>
* @version 0.1
*/
class KMapView : public QGLWidget, public osgViewer::Viewer, public KMapIface
{
Q_OBJECT
public:
/**
* Default constructor
*/
KMapView(QWidget* parent);
/**
* Destructor
*/
virtual ~KMapView();
// Gets our graphics window object.
osgViewer::GraphicsWindow* getGraphicsWindow();
/**
* Random 'get' function
*/
QString currentURL();
/**
* Random 'set' function accessed by DCOP
*/
virtual void open(QString filename);
/**
* Random 'set' function
*/
//virtual void openURL(const KURL& url);
/**
* Print this view to any medium -- paper or not
*/
void print(QPainter *, int height, int width);
signals:
/**
* Use this signal to change the content of the statusbar
*/
void signalChangeStatusbar(const QString& text);
/**
* Use this signal to change the content of the caption
*/
void signalChangeCaption(const QString& text);
private slots:
void slotOnURL(const QString& filename);
void slotSetTitle(const QString& title);
protected:
//void initializeGL();
//void paintEvent(QPaintEvent* paintEvent);
//void paintGL();
//void resizeGL(int width, int height);
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> m_gw;
private:
KParts::ReadOnlyPart *m_html;
osgViewer::Viewer m_Viewer;
};
#endif // _KMAPVIEW_H_
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org