void Ctest1View::OnDestroy()
{
CView::OnDestroy();
::wglMakeCurrent(NULL, NULL);
::wglDeleteContext(m_hRC);
}
void Ctest1View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType,cx,cy);
glViewport(0,0,cx,cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-cx / 2, cx / 2, -cy / 2, cy / 2, -10, 10);
}
int Ctest1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct)==-1)
{
return -1;
}
gl_Init();
return 0;
}
void Ctest1View::Draw()
{
gl_Transform();
glClearColor(1.0f,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);
for (int i = 0; i < 100; i++)
{
gl_Point(i, 0);
}
glFlush();
SwapBuffers(m_hDc);
}
void Ctest1View::gl_Init()
{
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,0,
0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0,
};
m_hDc = GetDC()->GetSafeHdc();
int nPixelFomat = ::ChoosePixelFormat(m_hDc,&pfd);
::SetPixelFormat(m_hDc,nPixelFomat,&pfd);
m_hRC = ::wglCreateContext(m_hDc);
::wglMakeCurrent(m_hDc,m_hRC);
}
void Ctest1View::gl_Transform()
{
RECT r;
GetClientRect(&r);
glOrtho(0 ,r.right/2,-r.bottom/2,r.top /2,-10,10);
}
void Ctest1View::gl_Point(GLint x,GLint y)
{
glBegin(GL_POINTS);
glVertex2d(x,y);
glEnd();
}
// Ctest1View 绘制
void Ctest1View::OnDraw(CDC* /*pDC*/)
{
Ctest1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//if (!pDoc)
// return;
Draw();
// TODO: 在此处为本机数据添加绘制代码
}
哪有错么 累人百度了好久还是不会解决