source: OGRE/trunk/ogrenew/Samples/GTKDemo/src/GTKDemo.cpp @ 692

Revision 692, 4.9 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

RevLine 
[692]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL like the rest of the engine.
12-----------------------------------------------------------------------------
13*/
14
15#include "ExampleGTKApplication.h"
16//#include "ExampleFrameListener.h"
17
18//#include "GTKWindow.h"
19#include <gtkmm/main.h>
20#include <gtkmm/box.h>
21#include <gtkmm/scale.h>
22#include <gtkmm/window.h>
23#include <gtkmm/frame.h>
24#include <gtkglmm.h>
25
26using namespace Ogre;
27
28class GTKDemoFrameListener : public FrameListener
29{
30public:
31    GTKDemoFrameListener() {
32    }
33
34    bool frameStarted(const FrameEvent& evt)
35    {
36        return true;
37    }
38
39    bool frameEnded(const FrameEvent& evt)
40    {
41        return true;
42    }
43};
44
45class GTKDemoApplication : public ExampleApplication, public SigC::Object
46{
47public:
48    void go(void)
49    {
50        if (!setup())
51            return;
52
53        //gtk_win->show_all();
54        //gtk_win->update();
55        //std::cout << "Go!" << std::endl;
56        mWindow->update();
57        // Redraw viewport after scene update
58        //owidget->queue_draw();
59
60        Gtk::Main::run();
61    }
62
63protected:
64    bool on_delete_event(GdkEventAny* event)
65    {
66        Gtk::Main::quit();
67        return false;
68    }
69
70    void on_value_changed(void)
71    {
72        Real s = hscale->get_value();
73        headNode->setScale(s, s, s);
74        //mWindow->update();
75        owidget->queue_draw();
76    }
77
78        /**
79        * At the end of this routine, the window containing the OGRE widget must be
80        * created and visible
81        */
82    void setupGTKWindow(void)
83    {
84        gtk_win = new Gtk::Window();
85        gtk_win->set_title("An Ogre Head in a box");
86        gtk_win->signal_delete_event().connect(SigC::slot(*this,
87            &GTKDemoApplication::on_delete_event));
88
89
90        // Setup our window
91        vbox = new Gtk::VBox;
92        gtk_win->add(*vbox);
93
94        int width = 640;
95        int height = 480;
96
97        // Create a bin in which we will attach the Ogre widget
98        Gtk::Bin *bin = Gtk::manage(new Gtk::Frame());
99        bin->show();
100        vbox->pack_end(*bin, true, true);
101
102        // Create a horizontal scaler to show normal GTK
103        // widgets working together with Ogre
104        hscale = Gtk::manage(new Gtk::HScale(1.0, 5.0, 0.1));
105        hscale->signal_value_changed().connect(SigC::slot(*this,
106            &GTKDemoApplication::on_value_changed));
107
108        vbox->pack_end(*hscale, false, true);
109
110        // Now show allAn Ogre in a box
111        gtk_win->show_all();
112
113        // Add our OGRE widget
114        std::cout << "Creating OGRE widget" << std::endl;
115
116        // Create OGRE widget and attach it
117        // Note that the parent widget *must* be visible already at this point,
118        // or the widget won't get realized in time for the GLinit that follows
119        // this call. This is usually the case for Glade generated windows, anyway.
120        mWindow = mRoot->createRenderWindow(
121                        "An Ogre in a box",
122                        width, height, 32,
123                        false, // non fullscreen
124                        0, 0, // left, top
125                        true, // depth buffer
126                        reinterpret_cast<RenderWindow*>(bin)
127                );
128
129        mWindow->getCustomAttribute("GTKGLMMWIDGET", &owidget);
130        std::cout << "Created OGRE widget" << std::endl;
131        //gtk_win->show_all();
132    }
133
134    void createScene(void)
135    {
136        mSceneMgr->setAmbientLight(ColourValue(0.6, 0.6, 0.6));
137
138        // Setup the actual scene
139        Light* l = mSceneMgr->createLight("MainLight");
140        l->setPosition(0, 100, 500);
141
142        Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
143        headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
144        headNode->attachObject(head);
145
146        mCamera->setAutoTracking(true, headNode);
147    }
148
149    void createFrameListener(void)
150    {
151        // This is where we instantiate our own frame listener
152        mFrameListener = new GTKDemoFrameListener();
153        mRoot->addFrameListener(mFrameListener);
154    }
155
156private:
157        Gtk::Window* gtk_win;
158        Gtk::VBox* vbox;
159        Gtk::HScale* hscale;
160        SceneNode* headNode;
161        Gtk::GL::DrawingArea *owidget;
162//      RenderWindow* mWindow;
163};
164
165#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
166#define WIN32_LEAN_AND_MEAN
167#include "windows.h"
168INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
169#else
170int main(int argc, char **argv)
171#endif
172{
173    // Create application object
174    GTKDemoApplication app;
175 
176    try {
177        app.go();
178    } catch( Ogre::Exception& e ) {
179#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
180        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
181#else
182        std::cerr << "An exception has occured: " << e.getFullDescription();
183#endif
184    }
185
186
187    return 0;
188}
Note: See TracBrowser for help on using the repository browser.