annotate trunk/src/Modules/Output/Graphics/Devices/GraphicsOutputDevice.h @ 397:7a573750b186

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