Main MRPT website > C++ reference
MRPT logo
CTexturedObject.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef opengl_CTexturedObject_H
29 #define opengl_CTexturedObject_H
30 
32 #include <mrpt/utils/CImage.h>
33 #include <mrpt/math/geometry.h>
34 
35 namespace mrpt
36 {
37  namespace opengl
38  {
40 
41  // This must be added to any CSerializable derived class:
43 
44  /** A base class for all OpenGL objects with loadable textures.
45  * \sa opengl::COpenGLScene, opengl::CTexturedPlane, opengl::CSetOfTexturedTriangles
46  * \ingroup mrpt_opengl_grp
47  */
49  {
51 
52  protected:
53  mutable unsigned int m_glTextureName;
54  mutable bool m_texture_is_loaded;
55  mutable mrpt::utils::CImage m_textureImage;
56  mutable mrpt::utils::CImage m_textureImageAlpha;
57  mutable bool m_enableTransparency; //!< Of the texture using "m_textureImageAlpha"
58  mutable int r_width,r_height; //!< Size of the texture image, rounded up to next power of 2
59  mutable int m_pad_x_right,m_pad_y_bottom; //!< The size of the fill in pixels in the textured image, w.r.t the image passed by the user.
60 
62  virtual ~CTexturedObject();
63  void unloadTexture();
64 
65  virtual void render_pre() const;
66  virtual void render_post() const;
67 
68  virtual void render_texturedobj() const = 0; //!< Must be implemented by derived classes
69 
70  void writeToStreamTexturedObject(mrpt::utils::CStream &out) const;
71  void readFromStreamTexturedObject(mrpt::utils::CStream &in);
72 
73  public:
74  /** Assigns a texture and a transparency image, and enables transparency (If the images are not 2^N x 2^M, they will be internally filled to its dimensions to be powers of two)
75  * \note Images are copied, the original ones can be deleted.
76  */
77  void assignImage(
78  const mrpt::utils::CImage& img,
79  const mrpt::utils::CImage& imgAlpha );
80 
81  /** Assigns a texture image, and disable transparency.
82  * \note Images are copied, the original ones can be deleted. */
83  void assignImage(const mrpt::utils::CImage& img );
84 
85  /** Similar to assignImage, but the passed images will be returned as empty: it avoids making a copy of the whole image, just copies a pointer. */
86  void assignImage_fast(
87  mrpt::utils::CImage& img,
88  mrpt::utils::CImage& imgAlpha );
89 
90  /** Similar to assignImage, but the passed images will be returned as empty: it avoids making a copy of the whole image, just copies a pointer. */
91  void assignImage_fast(mrpt::utils::CImage& img );
92 
93  /** VERY IMPORTANT: If you use a multi-thread application, you MUST call this from the same thread that will later destruct the object in order to the OpenGL texture memory to be correctly deleted.
94  * Calling this method more than once has no effects. If you use one thread, this method will be automatically called when rendering, so there is no need to explicitly call it.
95  */
96  void loadTextureInOpenGL() const;
97 
98  virtual void render_dl() const;
99 
100  };
101 
102  } // end namespace
103 
104 } // End of namespace
105 
106 
107 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013