Renderer.h

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016  
00017 #ifndef N_RENDERER
00018 #define N_RENDERER
00019 
00020 #include <sys/time.h>
00021 #include "dada.h"
00022 #include "deque"
00023 #include "map"
00024 #include "vector"
00025 #include "string"
00026 #include "Camera.h"
00027 #include "SceneGraph.h"
00028 #include "ImmediateMode.h"
00029 #include "Light.h"
00030 #include "TexturePainter.h"
00031 
00032 // TODO: check this works for Apple's OpenGL
00033 #ifndef GL_POLYGON_OFFSET_EXT
00034 #define GL_POLYGON_OFFSET_EXT ((GLenum)0x8037) 
00035 #endif
00036 
00037 using namespace std;
00038 
00039 namespace Fluxus
00040 {
00041 
00042 class State;
00043 class Primitive;
00044 
00053 
00057 class Renderer
00058 {
00059 public:
00060     Renderer();
00061     ~Renderer();
00062     
00066     void Render();
00067     void Clear();
00069     
00073     State *GetState();
00074     void ApplyState();
00075     void PushState();
00076     void PopState();
00078     void Grab(int ID);
00079     void UnGrab();
00080     Primitive *Grabbed() { return m_Grabbed; }
00082     
00086     int          AddPrimitive(Primitive *Prim);
00087     Primitive   *GetPrimitive(int ID);
00089     void         RemovePrimitive(int ID);
00092     void         DetachPrimitive(int ID);
00093     dMatrix      GetGlobalTransform(int ID);
00094     dBoundingBox GetBoundingBox(int ID);
00097     void         RenderPrimitive(Primitive *Prim);
00099     int          Select(int x, int y, int size);
00101     
00105     int AddLight(Light *l);
00106     Light *GetLight(int id);
00107     void ClearLights();
00109 
00113     Camera *GetCamera() { return &m_Camera; }
00115 
00119     const SceneGraph &GetSceneGraph()        { return m_World; }
00121         
00122     enum stereo_mode_t {noStereo, crystalEyes, colourStereo};
00123     
00127     void DrawText(const string &Text);
00128     void Reinitialise()                      { m_Initialised=false; }
00129     void SetMotionBlur(bool s, float a=0.02) { m_MotionBlur=s; m_Fade=a; }
00130     void SetResolution(int x, int y)         { m_Width=x; m_Height=y; m_Initialised=false; }
00131     void GetResolution(int &x, int &y)       { x=m_Width; y=m_Height; }
00132     TexturePainter *GetTexturePainter()      { return TexturePainter::Get(); }
00133     void ShowAxis(bool s)                    { m_ShowAxis=s; }
00134     void ShowCursor(bool s);
00135     void SetBGColour(const dColour &s)       { m_BGColour=s; }
00136     void SetClearFrame(bool s)               { m_ClearFrame=s; }
00137     void SetClearZBuffer(bool s)             { m_ClearZBuffer=s; }
00138     void SetClearAccum(bool s)               { m_ClearAccum=s; }
00139     void SetBackFaceCull(bool s)             { m_BackFaceCull=s; m_Initialised=false; }
00141     void SetFaceOrderClockwise(bool s)       {  m_FaceOrderClockwise=s; m_Initialised=false; }
00142     void SetDesiredFPS(float s)              { m_Deadline=1/s; }
00143     void SetFPSDisplay(bool s)               { m_FPSDisplay=s; }
00144     void SetFog(const dColour &c, float d, float s, float e)    
00145         { m_FogColour=c; m_FogDensity=d; m_FogStart=s; m_FogEnd=e; m_Initialised=false; }
00146     void ShadowLight(unsigned int s)         { m_ShadowLight=s; }
00147     void DebugShadows(bool s)                { m_World.GetShadowVolumeGen()->SetDebug(s); }
00148     void ShadowLength(float s)               { m_World.GetShadowVolumeGen()->SetLength(s); }
00149     double GetTime()                         { return m_Time; }
00150     double GetDelta()                        { return m_Delta; }
00151     bool SetStereoMode(stereo_mode_t mode);
00152     stereo_mode_t GetStereoMode(){ return m_StereoMode;}
00154     
00158     void SetColourMask(bool inred, bool ingreen, bool inblue, bool inalpha);
00159     void Accum(int mode, float factor);
00160     void DrawBuffer(GLenum mode);
00161     void ReadBuffer(GLenum mode);
00163     
00164     
00165 private:
00166     void PreRender(bool PickMode=false);
00167     void PostRender();
00168     void RenderLights(bool camera);
00169     void RenderStencilShadows();
00170     
00171     bool  m_Initialised;
00172     bool  m_InitLights;
00173     int   m_Width,m_Height;
00174     bool  m_MotionBlur;
00175     float m_Fade;
00176     bool  m_ShowAxis;
00177     Primitive *m_Grabbed;
00178     dColour m_BGColour;
00179     bool m_ClearFrame;
00180     bool m_ClearZBuffer;
00181     bool m_ClearAccum;
00182     bool m_BackFaceCull;
00183     bool m_FaceOrderClockwise;
00184     dColour m_FogColour; 
00185     float m_FogDensity; 
00186     float m_FogStart; 
00187     float m_FogEnd;
00188     unsigned int m_ShadowLight;
00189     
00190     deque<State> m_StateStack;
00191     SceneGraph m_World;
00192     vector<Light*> m_LightVec;
00193     Camera m_Camera;
00194     ImmediateMode m_ImmediateMode;
00195         
00196     // info for picking mode
00197     struct SelectInfo
00198     {
00199         int x,y;
00200         int size;
00201     };
00202     
00203     SelectInfo m_SelectInfo;
00204     stereo_mode_t m_StereoMode;
00205     bool m_MaskRed,m_MaskGreen,m_MaskBlue,m_MaskAlpha;
00206     
00207     timeval m_LastTime;
00208     float m_Deadline;
00209     bool m_FPSDisplay;
00210     double m_Time;
00211     double m_Delta;
00212 };
00213     
00214 };
00215 
00216 #endif

Generated on Mon Feb 11 06:54:25 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1