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     void InitTextures()                      { TexturePainter::Get()->Initialise(); }
00133     unsigned int LoadTexture(const string &Filename, bool ignorecache=false) { return TexturePainter::Get()->LoadTexture(Filename,ignorecache); }
00134     void ShowAxis(bool s)                    { m_ShowAxis=s; }
00135     void ShowCursor(bool s);
00136     void SetBGColour(const dColour &s)       { m_BGColour=s; }
00137     void SetClearFrame(bool s)               { m_ClearFrame=s; }
00138     void SetClearZBuffer(bool s)             { m_ClearZBuffer=s; }
00139     void SetClearAccum(bool s)               { m_ClearAccum=s; }
00140     void SetBackFaceCull(bool s)             { m_BackFaceCull=s; m_Initialised=false; }
00142     void SetFaceOrderClockwise(bool s)       {  m_FaceOrderClockwise=s; m_Initialised=false; }
00143     void SetDesiredFPS(float s)              { m_Deadline=1/s; }
00144     void SetFPSDisplay(bool s)               { m_FPSDisplay=s; }
00145     void SetFog(const dColour &c, float d, float s, float e)    
00146         { m_FogColour=c; m_FogDensity=d; m_FogStart=s; m_FogEnd=e; m_Initialised=false; }
00147     void ShadowLight(unsigned int s)         { m_ShadowLight=s; }
00148     void DebugShadows(bool s)                { m_World.GetShadowVolumeGen()->SetDebug(s); }
00149     void ShadowLength(float s)               { m_World.GetShadowVolumeGen()->SetLength(s); }
00150     double GetTime()                         { return m_Time; }
00151     double GetDelta()                        { return m_Delta; }
00152     bool SetStereoMode(stereo_mode_t mode);
00153     stereo_mode_t GetStereoMode(){ return m_StereoMode;}
00155     
00159     void SetColourMask(bool inred, bool ingreen, bool inblue, bool inalpha);
00160     void Accum(int mode, float factor);
00161     void DrawBuffer(GLenum mode);
00162     void ReadBuffer(GLenum mode);
00164     
00165     
00166 private:
00167     void PreRender(bool PickMode=false);
00168     void PostRender();
00169     void RenderLights(bool camera);
00170     void RenderStencilShadows();
00171     
00172     bool  m_Initialised;
00173     bool  m_InitLights;
00174     int   m_Width,m_Height;
00175     bool  m_MotionBlur;
00176     float m_Fade;
00177     bool  m_ShowAxis;
00178     Primitive *m_Grabbed;
00179     dColour m_BGColour;
00180     bool m_ClearFrame;
00181     bool m_ClearZBuffer;
00182     bool m_ClearAccum;
00183     bool m_BackFaceCull;
00184     bool m_FaceOrderClockwise;
00185     dColour m_FogColour; 
00186     float m_FogDensity; 
00187     float m_FogStart; 
00188     float m_FogEnd;
00189     unsigned int m_ShadowLight;
00190     
00191     deque<State> m_StateStack;
00192     SceneGraph m_World;
00193     vector<Light*> m_LightVec;
00194     Camera m_Camera;
00195     ImmediateMode m_ImmediateMode;
00196     
00197     // info for picking mode
00198     struct SelectInfo
00199     {
00200         int x,y;
00201         int size;
00202     };
00203     
00204     SelectInfo m_SelectInfo;
00205     stereo_mode_t m_StereoMode;
00206     bool m_MaskRed,m_MaskGreen,m_MaskBlue,m_MaskAlpha;
00207     
00208     timeval m_LastTime;
00209     float m_Deadline;
00210     bool m_FPSDisplay;
00211     double m_Time;
00212     double m_Delta;
00213 };
00214     
00215 };
00216 
00217 #endif

Generated on Tue Sep 4 23:22:18 2007 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1