00001 /* 00002 * glut-demo.h 00003 * 00004 * Copyright (C) 2010 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 */ 00031 00032 #ifndef WAVE_GLUT_GLUT_DEMO_H__ 00033 #define WAVE_GLUT_GLUT_DEMO_H__ 00034 00035 // includes -------------------------------------------------------------------- 00036 #include "wave-glut/renderable.h" 00037 00038 00039 namespace glut { 00040 00041 00042 //////////////////////////////////////////////////////////////////////////////// 00043 /// 00044 /// \ingroup wave_glut 00045 /// \defgroup glut_demo Demo application base class 00046 /// 00047 /// Simple base class to support demos and test programs. 00048 /// 00049 //////////////////////////////////////////////////////////////////////////////// 00050 /*@{*/ 00051 00052 00053 /// represents a single (small) status line to overlay in the demo 00054 class DisplayLine { 00055 public: 00056 // public enums -------------------------------------------------------- 00057 enum ePosition { 00058 eTopLeft = 1, 00059 eTopRight = 2, 00060 eBottomLeft = 3, 00061 eBottomRight = 4, 00062 00063 // keep this last! 00064 eInvalid = 0 00065 }; 00066 00067 // virtual destructor -------------------------------------------------- 00068 virtual ~DisplayLine(void) throw(); 00069 00070 // glut::DisplayLine class interface methods --------------------------- 00071 virtual ePosition getPosition(void) = 0; 00072 virtual const char * getText(void) = 0; 00073 }; 00074 00075 typedef std::vector<smart_ptr<DisplayLine> > vec_display_lines_t; 00076 00077 00078 00079 /// You'll need to provide a class that inherits from DemoHost. Override any 00080 /// glut::DemoHost interface method to receive the specified callback. 00081 /// This base class will provide default implementation for all callbacks. 00082 class DemoHost { 00083 public: 00084 // public enum --------------------------------------------------------- 00085 enum eConstants { 00086 eDefaultWidth = 800, 00087 eDefaultHeight = 600, 00088 00089 // keep this last 00090 eInvalid = -1 00091 }; 00092 00093 // virtual destructor -------------------------------------------------- 00094 virtual ~DemoHost(void) throw(); 00095 00096 // glut::DemoHost class interface methods ------------------------------ 00097 virtual int getWidth(void) { return eDefaultWidth; } 00098 virtual int getHeight(void) { return eDefaultHeight; } 00099 virtual float getDelta(void) { return 0.25; } 00100 00101 /// host can perform any pre-rendering work here 00102 virtual void onInit(void) { } 00103 00104 /// want to display the tricolor xyz axes? 00105 virtual bool displayAxes(void) { return true; } 00106 00107 /// want to draw queued (transparent) polygons? 00108 virtual bool displayQueuedPolys(void) { return true; } 00109 00110 /// host can provide additional display lines 00111 virtual void getDisplayLines(OUT vec_display_lines_t& lines) 00112 { lines.clear(); } 00113 00114 /// host is notified just before shutdown 00115 virtual void onShutdown(void) { } 00116 00117 /// host is notified that mouse has moved 00118 virtual void onCursor(IN int x, IN int y) { } 00119 00120 /// host is notified that mouse button has been pressed/released 00121 virtual void onButton(IN int button, IN int state, IN int x, IN int y) { } 00122 00123 /// host is notified that a key has been pressed 00124 virtual void onKey(IN int key, IN int mods) { } 00125 00126 /// host is notified per frame, and is told the time delta in seconds 00127 virtual void onIdle(IN float dt) { } 00128 00129 /// host is notified that GL is set up for 3D drawing (called per frame) 00130 virtual void display3D(IN const render_context_t& rc, 00131 IN RenderQueue * rq) { } 00132 00133 /// host is notified that GL is set up for 2D drawing (called per frame) 00134 virtual void display2D(IN int width, IN int height) { } 00135 }; 00136 00137 00138 00139 /// use this method to kick off a quick demo (provide an instance of your own 00140 /// host, inherited from glut::DemoHost ). 00141 /// this routine does not return. It is fine to leak 00142 /// your DemoHost object, although better to wrap it with a smart_ptr<T>. 00143 void startDemo(IN int argc, 00144 IN const char * argv[], 00145 IN const char * title, 00146 IN DemoHost * host); 00147 00148 00149 00150 }; // glut namespace 00151 00152 #endif // WAVE_GLUT_GLUT_DEMO_H__ 00153