Sign in to follow this  

MFC & OpenGl

This topic is 4762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?!

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this