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