annotate src/Modules/Output/Graphics/Devices/GraphicsOutputDevice.h @ 244:d3968c3149b0

- Support (hopefully) both movie writing and HTK file output.
author tomwalters
date Tue, 26 Oct 2010 00:03:29 +0000
parents af02b6addf7a
children
rev   line source
tomwalters@237 1 // Copyright 2006-2010, Willem van Engen, Thomas Walters
tomwalters@116 2 //
tomwalters@116 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@116 4 // http://www.acousticscale.org/AIMC
tomwalters@116 5 //
tomwalters@116 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@116 7 // you may not use this file except in compliance with the License.
tomwalters@116 8 // You may obtain a copy of the License at
tomwalters@116 9 //
tomwalters@116 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@116 11 //
tomwalters@116 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@116 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@116 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@116 15 // See the License for the specific language governing permissions and
tomwalters@116 16 // limitations under the License.
tomwalters@116 17
tomwalters@116 18 #ifndef __GRAPHICS_OUTPUT_DEVICE_H__
tomwalters@116 19 #define __GRAPHICS_OUTPUT_DEVICE_H__
tomwalters@116 20
tomwalters@116 21 #include "Support/Parameters.h"
tomwalters@116 22
tom@229 23 namespace aimc {
tom@229 24
tomwalters@116 25 /*!
tomwalters@116 26 * \class GraphicsOutputDevice "Output/GraphicsOutputDevice.h"
tomwalters@116 27 * \brief General output device class
tomwalters@116 28 *
tomwalters@116 29 * This class provides basic drawing primitives in a device-independent manner.
tomwalters@116 30 * It is structured like the OpenGL interface. Following is an example drawing
tomwalters@116 31 * five horizontal lines, with the colour changing between red and blue over
tomwalters@116 32 * time.
tomwalters@116 33 * \code
tomwalters@116 34 * GraphicsOutputDevice oOutput = static_cast<GraphicsOutputDevice>(new GraphicsOutputDeviceSomething());
tomwalters@116 35 * unsigned int a=0;
tomwalters@116 36 * ...
tomwalters@116 37 * oOutput->Start();
tomwalters@116 38 * while ( bIsRunning ) {
tomwalters@228 39 * // Start a drawing operation
tomwalters@228 40 * oOutput->gGrab();
tomwalters@228 41 * // Draw five horizontal lines
tomwalters@228 42 * for (int y=0; y<5; y++) {
tomwalters@228 43 * // Start a new line
tomwalters@228 44 * oOutput->gBegin();
tomwalters@228 45 * // Give each line it's own colour
tomwalters@228 46 * oOutput->gColor3f( (a%255)/255, 0, 1-(a%255)/255 );
tomwalters@228 47 * // Draw the line
tomwalters@228 48 * oOutput->gVertex2f(0, y);
tomwalters@228 49 * oOutput->gVertex2f(1, y);
tomwalters@228 50 * // End the line
tomwalters@228 51 * oOutput->gEnd();
tomwalters@228 52 * }
tomwalters@228 53 * oOutput->gRelease();
tomwalters@228 54 * Sleep(1);
tomwalters@228 55 * a++;
tomwalters@116 56 * }
tomwalters@116 57 * oOutput->Stop();
tomwalters@116 58 * \endcode
tomwalters@116 59 *
tomwalters@116 60 * This class includes some basic overloading definitions to ease the
tomwalters@116 61 * children's implementation. Note that the basic operations that need
tomwalters@116 62 * implementation are glVertex3f(x,y,z) and glColor(r,g,b).
tomwalters@116 63 */
tomwalters@116 64 class GraphicsOutputDevice {
tomwalters@116 65 public:
tom@229 66 GraphicsOutputDevice(Parameters *pParam);
tomwalters@228 67 virtual ~GraphicsOutputDevice() { };
tomwalters@116 68
tomwalters@228 69 /*! \brief Initialize the module, sets up everything to Start().
tomwalters@228 70 * \return true on success, false on error
tomwalters@228 71 *
tomwalters@228 72 * Initialize() needs to be called before any other function.
tomwalters@228 73 *
tomwalters@228 74 * This method is called in it's form as displayed here by the GraphicsView,
tomwalters@228 75 * but you may want to setup your own Initialize(...) function with
tomwalters@228 76 * different arguments and call it yourself.
tomwalters@228 77 *
tomwalters@228 78 * Thus make sure you do all memory allocations here. They can be cleaned
tomwalters@228 79 * up by the destructor. Because Initialize() may fail, it's not put in
tomwalters@228 80 * the constructor, so it can return a value.
tomwalters@228 81 *
tomwalters@228 82 * \sa Module::Initialize()
tomwalters@228 83 */
tomwalters@237 84
tomwalters@228 85 /*! \overload
tomwalters@228 86 * This function reloads the parameters; make sure to have at least the
tomwalters@228 87 * function with maximum parameters called once.
tomwalters@228 88 */
tomwalters@237 89 virtual bool Initialize(Parameters *global_parameters) {
tomwalters@237 90 global_parameters_ = global_parameters;
tomwalters@237 91 return true;
tomwalters@237 92 };
tomwalters@126 93
tomwalters@228 94 /*! \brief Create a new drawing
tomwalters@228 95 * Run this before any other drawing command.
tomwalters@228 96 * \sa glRelease()
tomwalters@228 97 */
tomwalters@228 98 virtual void gGrab() = 0;
tomwalters@116 99
tomwalters@228 100 //! \brief Start a new vertex group for drawing a line strip
tomwalters@116 101 virtual void gBeginLineStrip() = 0;
tomwalters@116 102 //! \brief Start a new vertex group for drawing a quad strip
tomwalters@116 103 virtual void gBeginQuadStrip() = 0;
tomwalters@116 104
tomwalters@228 105 /*! \brief Specify a vertex to draw
tomwalters@228 106 * \param[in] x X-coordinate of the vertex
tomwalters@228 107 * \param[in] y Y-coordinate of the vertex
tomwalters@228 108 * \param[in] z Z-coordinate of the vertex
tomwalters@228 109 * \param[in] r Red component of colour
tomwalters@228 110 * \param[in] g Green component of colour
tomwalters@228 111 * \param[in] b Blue component of colour
tomwalters@228 112 *
tomwalters@228 113 * Currently, only lines are implemented.
tomwalters@228 114 */
tomwalters@116 115 virtual void gVertex3f(float x, float y, float z, float r, float g, float b);
tomwalters@116 116
tomwalters@228 117 /*! \overload
tomwalters@228 118 * This will add a vertex with the last specified colour.
tomwalters@228 119 */
tomwalters@116 120
tomwalters@228 121 virtual void gVertex3f(float x, float y, float z) = 0;
tomwalters@228 122 /*! \overload
tomwalters@228 123 * This will add a vertex in the 2d-plane with z=0.
tomwalters@228 124 */
tomwalters@116 125
tomwalters@228 126 virtual void gVertex2f(float x, float y, float r, float g, float b);
tomwalters@116 127
tomwalters@228 128 /*! \overload
tomwalters@228 129 * This will add a vertex in the 2d-plane with z=0 with the last
tomwalters@116 130 * specified colour.
tomwalters@228 131 */
tomwalters@228 132 virtual void gVertex2f(float x, float y);
tomwalters@116 133
tomwalters@228 134 /*! \brief Sets the current colour
tomwalters@228 135 * \param[in] r Red component
tomwalters@228 136 * \param[in] g Green component
tomwalters@228 137 * \param[in] b Blue component
tomwalters@228 138 */
tomwalters@228 139 virtual void gColor3f(float r, float g, float b) = 0;
tomwalters@116 140
tomwalters@228 141 //! \brief End a vertex group
tomwalters@116 142 virtual void gEnd() = 0;
tomwalters@116 143
tomwalters@228 144 /*! \brief Render a text string
tomwalters@228 145 * \param[in] x X-coordinate of the text's alignment point
tomwalters@228 146 * \param[in] y Y-coordinate of the text's alignment point
tomwalters@228 147 * \param[in] z Z-coordinate of the text's alignment point
tomwalters@228 148 * \param[in] sStr Text to render
tomwalters@228 149 * \param[in] bRotated \c true for vertically rotated text
tomwalters@228 150 *
tomwalters@228 151 * Current alignment is horizontal:left and vertical:bottom
tomwalters@228 152 * \todo Allow multiple alignment points
tomwalters@228 153 */
tomwalters@228 154 virtual void gText3f(float x,
tomwalters@116 155 float y,
tomwalters@116 156 float z,
tomwalters@116 157 const char *sStr,
tomwalters@116 158 bool bRotated = false) = 0;
tomwalters@116 159
tomwalters@228 160 /*! \overload
tomwalters@228 161 * This will render a text string in the 2d-plane with z=0.
tomwalters@228 162 */
tomwalters@228 163 virtual void gText2f(float x,
tomwalters@116 164 float y,
tomwalters@116 165 const char *sStr,
tomwalters@116 166 bool bRight = false);
tomwalters@116 167
tomwalters@228 168 /*! \brief Finish drawing
tomwalters@228 169 * Call this when a drawing is finished. It also makes sure that the
tomwalters@228 170 * rendering is actually done.
tomwalters@228 171 * \sa glGrab()
tomwalters@228 172 */
tomwalters@228 173 virtual void gRelease() = 0;
tomwalters@116 174
tomwalters@228 175 /*! \brief Called when animation starts
tomwalters@228 176 *
tomwalters@228 177 * You may wonder what Start() and Stop() do here. Some implementations
tomwalters@228 178 * may want to behave differently with respect to updating, if an
tomwalters@228 179 * animation is running or not (e.g. updating).
tomwalters@228 180 */
tomwalters@228 181 virtual void Start() { m_bRunning = true; }
tomwalters@116 182
tomwalters@228 183 //! \brief Called when animation stops
tomwalters@228 184 virtual void Stop() { m_bRunning = false; }
tomwalters@244 185
tomwalters@244 186 virtual void Reset(Parameters* global_parameters) = 0;
tomwalters@244 187
tomwalters@116 188
tomwalters@116 189 protected:
tomwalters@228 190 //! \brief True when animation is running
tomwalters@228 191 bool m_bRunning;
tomwalters@228 192 //! \brief Parameter store
tomwalters@237 193 Parameters *parameters_;
tomwalters@237 194 Parameters *global_parameters_;
tomwalters@116 195
tomwalters@228 196 //! \brief Pixel Formats
tomwalters@228 197 enum PixelFormat {AIM_PIX_FMT_RGB24_32, AIM_PIX_FMT_RGB24_24};
tomwalters@116 198 };
tom@229 199 } // namespace aimc
tomwalters@116 200 #endif /* __GRAPHICS_OUTPUT_DEVICE__ */