8/20/2012

source code - OpenGL Drawing on MFC dlg(using COpenGLControl class)

This  post introduces how to drawing opengl on the mfc dialog.
If we are using COpenGLControl class, this work is very easy and simple.

Fi rstly, get the COpenGLControl class in the web or on this.

1. In the ~Dlg.h, Add header file and member variable

#include "OpenGLControl.h"
~
COpenGLControl m_oglWindow;


2. Add below source code in the OnInitDialog() function.

CRect rect;
// Get size and position of the template textfield we created before in the dialog editor
GetDlgItem(IDC_PIC_OPENGL)->GetWindowRect(rect);
// Convert screen coordinates to client coordinates
ScreenToClient(rect);
// Create OpenGL Control window
m_oglWindow.oglCreate(rect, this);
// Setup the OpenGL Window's timer to render
m_oglWindow.m_unpTimer = m_oglWindow.SetTimer(1, 1, 0);


* You have to set picture box option as "Visible is False".


The source code is here.