1 // BASE_APP.H : an OpenGL application base class. 2 3 // Copyright (C) 2005 Tommi Hassinen. 4 5 // This package is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 2 of the License, or 8 // (at your option) any later version. 9 10 // This package is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 15 // You should have received a copy of the GNU General Public License 16 // along with this package; if not, write to the Free Software 17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 19 /*################################################################################################*/ 20 21 //#include "config.h" 22 23 #ifndef BASE_APP_H 24 #define BASE_APP_H 25 26 /*################################################################################################*/ 27 28 #ifdef WIN32 29 #include <windows.h> // need to have this before the GL stuff... 30 #endif // WIN32 31 32 #include <GL/gl.h> 33 #include <GL/glu.h> 34 35 #include <map> 36 #include <vector> 37 using namespace std; 38 39 /*################################################################################################*/ 40 41 struct mouseinfo; 42 43 class base_app; 44 45 #include "base_wnd.h" 46 47 #include "ogl_camera.h" 48 #include "ogl_lights.h" 49 50 #include "transparent.h" 51 52 /*################################################################################################*/ 53 54 struct mouseinfo 55 { 56 enum mi_state { sUp, sDown, sUnknown }; 57 enum mi_button { bLeft, bMiddle, bRight, bNone }; 58 59 static mi_state state; 60 static mi_button button; 61 62 static bool shift_down; 63 static bool ctrl_down; 64 65 static float ang_sensitivity; 66 static float dist_sensitivity; 67 68 static int latest_x; 69 static int latest_y; 70 }; 71 72 /*################################################################################################*/ 73 74 class base_app 75 { 76 private: 77 78 static base_app * app; 79 80 protected: 81 82 vector<ogl_camera *> camera_vector; 83 vector<ogl_light *> light_vector; 84 85 GLuint glname_counter; // these are for generating GLuint-type 86 map<GLuint, void *> glname_map; // names for objects (or memory blocks). 87 88 vector<transparent_primitive> tp_vector; 89 90 // friends... 91 // ^^^^^^^^^^ 92 friend class ogl_camera; 93 94 public: 95 96 base_app(void); 97 virtual ~base_app(void); 98 99 static base_app * GetAppB(void); 100 101 // simple messaging methods: 102 // ^^^^^^^^^^^^^^^^^^^^^^^^^ 103 104 virtual void Message(const char *) = 0; 105 virtual void WarningMessage(const char *) = 0; 106 virtual void ErrorMessage(const char *) = 0; 107 virtual bool Question(const char *) = 0; 108 109 // some camera/light-related methods: 110 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 111 112 virtual void AddCamera(ogl_camera *); 113 virtual bool RemoveCamera(ogl_camera *); 114 115 virtual bool AddGlobalLight(ogl_light *); 116 virtual bool AddLocalLight(ogl_light *, ogl_camera *); 117 virtual bool RemoveLight(ogl_dummy_object *); 118 119 int IsLight(const ogl_dummy_object *); 120 121 GLint CountGlobalLights(void); 122 GLint CountLocalLights(ogl_camera *); 123 124 void SetupLights(ogl_camera *); 125 126 void SetGlobalLightNumbers(void); 127 void SetLocalLightNumbers(ogl_camera *); 128 129 void UpdateLocalLightLocations(ogl_camera *); 130 void RenderLights(ogl_camera *); 131 132 // OpenGL selection naming methods: 133 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 134 135 GLuint RegisterGLName(void *); 136 void UnregisterGLNameByName(GLuint); 137 void UnregisterGLNameByPtr(void *); 138 void * FindPtrByGLName(GLuint); 139 140 // transparent primitive rendering methods: 141 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 142 143 bool AddTP(void *, transparent_primitive &); 144 void UpdateMPsForAllTPs(void *); 145 void RenderAllTPs(ogl_camera *); 146 void RemoveAllTPs(void *); 147 }; 148 149 /*################################################################################################*/ 150 151 #endif // BASE_APP_H 152 153 // eof 154