Setting up OpenGL in SDI/MDI MFC application

I am new in OpenGL and even in VC++, was programming with Fortran for all my student time. I am trying to set up OpenGL in MFC SDI or Dialog application. Tried different websites for more than a week so far. I learned basic OpenGL functionalities but yet to fully understand how it connects to MFC. I am trying to exactly follow step by step below procedure to set up OpenGL in a MFC/Dialog from below link.…MFC-Control.htm

I get error on this line:
CreateEx(0, className, “OpenGL”, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rect, parent, 0);
it says "no instance of overloaded function “COpenControl:: CreateEx” matches the argument list.
is it because of different version of VS? any comment is appreciated.
Also tried to follow Microsoft MFCOGL example; it does not have solution “.sln” and I could not build something to test it.

My ultimate goal is to have a MFC/SDI application with a window in it that can show 3D graphic of cutting tools that is moving toward a piece and can zoom/rotate/pan it.

I am using VS2010 Professional in WinXP.
Thanks for any other comment to expedite my learning procedure

First, use glut if you are new. This is the best and easiest way to start with OpenGL with no mess at all.

Second, I think there is no reason to use MFC libraries, and I wonder if they are still really used.

what do you mean, by using “glut”.
by “I think there is no reason to use MFC libraries” you mean for such an application that I am looking for I don’t need to use MFC?

To my opinion, mfc are old. But if you want to continue with them, the error you have says that the arguments you give to CreateEx does not match any prototype providen by MFC. So check for all prototypes of this function and call it the good way (I know nothing about MFC, so maybe it’s just a type that doesn’t match, or a missing argument, or argument ordering…).

I just meant that if you’re new to OpenGL you should first get use to program with it before entering a “big” application. glut won’t allow you to have menus, buttons or such, but it will allow you to work with GL easily, without having to deal with other things (windowing programmation…).

Finally, direct programming with WIN32 libraries should be better than MFC; and VC 2010 provides you an editor to create your window and buttons and such easily, so AFAIK there’s no more need to use MFC.

what do you mean, by using “glut”.

FreeGLUT is a simple library for writing relatively simple OpenGL applications. It does all the setup work for you, which allows you to focus on learning OpenGL. So if you are new to OpenGL and need to learn how the API works, it’s a great starting place.

There is an older GLUT library, which you should not use. It hasn’t been updated in the better part of a decade. FreeGLUT is actually being worked on, so it’s far more likely to work.

As for his commentary on MFC, I have no idea what he’s talking about.

It is a good idea to isolate OpenGL functions from MFC framework. So I recommend you to create GLRenderer class with following attributes and methods:

[ul][li]attribut[LIST][]HGLRC m_hrc – OpenGL Rendering Context (OpenGL server)[/ul][]mehtods[/li] – bool CreateGLContext(CDC* pDC) –Creates OpenGL Rendering Context,
– void PrepareScene(CDC* pDC) – Initializes scene,
– void DestroyScene(CDC* pDC) – Releases resources,
– void Reshape(CDC* pDC, int w, int h) – Executes whenever the window or viewport is resized
– void DrawScene(CDC* pDC) – Draws scene[/LIST]
Include OpenGL support (gl.h, glu.h, …, opengl.lib, glu32.lib, …)

In the View class:
[ul][li]add reference to GLRenderer (m_glRend), []add message handlers for:[LIST][]WM_CREATE,[]WM_ERASEBKGND, []WM_SIZE i []WM_DESTROY, [/ul][]overload OnInitialUpdate []in CGLView::OnCreate call m_glRend.CreateGLContext,[]in CGLView::OnSize call m_glRend.Reshape,[]in CGLView::OnDestroy call m_glRend.DestoyScene,[]in CGLView::OnInitialUpdate call m_glRend.PrepareScene,[]in CGLView::OnDraw call m_glRend.DrawScene,[]in CGLView::OnEraseBkgnd just return TRUE[/LIST][/li]
This is in short how MFC SDI/MDI/Dialog Based application can be OpenGL “enabled”. :slight_smile:

I used LPCTSTR(“OpenGL”) for third arg and it worked.
“CreateEx(0, className, LPCTSTR(“OpenGL”), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rect, parent, 0);”

Thanks for the advises.

The first statement is that MFC is old, but the last claims that you don’t know anything about MFC. Isn’t is contradictory? :slight_smile:

Even more silly statement!!! :slight_smile: :slight_smile:

I really don’t understand need to tell something about the unknown stuff.

Well, MFC library was extremely useful in the time of VS 4.0/4.1/4.2. Then there was an enormous time gap. It is shame that Microsoft don’t support C++ programmers as they did before. There are so many useful tools and libraries for e.g. C#, and practically nothing for C++. It was sad to see VS2k8 with MFC on the level of VS6.0 (even with VS6.0 we used additional libraries for fancy controls). But with the service pack 1 things are become little bit better. Now we have ribbons and all the fancy stuff. :slight_smile:
VS2k10 is on the level of 2k8 considering MFC, but it is still very useful. I would like to see anyone creating Windows application using only Windows API. :wink:

I tried MFC some years ago, and I found that direct C WIN32 was easier, and better supported. So I know enough to say that MFC is old, not really maintained, and know too few about it to try to correct his mistake.

Well, it is time to reconsider your opinion. :wink:

Check, for example, the following link:…nhancements.htm

OK. I don’t want to be out of topic, but…

Making people wait 10 years (1998 - VS 2008) for upgrades, enhancement and such is not a responsive and professional attitude, to my opinion.

So, I won’t reconsider my opinion :slight_smile: