// minoglView.cpp : implementation of the CMinoglView class
//
#include "stdafx.h"
#include "minogl.h"
#include "minoglDoc.h"
#include "minoglView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMinoglView
IMPLEMENT_DYNCREATE(CMinoglView, CView)
BEGIN_MESSAGE_MAP(CMinoglView, CView)
//{{AFX_MSG_MAP(CMinoglView)
ON_WM_CREATE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMinoglView construction/destruction
CMinoglView::CMinoglView()
{
// TODO: add construction code here
}
CMinoglView::~CMinoglView()
{
}
BOOL CMinoglView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMinoglView drawing
void CMinoglView::OnDraw(CDC* pDC)
{
CMinoglDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
wglMakeCurrent(pDC->m_hDC, m_hRC);
DrawWithOpenGL(); // Helper function does all drawing
wglMakeCurrent(pDC->m_hDC, NULL);
}
/////////////////////////////////////////////////////////////////////////////
// CMinoglView diagnostics
#ifdef _DEBUG
void CMinoglView::AssertValid() const
{
CView::AssertValid();
}
void CMinoglView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMinoglDoc* CMinoglView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMinoglDoc)));
return (CMinoglDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMinoglView message handlers
int CMinoglView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,0,0,0,0,0,0, // 24 color bits
0,0,0,0,0,0,0,
32,0,0,0,0,0,0,0 // 32 bit deep Z-buffer
};
CDC* pDC = GetDC();
int pixelFormat = ChoosePixelFormat(pDC->m_hDC, &pfd);
SetPixelFormat(pDC->m_hDC, pixelFormat, &pfd);
m_hRC = wglCreateContext(pDC->m_hDC);
return 0;
}
void CMinoglView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
wglDeleteContext(m_hRC);
}
// *** Drawing helper function ***
void CMinoglView::DrawWithOpenGL()
{
float i;
glClearColor(1.0f,1.0f,1.0f,1.0f); // assign white as backgnd color for window
glClear(GL_COLOR_BUFFER_BIT); // make assigned backgnd color be displayed
// Draw a rectangle in different shades of red
for (i=0.2f; i<=1.0; i+=0.2f)
{
glColor3f(i, 0.0, 0.0); // drawing color
glBegin(GL_POLYGON); // define the rectangle
glVertex2f(-0.5,-0.5);
glVertex2f(-0.5,0.5);
glVertex2f(0.5,0.5);
glVertex2f(0.5,-0.5);
glEnd();
glFlush(); // force execution
Sleep(1000); // wait a while
}
}