Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Renderer.h

Go to the documentation of this file.
00001 /*
00002     File:           Renderer.h
00003 
00004     Function:       Contains the definition for the renderer class. A 
00005                     particular graphics system must implement objects of this
00006                     type.
00007 
00008                     example use: 
00009                         r.Clear().Start(renPoly)
00010                             .Colour(cRed).Vertex(a).Vertex(b).Vertex(c)
00011                             .End().Show();
00012     
00013     Author(s):      Andrew Willmott
00014 
00015     Copyright:      (c) 1995-2000, Andrew Willmott
00016  */
00017 
00018 #ifndef __Renderer__
00019 #define __Renderer__
00020 
00021 #include "gcl/Geometry.h"
00022 #include "gcl/Colour.h"
00023 #include "gcl/Image.h"
00024 #include "gcl/Camera.h"
00025 #include "cl/Action.h"
00026 
00027 
00028 // --- The Renderer class -----------------------------------------------------
00029 
00030 
00031 class Renderer;
00032 
00033 typedef Action<Renderer>    RenderAction;
00034 typedef Renderer            *RendererPtr;
00035 
00036 enum RenderStyle            // Commands for point-series drawing
00037 {
00038     renNone, 
00039     renPoints,
00040     renLines,
00041     renLineStrip,
00042     renLineLoop,
00043     renPoly,
00044     renTriangles,
00045     renTriStrip,
00046     renMaxStyles
00047 };
00048 
00049 class Renderable
00050 {
00051 public:
00052     virtual Void        Draw(Renderer &r) = 0;
00053 };
00054 
00055 class Renderer              // Abstract class for something you can render into
00056 {
00057 public:
00058     Renderer();
00059     
00060     virtual Void        Show() = 0;
00061     virtual Void        MakeCurrent() = 0;
00062     virtual Void        Print(ostream &s) = 0;
00063     
00064     Renderer            &Draw(Renderable &thing);
00065     Renderer            &Draw(Renderable *thing);
00066     virtual Renderer    &Begin(RenderStyle style) = 0;
00067     virtual Renderer    &End() = 0;
00068 
00069     virtual Renderer    &SetPoint(const Point &p) = 0;
00070     virtual Renderer    &SetNormal(const Point &p) = 0;
00071     virtual Renderer    &SetCoord(const Coord &c) = 0;
00072     virtual Renderer    &SetTexCoord(const Coord &c);
00073     virtual Renderer    &SetColour(const Colour &c) = 0;
00074     virtual Renderer    &SetColour(const Colour4 &c);
00075 
00076     virtual Renderer    &SetTransform(const Transform &t) = 0;
00077     virtual Renderer    &SetCamera(const Camera &c) = 0;
00078     virtual Renderer    &SetTexture(const Image *image);
00079 
00080     Void                SetBgColour(const Colour &c) { bgColour = c; };
00081     Colour              GetBgColour() { return(bgColour); };
00082 
00083     virtual Renderer    &Clear() = 0;
00084     virtual Renderer    &Pop() = 0;
00085     virtual Renderer    &Push() = 0;
00086 
00087     virtual Renderer    &GetImage(Image &image) = 0;
00088     virtual Renderer    &PutImage(const Image &image, Int x = 0, Int y = 0) = 0;
00089 
00090     // short-cuts
00091 
00092     Renderer            &P(const Point &p) {return(SetPoint(p));};
00093     Renderer            &P(const Coord &c) {return(SetCoord(c));};
00094     Renderer            &N(const Vector &p) {return(SetNormal(p));};
00095     Renderer            &C(const Colour &c) {return(SetColour(c));};
00096     Renderer            &C(const Colour4 &c) {return(SetColour(c));};
00097     Renderer            &T(const Coord &c) {return(SetTexCoord(c));};
00098     Renderer            &Xform(const Transform &t) {return(SetTransform(t));};
00099     Renderer            &Cam(const Camera &c) {return(SetCamera(c));};
00100 
00101                 
00102 protected:
00103     inline Void         SetWindow();
00104 
00105     Colour              bgColour;
00106     static Renderer     *sCurrentRenderer;
00107 };
00108 
00109 ostream &operator << (ostream &s, Renderer &gsr);
00110 
00111 // --- Inlines ----------------------------------------------------------------
00112 
00113 
00114 inline Void Renderer::SetWindow()
00115 //  swap drawing contexts if necessary...
00116 {
00117     if (this != sCurrentRenderer)
00118     {
00119         sCurrentRenderer = this;
00120         MakeCurrent();
00121     }
00122 }
00123 
00124 #endif

Generated at Sat Aug 5 00:17:02 2000 for Graphics Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000