VRUT::ImageCommon Class Reference

Image container with support for many formats readable by wxImage. More...

#include <imagecommon.h>

Inheritance diagram for VRUT::ImageCommon:

VRUT::Image

List of all members.

Public Member Functions

 ImageCommon ()
 Class constructor.
virtual ~ImageCommon ()
 Class destructor.
virtual bool IsOk () const
 Is image properly loaded? - Image overload.
virtual bool Load (const wxString &fname)
 Load image data from file - Image overload.
virtual GLuint BuildOglTexture () const
virtual bool HasTransparency () const
 Get true if image has alpha channel - Image overload.
virtual int GetWidth () const
 Get the widht of the image.
virtual int GetHeight () const
 Get the height of the image.

Protected Attributes

wxImage * image
 wxImage instance


Detailed Description

Image container with support for many formats readable by wxImage.

Definition at line 23 of file imagecommon.h.


Constructor & Destructor Documentation

ImageCommon::ImageCommon (  ) 

Class constructor.

Definition at line 19 of file imagecommon.cpp.

00019                          : Image(), image((wxImage *)NULL)
00020 {
00021 }

ImageCommon::~ImageCommon (  )  [virtual]

Class destructor.

Definition at line 24 of file imagecommon.cpp.

00025 {
00026        SAFE_DELETE(image);
00027 }


Member Function Documentation

bool ImageCommon::IsOk (  )  const [virtual]

Is image properly loaded? - Image overload.

Implements VRUT::Image.

Definition at line 30 of file imagecommon.cpp.

00031 {
00032        return image && image->IsOk();
00033 }

bool ImageCommon::Load ( const wxString &  fname  )  [virtual]

Load image data from file - Image overload.

Reimplemented from VRUT::Image.

Definition at line 36 of file imagecommon.cpp.

00037 {
00038        if (Image::Load(fname))
00039        {
00040               wxImage im(fname);
00041               if (im.IsOk())
00042               {
00043                      SAFE_DELETE(image);
00044                      image = new wxImage(im.Mirror(false));
00045                      return true;
00046               }
00047        }
00048        return false;
00049 }

GLuint ImageCommon::BuildOglTexture (  )  const [virtual]

Build and bind OpenGL texture from image in CURRENT OpenGL context - Image overload

Returns:
OpenGL ID for texture, GL_ID_NONE if failed

Join RGB and Alpha data

Implements VRUT::Image.

Definition at line 52 of file imagecommon.cpp.

00053 {
00054        GLuint texID = GL_ID_NONE;
00055        if (IsOk())
00056        {
00057               glEnable(GL_TEXTURE_2D);
00058               glGenTextures( 1, &texID );
00059               glBindTexture( GL_TEXTURE_2D, texID );
00060               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
00061               glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
00062               if (image->HasAlpha())
00063               {
00065                      unsigned pixels = image->GetWidth() * image->GetHeight();
00066                      GLubyte * rgbaData = new GLubyte[pixels * 4];
00067                      unsigned char * tmpRGBA = rgbaData;
00068                      unsigned char * rgbData = image->GetData();
00069                      unsigned char * alphaData = image->GetAlpha();
00070                      for (unsigned pix = 0; pix < pixels; pix++)
00071                      {
00072                             *tmpRGBA++ = *rgbData++;
00073                             *tmpRGBA++ = *rgbData++;
00074                             *tmpRGBA++ = *rgbData++;
00075                             *tmpRGBA++ = *alphaData++;
00076                      }
00077                      gluBuild2DMipmaps(GL_TEXTURE_2D,
00078                                    4,
00079                                    image->GetWidth(),
00080                                    image->GetHeight(),
00081                                    GL_RGBA,
00082                                    GL_UNSIGNED_BYTE,
00083                                    rgbaData);
00084                      delete [] rgbaData;
00085               }
00086               else
00087                      gluBuild2DMipmaps(GL_TEXTURE_2D,
00088                                    3,
00089                                    image->GetWidth(),
00090                                    image->GetHeight(),
00091                                    GL_RGB,
00092                                    GL_UNSIGNED_BYTE,
00093                                    image->GetData());
00094        }
00095        return texID;
00096 }

bool ImageCommon::HasTransparency (  )  const [virtual]

Get true if image has alpha channel - Image overload.

Implements VRUT::Image.

Definition at line 99 of file imagecommon.cpp.

00100 {
00101        return IsOk() && (image->HasAlpha() || image->HasMask());
00102 }

int ImageCommon::GetWidth (  )  const [virtual]

Get the widht of the image.

Implements VRUT::Image.

Definition at line 104 of file imagecommon.cpp.

00105 {
00106        return (IsOk()?image->GetWidth():0);
00107 }

int ImageCommon::GetHeight (  )  const [virtual]

Get the height of the image.

Implements VRUT::Image.

Definition at line 109 of file imagecommon.cpp.

00110 {
00111        return (IsOk()?image->GetHeight():0);
00112 }


Member Data Documentation

wxImage* VRUT::ImageCommon::image [protected]

wxImage instance

Definition at line 27 of file imagecommon.h.


The documentation for this class was generated from the following files:

Generated on Tue Mar 10 14:41:43 2009 for VRUT by  doxygen 1.5.5