Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef MOVEIT_MESH_FILTER_GLRENDERER_
00038 #define MOVEIT_MESH_FILTER_GLRENDERER_
00039
00040 #include <GL/glew.h>
00041 #ifdef __APPLE__
00042 #include <OpenGL/gl.h>
00043 #else
00044 #include <GL/gl.h>
00045 #endif
00046 #include <string>
00047 #include <boost/thread.hpp>
00048
00049 namespace mesh_filter
00050 {
00054 class GLRenderer
00055 {
00056 public:
00065 GLRenderer (unsigned width, unsigned height, float near = 0.1, float far = 10.0);
00066
00068 ~GLRenderer ();
00069
00074 void begin () const;
00075
00080 void end () const;
00081
00087 void callList (GLuint list) const;
00088
00094 void getColorBuffer(unsigned char* buffer) const;
00095
00101 void getDepthBuffer(float* buffer) const;
00102
00110 GLuint setShadersFromFile (const std::string& vertex_filename, const std::string& fragment_filename);
00111
00119 GLuint setShadersFromString (const std::string& vertex_shader, const std::string& fragment_shader);
00120
00129 void setCameraParameters (float fx, float fy, float cx, float cy);
00130
00137 void setClippingRange (float near, float far);
00138
00144 const float& getNearClippingDistance () const;
00145
00151 const float& getFarClippingDistance () const;
00152
00158 const unsigned getWidth () const;
00159
00165 const unsigned getHeight () const;
00166
00173 void setBufferSize (unsigned width, unsigned height);
00174
00180 const GLuint& getProgramID () const;
00181
00187 GLuint getDepthTexture () const;
00188
00194 GLuint getColorTexture () const;
00195
00196 private:
00201 void setCameraParameters () const;
00202
00209 void readShaderCodeFromFile (const std::string& filename, std::string& source) const;
00210
00218 GLuint loadShaders (const std::string& vertex_source, const std::string& fragment_source) const;
00219
00227 GLuint createShader (GLuint shaderID, const std::string& source) const;
00228
00233 void initFrameBuffers ();
00234
00239 void deleteFrameBuffers ();
00240
00245 static void createGLContext ();
00246
00251 static void deleteGLContext ();
00252
00254 unsigned width_;
00255
00257 unsigned height_;
00258
00260 GLuint fbo_id_;
00261
00263 GLuint rbo_id_;
00264
00266 GLuint rgb_id_;
00267
00269 GLuint depth_id_;
00270
00272 GLuint program_;
00273
00275 float near_;
00276
00278 float far_;
00279
00281 float fx_;
00282
00284 float fy_;
00285
00287 float cx_;
00288
00290 float cy_;
00291
00293 static std::map<boost::thread::id, std::pair<unsigned, GLuint> > context_;
00294
00295
00296 static boost::mutex context_lock_;
00297
00298 static bool glutInitialized_;
00299
00300 };
00301 }
00302 #endif