glcanvas.h

Go to the documentation of this file.
00001 
00004 
00005 //
00006 // Copyright (c) 1999-2004 California Institute of Technology
00007 // Copyright (c) 2004-2007 University of Southern California
00008 // Rob Peters <rjpeters at usc dot edu>
00009 //
00010 // created: Mon Dec  6 20:27:48 1999
00011 // commit: $Id: glcanvas.h 10065 2007-04-12 05:54:56Z rjpeters $
00012 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/gfx/glcanvas.h $
00013 //
00014 // --------------------------------------------------------------------
00015 //
00016 // This file is part of GroovX.
00017 //   [http://ilab.usc.edu/rjpeters/groovx/]
00018 //
00019 // GroovX is free software; you can redistribute it and/or modify it
00020 // under the terms of the GNU General Public License as published by
00021 // the Free Software Foundation; either version 2 of the License, or
00022 // (at your option) any later version.
00023 //
00024 // GroovX is distributed in the hope that it will be useful, but
00025 // WITHOUT ANY WARRANTY; without even the implied warranty of
00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027 // General Public License for more details.
00028 //
00029 // You should have received a copy of the GNU General Public License
00030 // along with GroovX; if not, write to the Free Software Foundation,
00031 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00032 //
00034 
00035 #ifndef GROOVX_GFX_GLCANVAS_H_UTC20050626084024_DEFINED
00036 #define GROOVX_GFX_GLCANVAS_H_UTC20050626084024_DEFINED
00037 
00038 #include "gfx/canvas.h"
00039 
00040 #include "nub/volatileobject.h"
00041 
00042 class GlxOpts;
00043 class GlWindowInterface;
00044 
00045 namespace rutz
00046 {
00047   template <class T> class shared_ptr;
00048 }
00049 
00051 class GLCanvas : public Gfx::Canvas, public virtual nub::volatile_object
00052 {
00053 protected:
00055   GLCanvas(rutz::shared_ptr<GlxOpts> opts,
00056            rutz::shared_ptr<GlWindowInterface> glx);
00057 
00058 public:
00060   static GLCanvas* make(rutz::shared_ptr<GlxOpts> opts,
00061                         rutz::shared_ptr<GlWindowInterface> glx);
00062 
00063   virtual ~GLCanvas() throw();
00064 
00065   void makeCurrent();
00066 
00067   static nub::soft_ref<GLCanvas> getCurrent();
00068 
00069   void drawBufferFront() throw();
00070   void drawBufferBack() throw();
00071 
00072   virtual geom::vec3<double> screenFromWorld3(const geom::vec3<double>& world_pos) const;
00073   virtual geom::vec3<double> worldFromScreen3(const geom::vec3<double>& screen_pos) const;
00074 
00075   virtual geom::rect<int> getScreenViewport() const;
00076 
00077 
00078   virtual bool isRgba() const;
00079   virtual bool isColorIndex() const;
00080   virtual bool isDoubleBuffered() const;
00081 
00082   virtual unsigned int bitsPerPixel() const;
00083 
00084   virtual void throwIfError(const char* where,
00085                             const rutz::file_pos& pos) const;
00086 
00087 
00088   virtual void pushAttribs(const char* comment="");
00089   virtual void popAttribs();
00090 
00091   virtual void drawOnFrontBuffer();
00092   virtual void drawOnBackBuffer();
00093 
00094   virtual void setColor(const Gfx::RgbaColor& rgba);
00095   virtual void setClearColor(const Gfx::RgbaColor& rgba);
00096 
00097   virtual void setColorIndex(unsigned int index);
00098   virtual void setClearColorIndex(unsigned int index);
00099 
00102   virtual void swapForeBack();
00103 
00104   virtual void setPolygonFill(bool on);
00105   virtual void setPointSize(double size);
00106   virtual void setLineWidth(double width);
00107   virtual void setLineStipple(unsigned short bit_pattern);
00108 
00109   virtual void enableAntialiasing();
00110 
00111 
00112 
00113   virtual void viewport(int x, int y, int w, int h);
00114 
00115   virtual void orthographic(const geom::rect<double>& bounds,
00116                             double zNear, double zFar);
00117 
00118   virtual void perspective(double fovy, double aspect,
00119                            double zNear, double zFar);
00120 
00121 
00122   virtual void pushMatrix(const char* comment="");
00123   virtual void popMatrix();
00124 
00125   virtual void translate(const geom::vec3<double>& v);
00126   virtual void scale(const geom::vec3<double>& v);
00127   virtual void rotate(const geom::vec3<double>& v, double degrees);
00128 
00129   virtual void transform(const geom::txform& tx);
00130   virtual void loadMatrix(const geom::txform& tx);
00131 
00133 
00136   void rasterPos(const geom::vec3<double>& world_pos);
00137 
00138   virtual void drawPixels(const media::bmap_data& data,
00139                           const geom::vec3<double>& world_pos,
00140                           const geom::vec2<double>& zoom);
00141 
00142   virtual void drawBitmap(const media::bmap_data& data,
00143                           const geom::vec3<double>& world_pos);
00144 
00145   virtual void grabPixels(const geom::rect<int>& bounds,
00146                           media::bmap_data& data_out);
00147 
00148   virtual void clearColorBuffer();
00149   virtual void clearColorBuffer(const geom::rect<int>& screen_rect);
00150 
00151   virtual void drawRect(const geom::rect<double>& rect);
00152 
00153   virtual void drawCircle(double inner_radius, double outer_radius, bool fill,
00154                           unsigned int slices, unsigned int loops);
00155 
00156   virtual void drawCylinder(double base_radius, double top_radius,
00157                             double height, int slices, int stacks,
00158                             bool fill);
00159 
00160   virtual void drawSphere(double radius, int slices, int stacks,
00161                           bool fill);
00162 
00163   virtual void drawBezier4(const geom::vec3<double>& p1,
00164                            const geom::vec3<double>& p2,
00165                            const geom::vec3<double>& p3,
00166                            const geom::vec3<double>& p4,
00167                            unsigned int subdivisions);
00168 
00169   virtual void drawBezierFill4(const geom::vec3<double>& center,
00170                                const geom::vec3<double>& p1,
00171                                const geom::vec3<double>& p2,
00172                                const geom::vec3<double>& p3,
00173                                const geom::vec3<double>& p4,
00174                                unsigned int subdivisions);
00175 
00176   virtual void beginPoints(const char* comment="");
00177   virtual void beginLines(const char* comment="");
00178   virtual void beginLineStrip(const char* comment="");
00179   virtual void beginLineLoop(const char* comment="");
00180   virtual void beginTriangles(const char* comment="");
00181   virtual void beginTriangleStrip(const char* comment="");
00182   virtual void beginTriangleFan(const char* comment="");
00183   virtual void beginQuads(const char* comment="");
00184   virtual void beginQuadStrip(const char* comment="");
00185   virtual void beginPolygon(const char* comment="");
00186 
00187   virtual void vertex2(const geom::vec2<double>& v);
00188   virtual void vertex3(const geom::vec3<double>& v);
00189 
00190   virtual void end();
00191 
00192   virtual void drawRasterText(const rutz::fstring& text,
00193                               const GxRasterFont& font);
00194   virtual void drawVectorText(const rutz::fstring& text,
00195                               const GxVectorFont& font);
00196 
00197   virtual void flushOutput();
00198 
00199   virtual void finishDrawing();
00200 
00201   // OpenGL-specific stuff:
00202 
00204 
00205   static int genLists(int num);
00207   static void deleteLists(int start, int num);
00209 
00210   void newList(int i, bool do_execute);
00212   void endList();
00214   bool isList(int i);
00216   void callList(int i);
00217 
00219   void light(int lightnum,
00220              const Gfx::RgbaColor* specular,
00221              const Gfx::RgbaColor* diffuse,
00222              const Gfx::RgbaColor* ambient,
00223              const geom::vec3<double>* position,
00224              const geom::vec3<double>* spotDirection,
00225              double attenuation,
00226              double spotExponent,
00227              double spotCutoff);
00228 
00230   void material(const Gfx::RgbaColor* specular,
00231                 const Gfx::RgbaColor* diffuse,
00232                 const Gfx::RgbaColor* ambient,
00233                 const double* shininess);
00234 
00235 private:
00236   GLCanvas(const GLCanvas&);
00237   GLCanvas& operator=(const GLCanvas&);
00238 
00239   class Impl;
00240   Impl* rep;
00241 };
00242 
00243 static const char __attribute__((used)) vcid_groovx_gfx_glcanvas_h_utc20050626084024[] = "$Id: glcanvas.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00244 #endif // !GROOVX_GFX_GLCANVAS_H_UTC20050626084024_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:38 2008 by Doxygen version 1.5.5.