Hello,
is anyone interested in a sample integration of osgProducer::Viewer from
OSG1.1 in wxWidgets (at the moment GTK)? A minimal example is attached.
It would be nice if there is a standard implementation of a wxOsgProducerView
(not to mention other working minimal examples for Qt, Eclipse, ... on
different Platforms) that finds a place in the OSG release or at least on the
web page.
There are some issues left (Hey, but it is running fast if you do not
resize :-):
- RenderSurface seems to misinterpret the coordinates when resizing with
setWindowRectangle (implemented workaround at the moment: call XWindowResize
by hand, which is not really optimal).
- RenderSurface dies when calling fullScreen if the RanderSurface has a
custom WindowParent (The WindowParent is correct, I double checked that).
- Keyboard input does not reach osgProducer::Viewer.
Perhaps somebody has some ideas on these issues or a superior implementation,
that I would be very interested in!
Detlef
/* wxOSGProducerViewer - Copyright (C) 2006 Detlef Mages
*
* This sample is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This sample 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
* OpenSceneGraph Public License for more details.
*/
#include <wx/wx.h>
#include <stdio.h>
#include <unistd.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xmd.h>
#include <X11/cursorfont.h>
#include <gdk/gdkx.h>
#include <wx/defs.h>
#include <wx/dcclient.h>
#include <gtk/gtkwidget.h>
#include <gdk/gdktypes.h>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <osgProducer/Viewer>
#include <iostream>
using namespace std;
class wxOsgProducerViewer:public wxWindow{
public:
wxOsgProducerViewer(wxWindow* parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0, const wxString& name = wxPanelNameStr);
~wxOsgProducerViewer();
void OnTimer(wxTimerEvent& event);
void OnCreate(wxWindowCreateEvent& WXUNUSED(event));
void OnResize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& WXUNUSED(event));
void OnEraseBackground(wxEraseEvent& WXUNUSED(event));
osgProducer::Viewer* getViewer(){return &m_viewer;}
protected:
DECLARE_EVENT_TABLE()
osgProducer::Viewer m_viewer;
wxTimer m_timer;
};
BEGIN_EVENT_TABLE(wxOsgProducerViewer,wxWindow)
EVT_ERASE_BACKGROUND(wxOsgProducerViewer::OnEraseBackground)
EVT_WINDOW_CREATE(wxOsgProducerViewer::OnCreate)
EVT_SIZE(wxOsgProducerViewer::OnResize)
EVT_PAINT(wxOsgProducerViewer::OnPaint)
EVT_TIMER(-1, wxOsgProducerViewer::OnTimer)
END_EVENT_TABLE()
wxOsgProducerViewer::wxOsgProducerViewer(wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style, const wxString& name)
: wxWindow(parent,id,pos,size,
style
|wxWS_EX_TRANSIENT
|wxWS_EX_PROCESS_UI_UPDATES
,name),
m_timer(this)// initialise the timer
{
// we dont need it, as everything is painted by ourselves.
SetAutoLayout(false);
m_viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
GdkWindow *window = this->GetHandle()->window;
std::cout << GDK_WINDOW_XID(window) << std::endl;
std::cout << GDK_WINDOW_XDISPLAY(window) << std::endl;
Producer::RenderSurface * rs = m_viewer.getCamera(0)->getRenderSurface();
rs->setDisplay( GDK_WINDOW_XDISPLAY(window) );
rs->setParentWindow( GDK_WINDOW_XID(window) );
// The call to fullScreen seems to be bugous, and leads to occasional crashes
// Relying on XFunctions instead for resizing, The viewport is somehow
// updated correctly.
// rs->fullScreen(false);
m_viewer.setSceneData(osgDB::readNodeFile("<SomeOSGFile>"));
cout << "realizing" << endl;
m_viewer.realize();
cout << "finished OnInit" << endl;
m_timer.Start( 10 );
}
void wxOsgProducerViewer::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) {}
wxOsgProducerViewer::~wxOsgProducerViewer(){
cout << "wxOsgProducerViewer" << endl;
m_viewer.setDone(true);
m_viewer.sync();
}
void wxOsgProducerViewer::OnResize(wxSizeEvent& event) {
unsigned int w, h;
GetClientSize((int*)&w, (int*)&h);
Producer::RenderSurface * rs = m_viewer.getCamera(0)->getRenderSurface();
// The method: RenderSurface->setWindowRectangle misplaces the window
// (y-coord ist constantly changing) --> Directly call the X11 Method
XResizeWindow(rs->getDisplay(),
rs->getWindow(), w, h);
Refresh();
Update();
}
void wxOsgProducerViewer::OnPaint(wxPaintEvent& WXUNUSED(event)){
m_viewer.sync();
m_viewer.update();
m_viewer.frame();
}
void wxOsgProducerViewer::OnCreate(wxWindowCreateEvent& WXUNUSED(event)){
}
void wxOsgProducerViewer::OnTimer(wxTimerEvent &event){
Refresh();
}
class TestApp : public wxApp{
public:
virtual bool OnInit();
wxOsgProducerViewer *myWxWindow;
};
IMPLEMENT_APP(TestApp)
bool TestApp::OnInit() {
wxFrame *frame = new wxFrame((wxFrame *) NULL, -1, "Test", wxPoint(500,700), wxSize(200,200));
frame->Show(TRUE);
SetTopWindow(frame);
myWxWindow = new wxOsgProducerViewer(frame, -1);
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/