tomwalters@411: // Copyright 2006-2010, Willem van Engen, Thomas Walters tomwalters@397: // tomwalters@397: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@397: // http://www.acousticscale.org/AIMC tomwalters@397: // tomwalters@397: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@397: // you may not use this file except in compliance with the License. tomwalters@397: // You may obtain a copy of the License at tomwalters@397: // tomwalters@397: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@397: // tomwalters@397: // Unless required by applicable law or agreed to in writing, software tomwalters@397: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@397: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@397: // See the License for the specific language governing permissions and tomwalters@397: // limitations under the License. tomwalters@397: tomwalters@397: #ifndef __GRAPHICS_OUTPUT_DEVICE_H__ tomwalters@397: #define __GRAPHICS_OUTPUT_DEVICE_H__ tomwalters@397: tomwalters@397: #include "Support/Parameters.h" tomwalters@397: tom@399: namespace aimc { tom@399: tomwalters@397: /*! tomwalters@397: * \class GraphicsOutputDevice "Output/GraphicsOutputDevice.h" tomwalters@397: * \brief General output device class tomwalters@397: * tomwalters@397: * This class provides basic drawing primitives in a device-independent manner. tomwalters@397: * It is structured like the OpenGL interface. Following is an example drawing tomwalters@397: * five horizontal lines, with the colour changing between red and blue over tomwalters@397: * time. tomwalters@397: * \code tomwalters@397: * GraphicsOutputDevice oOutput = static_cast(new GraphicsOutputDeviceSomething()); tomwalters@397: * unsigned int a=0; tomwalters@397: * ... tomwalters@397: * oOutput->Start(); tomwalters@397: * while ( bIsRunning ) { tomwalters@398: * // Start a drawing operation tomwalters@398: * oOutput->gGrab(); tomwalters@398: * // Draw five horizontal lines tomwalters@398: * for (int y=0; y<5; y++) { tomwalters@398: * // Start a new line tomwalters@398: * oOutput->gBegin(); tomwalters@398: * // Give each line it's own colour tomwalters@398: * oOutput->gColor3f( (a%255)/255, 0, 1-(a%255)/255 ); tomwalters@398: * // Draw the line tomwalters@398: * oOutput->gVertex2f(0, y); tomwalters@398: * oOutput->gVertex2f(1, y); tomwalters@398: * // End the line tomwalters@398: * oOutput->gEnd(); tomwalters@398: * } tomwalters@398: * oOutput->gRelease(); tomwalters@398: * Sleep(1); tomwalters@398: * a++; tomwalters@397: * } tomwalters@397: * oOutput->Stop(); tomwalters@397: * \endcode tomwalters@397: * tomwalters@397: * This class includes some basic overloading definitions to ease the tomwalters@397: * children's implementation. Note that the basic operations that need tomwalters@397: * implementation are glVertex3f(x,y,z) and glColor(r,g,b). tomwalters@397: */ tomwalters@397: class GraphicsOutputDevice { tomwalters@397: public: tom@399: GraphicsOutputDevice(Parameters *pParam); tomwalters@398: virtual ~GraphicsOutputDevice() { }; tomwalters@397: tomwalters@398: /*! \brief Initialize the module, sets up everything to Start(). tomwalters@398: * \return true on success, false on error tomwalters@398: * tomwalters@398: * Initialize() needs to be called before any other function. tomwalters@398: * tomwalters@398: * This method is called in it's form as displayed here by the GraphicsView, tomwalters@398: * but you may want to setup your own Initialize(...) function with tomwalters@398: * different arguments and call it yourself. tomwalters@398: * tomwalters@398: * Thus make sure you do all memory allocations here. They can be cleaned tomwalters@398: * up by the destructor. Because Initialize() may fail, it's not put in tomwalters@398: * the constructor, so it can return a value. tomwalters@398: * tomwalters@398: * \sa Module::Initialize() tomwalters@398: */ tomwalters@411: tomwalters@398: /*! \overload tomwalters@398: * This function reloads the parameters; make sure to have at least the tomwalters@398: * function with maximum parameters called once. tomwalters@398: */ tomwalters@411: virtual bool Initialize(Parameters *global_parameters) { tomwalters@411: global_parameters_ = global_parameters; tomwalters@411: return true; tomwalters@411: }; tomwalters@397: tomwalters@398: /*! \brief Create a new drawing tomwalters@398: * Run this before any other drawing command. tomwalters@398: * \sa glRelease() tomwalters@398: */ tomwalters@398: virtual void gGrab() = 0; tomwalters@397: tomwalters@398: //! \brief Start a new vertex group for drawing a line strip tomwalters@397: virtual void gBeginLineStrip() = 0; tomwalters@397: //! \brief Start a new vertex group for drawing a quad strip tomwalters@397: virtual void gBeginQuadStrip() = 0; tomwalters@397: tomwalters@398: /*! \brief Specify a vertex to draw tomwalters@398: * \param[in] x X-coordinate of the vertex tomwalters@398: * \param[in] y Y-coordinate of the vertex tomwalters@398: * \param[in] z Z-coordinate of the vertex tomwalters@398: * \param[in] r Red component of colour tomwalters@398: * \param[in] g Green component of colour tomwalters@398: * \param[in] b Blue component of colour tomwalters@398: * tomwalters@398: * Currently, only lines are implemented. tomwalters@398: */ tomwalters@397: virtual void gVertex3f(float x, float y, float z, float r, float g, float b); tomwalters@397: tomwalters@398: /*! \overload tomwalters@398: * This will add a vertex with the last specified colour. tomwalters@398: */ tomwalters@397: tomwalters@398: virtual void gVertex3f(float x, float y, float z) = 0; tomwalters@398: /*! \overload tomwalters@398: * This will add a vertex in the 2d-plane with z=0. tomwalters@398: */ tomwalters@397: tomwalters@398: virtual void gVertex2f(float x, float y, float r, float g, float b); tomwalters@397: tomwalters@398: /*! \overload tomwalters@398: * This will add a vertex in the 2d-plane with z=0 with the last tomwalters@397: * specified colour. tomwalters@398: */ tomwalters@398: virtual void gVertex2f(float x, float y); tomwalters@397: tomwalters@398: /*! \brief Sets the current colour tomwalters@398: * \param[in] r Red component tomwalters@398: * \param[in] g Green component tomwalters@398: * \param[in] b Blue component tomwalters@398: */ tomwalters@398: virtual void gColor3f(float r, float g, float b) = 0; tomwalters@397: tomwalters@398: //! \brief End a vertex group tomwalters@397: virtual void gEnd() = 0; tomwalters@397: tomwalters@398: /*! \brief Render a text string tomwalters@398: * \param[in] x X-coordinate of the text's alignment point tomwalters@398: * \param[in] y Y-coordinate of the text's alignment point tomwalters@398: * \param[in] z Z-coordinate of the text's alignment point tomwalters@398: * \param[in] sStr Text to render tomwalters@398: * \param[in] bRotated \c true for vertically rotated text tomwalters@398: * tomwalters@398: * Current alignment is horizontal:left and vertical:bottom tomwalters@398: * \todo Allow multiple alignment points tomwalters@398: */ tomwalters@398: virtual void gText3f(float x, tomwalters@397: float y, tomwalters@397: float z, tomwalters@397: const char *sStr, tomwalters@397: bool bRotated = false) = 0; tomwalters@397: tomwalters@398: /*! \overload tomwalters@398: * This will render a text string in the 2d-plane with z=0. tomwalters@398: */ tomwalters@398: virtual void gText2f(float x, tomwalters@397: float y, tomwalters@397: const char *sStr, tomwalters@397: bool bRight = false); tomwalters@397: tomwalters@398: /*! \brief Finish drawing tomwalters@398: * Call this when a drawing is finished. It also makes sure that the tomwalters@398: * rendering is actually done. tomwalters@398: * \sa glGrab() tomwalters@398: */ tomwalters@398: virtual void gRelease() = 0; tomwalters@397: tomwalters@398: /*! \brief Called when animation starts tomwalters@398: * tomwalters@398: * You may wonder what Start() and Stop() do here. Some implementations tomwalters@398: * may want to behave differently with respect to updating, if an tomwalters@398: * animation is running or not (e.g. updating). tomwalters@398: */ tomwalters@398: virtual void Start() { m_bRunning = true; } tomwalters@397: tomwalters@398: //! \brief Called when animation stops tomwalters@398: virtual void Stop() { m_bRunning = false; } tomwalters@418: tomwalters@418: virtual void Reset(Parameters* global_parameters) = 0; tomwalters@418: tomwalters@397: tomwalters@397: protected: tomwalters@398: //! \brief True when animation is running tomwalters@398: bool m_bRunning; tomwalters@398: //! \brief Parameter store tomwalters@411: Parameters *parameters_; tomwalters@411: Parameters *global_parameters_; tomwalters@397: tomwalters@398: //! \brief Pixel Formats tomwalters@398: enum PixelFormat {AIM_PIX_FMT_RGB24_32, AIM_PIX_FMT_RGB24_24}; tomwalters@397: }; tom@399: } // namespace aimc tomwalters@397: #endif /* __GRAPHICS_OUTPUT_DEVICE__ */