Original Post
Ok, so I have some smart pointers for texture files, and I''m having some trouble with them.
// Class TexPtr has: protected CImage *m_texture
TexPtr::TexPtr()
:m_texture(0)
{
}
TexPtr::TexPtr(CImage *m)
:m_texture(m)
{
if(m_texture != 0)
m_texture->attach();
}
TexPtr::TexPtr(TexPtr &p)
:m_texture(p.m_texture)
{
if(m_texture != 0)
m_texture->attach();
}
TexPtr::~TexPtr()
{
if(m_texture != 0)
m_texture->release();
}
void TexPtr::operator =(TexPtr &p)
{
// release old pointer
if(m_texture != 0)
m_texture->release();
// get new pointer and attach it
m_texture=p.m_texture;
if(m_texture != 0)
m_texture->attach();
}
void TexPtr::operator =(CImage *p)
{
// release old pointer
if(m_texture != 0)
m_texture->release();
// get new pointer and attach it
m_texture=p;
if(m_texture != 0)
m_texture->attach();
}
const CImage *TexPtr::operator ->()
{
return m_texture;
}
const CImage TexPtr::operator *()
{
return *m_texture;
}
bool TexPtr::operator ==(const CImage &p)
{
return (m_texture==&p);
}
bool TexPtr::operator ==(const TexPtr &p)
{
return (m_texture==p.m_texture);
}
bool TexPtr::operator !()
{
return (m_texture == 0);
}
bool TexPtr::operator !=(const CImage &p)
{
return (m_texture!=&p);
}
bool TexPtr::operator !=(const TexPtr &p)
{
return (m_texture!=p.m_texture);
}
class CImage:public MemoryObject
{
public:
//Load the image
bool Load(char * szFilename);
//Bind texture
void Bind();
//Unbind texture
void UnBind();
//Flip image
void VFlip(unsigned char * ucpData, unsigned int uiHeight, unsigned int uiWidth, unsigned int uiBpp); //Vertically
//Save a screenshot
static void ScreenShot(char * szDstFile = "screenshot.tga");
unsigned int getID()
{
return m_uiImage;
}
//Constructors
CImage()
:m_bBlend(false), m_szFilename(NULL), m_ucpBuffer(NULL), m_uiImage(0)
{
}
CImage(char * szFile)
:m_bBlend(false), m_szFilename(NULL), m_ucpBuffer(NULL)
{
Load(szFile);
}
~CImage()
{
}
void Destroy()
{
glDeleteTextures(1, &m_uiImage);
}
void ReloadTexture()
{
if(m_uiImage != 0)
Load(m_szFilename);
}
private:
//Load various image formats
bool LoadTGA(bool bCompressed);
bool LoadBMP();
bool LoadPCX();
bool LoadJPG();
//dimentions
unsigned int m_uiWidth;
unsigned int m_uiHeight;
//unsigned int m_uiFileLen; //needed for PCX
//Image ID
unsigned int m_uiImage;
//file buffer
unsigned char * m_ucpBuffer;
//mipmap?
bool m_bMipMap;
bool m_bBlend;
//filename
char * m_szFilename;
};
// Sphere has protected TexPtr texture
void Sphere::draw()
{
glColor3f(getRed(), getGreen(), getBlue());
orientation.multTimesWorld();
if(texture.isValid())
texture->Bind();
gluSphere(quadratic, radius, precision, precision);
if(texture.isValid())
texture->UnBind();
}
I get the following error upon compilation:
c:\program files\microsoft visual studio\opengl\strnad\project\recent\currenterikengine\sphere.cpp(33) : error C2662: ''Bind'' : cannot convert ''this'' pointer from ''const class CImage'' to ''class CImage &''
Conversion loses qualifiers
c:\program files\microsoft visual studio\opengl\strnad\project\recent\currenterikengine\sphere.cpp(38) : error C2662: ''UnBind'' : cannot convert ''this'' pointer from ''const class CImage'' to ''class CImage &''
Conversion loses qualifiers
What''s going on?