Anyone ever experimented heavily with OpenGL and MFC?

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).]

I am pleased to report that my hypothesis seems to be correct: I moved the RegisterWithOpenGL code to later on in the cycle (in the OnSetActive() method of the CTexturePage property page) and it WORKS!!!

Only thing I’m noticing now is my framerate is slower than molasses, but I’m sure that with a little reorganization and optimization I can overcome that.

One of my future plans is to be able to export the scene as my own model format and then read it in as a texture and vertex array to another program. Again, yeah I know I’m reinventing the wheel but hey, it’s fun!

I’d still like to hear from anyone else who’s ever done anything like this if y’all wouldn’t mind!

Thanks
Joe

I’m a doofus - my framerate was slow because I wasn’t setting m_bRegistered to True after registering a texture, so it was registering every texture every frame (insert the embarrassed smiley from MSN here).

Gimme the labor day weekend to continue cleaning stuff up and I’ll upload the latest.