Jump to content
  • Advertisement
Sign in to follow this  

MFC & OpenGl

This topic is 4974 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.


Share this post

Link to post
Share on other sites
pretty easy




CClientDC dc(this);
//choose pixelformat and create rendering context


m_glDevice.enable();// wglmakecurrent(...)



onpaint(CPaintDC *pDC)

//draw your geometry here ....


onerasbkgrnd()//erase background
return TRUE; // prevents windows from filling the clientarea with //white color every frame


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

HGLRC glRC = wglcreatecontext

for more detailed information read up the MSDN

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!