http://msdn.microsoft.com/library/en-us/vcsample98/html/_sample_mfc_cube.asp
解决方案 »
- 求指教:stdafx.h中自定义的头文件无法打开
- 高手进 CPtrList 内存泄露
- 利用filter-hook进行端口过滤的问题
- dll和exe程序窗口消息传递的问题,对话框程序好用,单文档程序就不好用。
- 散分。再来再来,还没拿到分的兄弟过来了
- VC中如何读取Excel表格里的内容
- Error:1813 The specified resource type cannot be found in the image file.
- 谁有用WTL建DLL的文章或代码?(昨天没人回答,希望今天能有)
- 急,求救!
- CTabCtrl在切换到CDialog时如何在显示前更新某个控件?
- 超级难题: 怎么用程序关闭 MessageBox 弹出的消息框 ?
- 文件格式(.par还有.tcl)
VIEW中再包括以下头文件:
#include "gl\gl.h"
#include "gl\glu.h"
#include "gl\glaux.h"
就可以最VIEW中使用OpenGL了。请看下面的例子:int CAtlas98GLView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CScrollView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
InitPixelFormat();
InitProjection();
return 0;
}void CAtlas98GLView::InitPixelFormat()
{
HGLRC hrc;
m_pDC = new CClientDC(this);
ASSERT(m_pDC != NULL);
if (!bSetupPixelFormat())
return;
hrc = wglCreateContext(m_pDC->GetSafeHdc());
wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
}BOOL CAtlas98GLView::bSetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int pixelformat; if ( (pixelformat = ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd)) == 0 )
{
MessageBox("ChoosePixelFormat failed");
return FALSE;
} if (SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &pfd) == FALSE)
{
MessageBox("SetPixelFormat failed");
return FALSE;
} return TRUE;
}
void CAtlas98GLView::InitProjection()
{
GLfloat fMaxObjSize, fAspect;
GLfloat fNearPlane, fFarPlane; GetClientRect(&m_oldRect);
if(m_oldRect.bottom == 0)
m_oldRect.bottom = 1;
glViewport(0,0,m_oldRect.right,m_oldRect.bottom); glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST); fAspect = (GLfloat)m_oldRect.right/m_oldRect.bottom;
fNearPlane = 0.001f;
// fFarPlane = 20.0f;
// fMaxObjSize = 20.0f;
fFarPlane = 10.0f;
fMaxObjSize = 10.0f;
m_dRadius = fNearPlane + fMaxObjSize/2.0f; glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, fAspect, fNearPlane, fFarPlane);
glMatrixMode(GL_MODELVIEW);
}