MFC & OpenGl
I have a problem. I have to put gl inside an SDI application on MFC. But of course I do not have bloody idea how to do this. If someone could help me with the correct code or some hints for example where to put functions from NeHe's tutorials. I'd be grateful for details.
This kinda requires a bit of work but it is almost the same as lesson one of the tutorial. The only real difference is managing your render contexts (which window in the mfc app is being drawn to). If you set it up properly, you should even be able to add gl to dialog boxes with little effort.
The first place to start is to try to interface nehe's stuff (lesson one) with the mfc app. Make a list of all the things you need from windows to do setup gl using nehe's method and then try to find equivilents in mfc. You will also have to do a few things to get mfc to not flicker and update properly, but that shouldnt be too hard (search topics on this forum for the properties you need to set).
Good luck,
- llvllatrix
The first place to start is to try to interface nehe's stuff (lesson one) with the mfc app. Make a list of all the things you need from windows to do setup gl using nehe's method and then try to find equivilents in mfc. You will also have to do a few things to get mfc to not flicker and update properly, but that shouldnt be too hard (search topics on this forum for the properties you need to set).
Good luck,
- llvllatrix
The easyest way is to it is:
1 place a random control on your form.
2 grab it's dc control->getDC or something
3 init the opengl rendering context and stuff using the code from lesson 1, using the DC from step 2
1 place a random control on your form.
2 grab it's dc control->getDC or something
3 init the opengl rendering context and stuff using the code from lesson 1, using the DC from step 2
I'm not really sure what am I doing but correct me if I'm wrong. Should I put the initialization lines like window styles, hbrBackground and so on (these from NeHe's createGLwindow function) into the CMyView::PreCreateWindow(CREATESTRUCT& cs) function in MFC?? Please help?! What now? Is this a good place to attach all those contexts? And where should I put globals?!
The best place is as soon as possible, but the controls have to be created first (to get that DC)
So in MFC you usually can't use the contructor.
I think you can't use the precreatewindow either because the controls aren't initialized there yet(i think)
So you should use the onInitialUpdate or onCreate (after standard call is called).
So in MFC you usually can't use the contructor.
I think you can't use the precreatewindow either because the controls aren't initialized there yet(i think)
So you should use the onInitialUpdate or onCreate (after standard call is called).
You could take a look at this tutorial here at gamedev.net.
It uses MFC and openGL, using multiple windows makes it a bit harder, but you'll get the point.
If you wan't a single window, copy paste the code from OpenGLWnd.h/.cpp to your view class.
http://www.gamedev.net/reference/articles/article1358.asp
It uses MFC and openGL, using multiple windows makes it a bit harder, but you'll get the point.
If you wan't a single window, copy paste the code from OpenGLWnd.h/.cpp to your view class.
http://www.gamedev.net/reference/articles/article1358.asp
pretty easy
precreatewindow
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
oncreate()....
CClientDC dc(this);
m_glDevice.Create(dc.m_hDC);
//choose pixelformat and create rendering context
onsize(cx,cy)
m_glDevice.enable();// wglmakecurrent(...)
glViewport(0,0,cx,cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
.....
glMatrixMode(GL_MODELVIEW);
glLoadIdentity():
....
m_glDevice.Disable()://wglmakecurrent(null.null);
onpaint(CPaintDC *pDC)
m_glDevice.enable();
glClearColor(...);
glClear(....);
//draw your geometry here ....
SwapBuffers(....);
m_glDevice.Disable();
onerasbkgrnd()//erase background
return TRUE; // prevents windows from filling the clientarea with //white color every frame
ondestroy()
m_glDevice.Delete();// delete your rendering context
// member of your View, Dialog, control class
COpenglDevice m_glDevice;
in m_glDevice.Create(...)
your describe a pixelformat
int iformat = choosepixelformat
setpixelformat(iformat)
HGLRC glRC = wglcreatecontext
for more detailed information read up the MSDN
precreatewindow
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
oncreate()....
CClientDC dc(this);
m_glDevice.Create(dc.m_hDC);
//choose pixelformat and create rendering context
onsize(cx,cy)
m_glDevice.enable();// wglmakecurrent(...)
glViewport(0,0,cx,cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
.....
glMatrixMode(GL_MODELVIEW);
glLoadIdentity():
....
m_glDevice.Disable()://wglmakecurrent(null.null);
onpaint(CPaintDC *pDC)
m_glDevice.enable();
glClearColor(...);
glClear(....);
//draw your geometry here ....
SwapBuffers(....);
m_glDevice.Disable();
onerasbkgrnd()//erase background
return TRUE; // prevents windows from filling the clientarea with //white color every frame
ondestroy()
m_glDevice.Delete();// delete your rendering context
// member of your View, Dialog, control class
COpenglDevice m_glDevice;
in m_glDevice.Create(...)
your describe a pixelformat
int iformat = choosepixelformat
setpixelformat(iformat)
HGLRC glRC = wglcreatecontext
for more detailed information read up the MSDN
http://www.8ung.at/basiror/theironcross.html
if you still need help I have a bunch of MFC examples on my site. If not, congratulations and keep at it :)
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement