基于wfc的openGL画条线显示不出 2C

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: 在此处为本机数据添加绘制代码

}
哪有错么 累人百度了好久还是不会解决

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐