00001 //------------------------------------------------------------------------ 00002 // 00003 // Joe Kniss 00004 // 6-20-03 00005 // ________ ____ ___ 00006 // | \ / | / / 00007 // +---+ \/ |/ / 00008 // +--+| |\ /| < 00009 // | || | \ / | |\ \ 00010 // | | \/ | | \ \ 00011 // \_____| |__| \__\ 00012 // Copyright 2003 00013 // Joe Michael Kniss 00014 // <<< jmk@cs.utah.edu >>> 00015 // "All Your Base are Belong to Us" 00016 //------------------------------------------------------------------------- 00017 00018 /// GLItems.h 00019 00020 #ifndef __GL_ITEMS_DOT_H 00021 #define __GL_ITEMS_DOT_H 00022 00023 #include <GL/glew.h> 00024 #include <GL/gl.h> 00025 #include <GL/glu.h> 00026 #include <mathGutz.h> 00027 00028 ////////////////////////////////////////////////////////// 00029 /// a generic gl object, just a base class 00030 class GLItem { 00031 public: 00032 virtual ~GLItem() {} 00033 00034 ///////////////////////////////////////////// 00035 /// drawGL handles some display list stuff for you, 00036 /// you have to call "setUP()" if the object 00037 /// changes and needs to have the disp list re-compiled. 00038 /// drawGL() only calls "drawGLDef()" if the 00039 /// display list is being recompiled or you turn 00040 /// compilation off. 00041 ///@see setCompile 00042 void drawGL(); 00043 00044 ///////////////////////////////////////////// 00045 /// @name compile to a display list? 00046 ///@{ 00047 bool compiles() const { return _compile; } 00048 void setCompile(bool yes) { _compile = yes; } 00049 ///@} 00050 ///////////////////////////////////////////// 00051 00052 ////////////////////////////////////////// 00053 /// object needs update? something changed, 00054 /// for display lists mostly 00055 void setUp(bool yes = true) { _update = yes; } 00056 00057 ////////////////////////////////////////// 00058 /// gl name for picking + push "this pointer" as second name 00059 /// be sure to call "popNames when you are through" 00060 /// ... the drawGL() calls initNames() draw() popNames() 00061 void initNames(unsigned int name1, unsigned int name2); 00062 /// push a name on the pick stack, keeps track of how 00063 /// many you pushed so that when you call popNames() they 00064 /// all come off 00065 void pushName(unsigned int name); 00066 /// pop all names pushed on stack 00067 void popNames(); 00068 ////////////////////////////////////////// 00069 00070 protected: 00071 00072 virtual void drawGLDef() = 0; 00073 00074 GLuint _listName; 00075 bool _compile; 00076 bool _update; 00077 int _numNames; 00078 00079 GLItem(bool compile = true) 00080 : _compile(compile), _listName(0xffffffff), 00081 _update(true), _numNames(0) 00082 {if(compile) _listName = glGenLists(1);} 00083 00084 GLItem(const GLItem &gli) 00085 : _compile(gli._compile), _listName(0xffffffff), 00086 _update(true), _numNames(0) 00087 { if(_compile) _listName = glGenLists(1); } 00088 }; 00089 00090 ////////////////////////////////////////////////////////// 00091 /// a generic glu object. 00092 /// Its drawGLDef() does nothing, but it does allow you 00093 /// to draw various items. A concrete subclass should 00094 /// implement "drawGLDef()" and call one or more of the 00095 /// draw-shape functions. You can also create a GLUItem 00096 /// and just call the draw-shape functions. 00097 class GLUItem : public GLItem { 00098 public: 00099 GLUItem(int slice=20, int stack=20); 00100 GLUItem(const GLUItem &gi); 00101 GLUItem &operator=(const GLUItem &gi); 00102 virtual ~GLUItem(); 00103 00104 GLUquadricObj *getObj() const { return _qobj; } 00105 00106 ////////////////////////////////////////// 00107 /// @name Slices & Stacks. 00108 /// These define the subdivisions 00109 /// used to tesselate the quadric to a polygon. 00110 ///@{ 00111 int getSlice() const { return _slice; } 00112 void setSlice(int slice){ _slice = slice; setUp();} 00113 int getStack() const { return _stack; } 00114 void setStack(int stack){ _stack = stack; setUp();} 00115 ///@} 00116 ////////////////////////////////////////// 00117 00118 ////////////////////////////////////////// 00119 /// @name Draw-shape, creates the geometry for a shape 00120 ///@{ 00121 void drawSphere(const gutz::vec3f &pos, float rad); 00122 void drawBar(const gutz::vec3f &start, const gutz::vec3f &end, float rad); 00123 ///@} 00124 ////////////////////////////////////////// 00125 00126 protected: 00127 /// does nothing!!! 00128 virtual void drawGLDef() {} 00129 GLUquadricObj *_qobj; 00130 int _slice; 00131 int _stack; 00132 }; 00133 00134 #endif 00135 00136