我想用鼠标画一个点:
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    SetCapture();
    CRect rect;
    GetClientRect(&rect);

    pt.x = point.x - rect.right/2;
    pt.y = -(point.y - rect.bottom/2);    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(1.0f, 1.0f, 1.0f);
    glPointSize(3);
    glBegin(GL_POINTS);
glVertex2f(pt.x,pt.y);      
    glEnd();      CView::OnLButtonUp(nFlags, point);
}
最后却看不到结果。请大家帮忙想想办法

解决方案 »

  1.   

    再mfc中调用opengl,你上面的代码应该再调用opengl函数前加如下代码:
    CClientDC dc(this);
    wglMakeCurrent(dc.m_hDC,m_hGLContext);
    其中m_hGLContext 是你在OnCreate里面创建的在函数结尾这么写一句 wglMakeCurrent(NULL,NULL);
      

  2.   

    这段代码我已经加过了,可还是有问题我想还是坐标转换的问题
    pt.x = point.x - rect.right/2;
    pt.y = -(point.y - rect.bottom/2);
    这样得到的点还是显示不出来
      

  3.   

    缺省方式下,opengl能显示的是-1.0<=x<=1.0f,-1.0<=y<=1.0,你的坐标肯定是有问题阿,你的最后的坐标这样吧pt.x = (point.x - rect.right/2)/(rect.right/2);
    pt.y = -(point.y - rect.bottom/2)/(rect.bottom/2);应该就可以了把
      

  4.   

    上面那样差的远,是因为都是整数相除,是不对的,顺便说一下你的pt.x,pt.y的类型都应该是float吧,把后面的变成float 数相除
      

  5.   

    如果定义CPoint ptpt.x = (point.x - rect.right/2.0)/(rect.right/2.0);
    pt.y = -(point.y - rect.bottom/2.0)/(rect.bottom/2.0);这样会产生数据丢失,该如何解决呢?
      

  6.   

    不能使用CPoint保存用于OpenGL的点,必须使用浮点数保存。
      

  7.   

    我也遇到过相似的问题,我是用鼠标放大图像。使用MFC实现OpenGL编程,使用消息映射函数返回的是鼠标在屏幕上的坐标,不是在视图窗口中的坐标,所以你那样是的不到想要的结果的。必须要将其转换成视窗中的坐标才行。