two_render_widgets.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "ogre_tools/render_system.h"
00031 #include "ogre_tools/render_widget.h"
00032 
00033 #include <QApplication>
00034 #include <QTimer>
00035 #include <QVBoxLayout>
00036 #include <QPushButton>
00037 
00038 #include <OGRE/OgreRenderWindow.h>
00039 #include <OGRE/OgreEntity.h>
00040 
00041 using namespace ogre_tools;
00042 
00043 int main( int argc, char** argv )
00044 {
00045   // initialize the entire render system
00046   RenderSystem* render_system = RenderSystem::get();
00047 
00048   QApplication app( argc, argv );
00049 
00050 
00051   // make the render window
00052   RenderWidget* window = new RenderWidget( render_system );
00053   window->setWindowTitle( "I hope this is not all black." );
00054 
00055   QVBoxLayout* layout = new QVBoxLayout;
00056   layout->addWidget( window );
00057   layout->addWidget( new QPushButton( "chubs" ));
00058 
00059   QWidget container;
00060   container.setLayout( layout );
00061   container.resize( 900, 600 );
00062   container.show();
00063 
00064   // Make a scene and show it in the window.
00065   Ogre::SceneManager* scene_manager = render_system->root()->createSceneManager( Ogre::ST_GENERIC );
00066 
00067   Ogre::Entity* thing = scene_manager->createEntity( "thing", "ogre_tools_cone.mesh" );
00068   Ogre::SceneNode* node = scene_manager->getRootSceneNode()->createChildSceneNode();
00069   node->attachObject( thing );
00070 
00071   scene_manager->setAmbientLight( Ogre::ColourValue( .5, .5, .5 ));
00072   Ogre::Light* light = scene_manager->createLight( "light" );
00073   light->setPosition( 20, 80, 50 );
00074 
00075   Ogre::Camera* camera = scene_manager->createCamera( "SampleCam" );
00076   camera->setPosition( Ogre::Vector3( 0, 0, 10 ));
00077   camera->lookAt( Ogre::Vector3( 0, 0, -300 ));
00078   camera->setNearClipDistance( 5 );
00079 
00080   Ogre::Viewport* viewport = window->getRenderWindow()->addViewport( camera );
00081   viewport->setBackgroundColour( Ogre::ColourValue( 0, 0, 1.0 ));
00082 
00083   camera->setAspectRatio( Ogre::Real( viewport->getActualWidth() ) / Ogre::Real( viewport->getActualHeight() ));
00084 
00085   // redraw every 33ms.
00086   QTimer timer;
00087   QObject::connect( &timer, SIGNAL(timeout()), window, SLOT(update()) );
00088   timer.start( 33 );
00089 
00090 
00091   RenderWidget window2( render_system );
00092   window2.resize( 400, 400 );
00093   window2.setWindowTitle( "I hope this is also not all black." );
00094   window2.show();
00095 
00096   Ogre::Camera* camera2 = scene_manager->createCamera( "SampleCam2" );
00097   camera2->setPosition( Ogre::Vector3( 0, 10, 0 ));
00098   camera2->setFixedYawAxis( false );
00099   camera2->lookAt( Ogre::Vector3( 0, 0, 0 ));
00100   camera2->setNearClipDistance( 5 );
00101 
00102   Ogre::Viewport* viewport2 = window2.getRenderWindow()->addViewport( camera2 );
00103   viewport2->setBackgroundColour( Ogre::ColourValue( 0, 1.0, 0 ));
00104 
00105   camera2->setAspectRatio( Ogre::Real( viewport2->getActualWidth() ) / Ogre::Real( viewport2->getActualHeight() ));
00106 
00107   // redraw every 33ms.
00108   QTimer timer2;
00109   QObject::connect( &timer2, SIGNAL(timeout()), &window2, SLOT(update()) );
00110   timer2.start( 33 );
00111 
00112   // main loop
00113   return app.exec();
00114 }


ogre_tools_qt
Author(s): Josh Faust
autogenerated on Fri Dec 6 2013 20:56:42