This tip contains a basic working example of OpenGL with MFC/CDialog, without the deprecated
glEnd(). The project contains code that enables multiple contexts MFC/CDialog-style.
The basic idea is to get a simple window or two to draw simple graphics in a MFC/CDialog-style window. This is geared more towards beginners who, like myself, struggle to get something like this to work. A basic understanding of C++/OpenGL would be helpful. The code contains no colour mapping or shaders, just basic shape using vao/vbo.
Using the Code
The code was written in VS 2010 as MFC project. It makes use of GLEW & its library.
How to use:
- Unzip, Open Solution & compile to see example work.
- Make sure to include glew32.dll in the debug/release folder, as I have not included it.
The following snippet of code highlights main link/binding:
bool OpenGLRenderer::CreateGLContext(CRect rect, CWnd *parent)
CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW |
CS_OWNDC, NULL, (HBRUSH)GetStockObject(WHITE_BRUSH),
CreateEx(0, className, _T("OpenGL with MFC/CDialog"),
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rect, parent, 0);
MessageBox(_T("ERROR Creating InitContext"));
Points of Interest
I searched, Googled & read a lot, but failed to come across a complete example that displayed the above without using
winmain() as the entry point. Very frustrating.
I don't plan on maintaining this, unless something serious warrants updating. There is probably more efficient ways to implement this. I just wanted to share this as I struggled to find something similar that contained a full yet basic working example.