Greetings fellow OpenGLites,
I just wanted to see if anyone’s ever tried what I’m trying here: I’m learning both MFC and OpenGL right now, and just as a learning experience I’m designing my own modelling tool. I just recently added serialization support. I have a class I’m calling CTexture which is defined as follows:
class CTexture : public CObject
{
public:
virtual void Serialize(CArchive& ar);
void RegisterWithOpenGL();
unsigned int m_uiTexTexID;
unsigned int m_uiViewTexID;
CString m_sDescription;
CString m_sFilename;
CTexture();
AUX_RGBImageRec* m_bitmapData;
virtual ~CTexture();
CTexture& operator=(CTexture& vTexture)
{
if (this != &vTexture)
{
m_sDescription = vTexture.m_sDescription;
m_sFilename = vTexture.m_sFilename;
m_uiTexTexID = vTexture.m_uiTexTexID;
m_uiViewTexID = vTexture.m_uiViewTexID;
m_bitmapData = vTexture.m_bitmapData;
}
return *this;
}
CTexture::CTexture(CTexture& vTexture)
{
m_sDescription = vTexture.m_sDescription;
m_sFilename = vTexture.m_sFilename;
m_uiViewTexID = vTexture.m_uiViewTexID;
m_uiTexTexID = vTexture.m_uiTexTexID;
m_uiViewTexID = vTexture.m_uiViewTexID;
m_bitmapData = vTexture.m_bitmapData;
}
protected:
DECLARE_SERIAL(CTexture)
private:
BOOL m_bRegistered;
};
and here’s the code for RegisterWithOpenGL:
void CTexture::RegisterWithOpenGL()
{
if (!m_bRegistered)
{
CMDIModeler3App* myApp = (CMDIModeler3App*)AfxGetApp();
HDC hDC;
HGLRC hRC;
hDC = myApp->m_hDCTexturePage;
hRC = myApp->m_hRCTexturePage;
wglMakeCurrent(hDC, hRC);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &m_uiTexTexID);
glBindTexture(GL_TEXTURE_2D, m_uiTexTexID); // enable our texture object
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_bitmapData->sizeX, m_bitmapData->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, m_bitmapData->data);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_bitmapData->sizeX, m_bitmapData->sizeY, GL_RGB, GL_UNSIGNED_BYTE, m_bitmapData->data);
hDC = myApp->m_hDCView;
hRC = myApp->m_hRCView;
wglMakeCurrent(hDC, hRC);
glGenTextures(1, &m_uiViewTexID);
glBindTexture(GL_TEXTURE_2D, m_uiViewTexID); // enable our texture object
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_bitmapData->sizeX, m_bitmapData->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, m_bitmapData->data);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_bitmapData->sizeX, m_bitmapData->sizeY, GL_RGB, GL_UNSIGNED_BYTE, m_bitmapData->data);
}
}
When I save a file and then open it, the textures are all just blank white. Any subsequent textures that I create are functional though.
My working hypothesis is that the DCs on the texture dialog and on the main view haven’t been created yet and therefore wglMakeCurrent is failing. I’m going to try a few different things to get around that.
But mainly with this post, I’m curious as to if anyone’s ever tried anything like this.
Let me know!
If you’re curious as to the code, it can be found on my page: http://daltxcoltsfan.tripod.com - just scroll below the modeler screenshots and there’s a link.
Thanks
Joe
[This message has been edited by DalTXColtsFan (edited 08-28-2003).]