Click here to Skip to main content
14,267,292 members

Writing a Platform and GUI Toolkit Independent OpenGL Class

Rate this:
4.95 (30 votes)
Please Sign up or sign in to vote.
4.95 (30 votes)
1 Nov 2010CPOL
Article showing how to write OS and GUI toolkit portable OpenGL view class
basecode
linux
MultiGL
GLView
GLViewGTKApp
.project
AUTHORS
autom4te.cache
output.0
requests
traces.0
ChangeLog
config.guess
config.h.in
config.sub
configure
configure.in
COPYING
depcomp
glviewgtkapp.gladep
INSTALL
install-sh
Makefile.am
Makefile.in
missing
mkinstalldirs
NEWS
po
ChangeLog
Makefile.in.in
POTFILES.in
README
src
Makefile.am
Makefile.in
stamp-h.in
GLViewMotifApp
.project
autom4te.cache
output.0
requests
traces.0
config.h.in
configure
configure.ac
depcomp
install-sh
Makefile.am
Makefile.in
missing
src
Makefile.am
Makefile.in
GLViewQtApp
.project
GLViewQtApp.ico
GLViewQtApp.pro.user
glviewqtapp.qrc
Makefile
Resources
.project
autom4te.cache
output.0
requests
traces.0
config.guess
config.h.in
config.sub
configure
configure.ac
depcomp
install-sh
m4
Makefile.am
Makefile.in
missing
src
Makefile.am
Makefile.in
win32
MultiGL
GLView
GLViewGTKApp
AUTHORS
ChangeLog
configure.in
devcpp
glviewgtkapp.dev
glviewgtkapp.gladep
Makefile.am
msvc
glviewgtkapp.suo
glviewgtkapp.vcproj
NEWS
po
ChangeLog
POTFILES.in
README
src
Makefile.am
stamp-h.in
GLViewMFCDlgApp
GLViewMFCDlgApp.aps
GLViewMFCDlgApp.vcproj
res
GLViewMFCDlgApp.ico
GLViewMFCMDIApp
GLViewMFCMDIApp.vcproj
res
buttons.bmp
filelarge.bmp
filesmall.bmp
GLViewMFCMDIApp.ico
GLViewMFCMDIAppDoc.ico
main.bmp
Toolbar.bmp
Toolbar256.bmp
writelarge.bmp
writesmall.bmp
GLViewQtApp
GLViewQtApp
GLViewQtApp.ico
glviewqtapp.qrc
GLViewQtApp.vcproj
Makefile
moc_glviewqtapp.o
Resources
GLView.cpp.bak
GLView.suo
GLView.vcproj
MultiGL.suo
// This MFC Samples source code demonstrates using MFC Microsoft Office Fluent User Interface 
// (the "Fluent UI") and is provided only as referential material to supplement the 
// Microsoft Foundation Classes Reference and related electronic documentation 
// included with the MFC C++ library software.  
// License terms to copy, use or distribute the Fluent UI are available separately.  
// To learn more about our Fluent UI licensing program, please visit 
// http://msdn.microsoft.com/officeui.
//
// Copyright (C) Microsoft Corporation
// All rights reserved.

// GLViewMFCMDIAppView.cpp : implementation of the CGLViewMFCMDIAppView class
//

#include "stdafx.h"
#include "GLViewMFCMDIApp.h"

#include "GLViewMFCMDIAppDoc.h"
#include "GLViewMFCMDIAppView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CGLViewMFCMDIAppView

IMPLEMENT_DYNCREATE(CGLViewMFCMDIAppView, CView)

BEGIN_MESSAGE_MAP(CGLViewMFCMDIAppView, CView)
	ON_WM_SIZE()
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CGLViewMFCMDIAppView::OnFilePrintPreview)
END_MESSAGE_MAP()

// CGLViewMFCMDIAppView construction/destruction

CGLViewMFCMDIAppView::CGLViewMFCMDIAppView()
{
	// TODO: add construction code here
	m_pGLView = new CGLView();
}

CGLViewMFCMDIAppView::~CGLViewMFCMDIAppView()
{
	if(m_pGLView)
	{
		delete m_pGLView;
	}
}

BOOL CGLViewMFCMDIAppView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	return CView::PreCreateWindow(cs);
}

void CGLViewMFCMDIAppView::OnInitialUpdate()
{
	CView::OnInitialUpdate();
	if(m_pGLView)
	{
		m_pGLView->SetWindow(GetSafeHwnd());
		m_pGLView->SetupGLContext(true);
		CRect rect;
		GetClientRect(&rect);
		m_pGLView->Resize(rect.Width(), rect.Height());
	}
}
// CGLViewMFCMDIAppView drawing

void CGLViewMFCMDIAppView::OnDraw(CDC* /*pDC*/)
{
	CGLViewMFCMDIAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
	if(m_pGLView)
	{
		m_pGLView->RenderScene();;
	}
}


// CGLViewMFCMDIAppView printing


void CGLViewMFCMDIAppView::OnFilePrintPreview()
{
	AFXPrintPreview(this);
}

BOOL CGLViewMFCMDIAppView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CGLViewMFCMDIAppView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CGLViewMFCMDIAppView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CGLViewMFCMDIAppView::OnRButtonUp(UINT nFlags, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CGLViewMFCMDIAppView::OnContextMenu(CWnd* pWnd, CPoint point)
{
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
}


// CGLViewMFCMDIAppView diagnostics

#ifdef _DEBUG
void CGLViewMFCMDIAppView::AssertValid() const
{
	CView::AssertValid();
}

void CGLViewMFCMDIAppView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CGLViewMFCMDIAppDoc* CGLViewMFCMDIAppView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGLViewMFCMDIAppDoc)));
	return (CGLViewMFCMDIAppDoc*)m_pDocument;
}
#endif //_DEBUG


// CGLViewMFCMDIAppView message handlers
void CGLViewMFCMDIAppView::OnSize(UINT nType, int cx, int cy)
{
	CView::OnSize(nType, cx, cy);
	if(m_pGLView)
	{
		m_pGLView->Resize(cx, cy);
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sharjith
Product Manager Mahindra & Mahindra
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Stats

73.1K views
6.9K downloads
88 bookmarked