我的代码如下:
void CWnd3D::OnPaint() 
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here
HDC hdc = ::GetDC(m_hWnd);
HGLRC hglrc; // TODO: Add your message handler code here
glClearColor(0,0,0,0);
glColor3f(1, 1, 1); if (hglrc = wglCreateContext(hdc))

        // try to make it the thread's current rendering context 
        if(wglMakeCurrent(hdc, hglrc))
{
  //render here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(m_fRot[0], 1, 0, 0);
glRotatef(m_fRot[1], 0, 1, 0); glScalef(200, 300, 256);/////注意这行!! //画坐标轴
if (m_bAxis)
{
DrawAxis();
}
glPopMatrix();
// glFlush();
SwapBuffers(hdc);
        } 
    }   wglMakeCurrent(NULL, NULL) ; 
::ReleaseDC (m_hWnd, hdc) ; 
wglDeleteContext(hglrc);  // Do not call CWnd::OnPaint() for painting messages
}
void CWnd3D::DrawAxis()
{
glBegin(GL_LINES);
glColor3f(1,0,0);//x轴
glVertex3f(0,0,0); 
glVertex3f(1,0,0); 
glColor3f(0,1,0);//y轴
glVertex3f(0,0,0); 
glVertex3f(0,1,0); 
glColor3f(0,0,1);//z轴
glVertex3f(0,0,0); 
glVertex3f(0,0,1); 
glEnd();
}我想画坐标超过100的图元(如画线从(0,0,0)到(200,120,200)),怎么办?用glScalef()怎么没有反应???

解决方案 »

  1.   

    void CNCSimView::InitDraw()
    {
    glClearColor(m_SimBkColor.Red,m_SimBkColor.Green,m_SimBkColor.Blue,1.0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    //公共变换
        glLoadIdentity();
    glTranslatef(m_SimMove.MoveX,m_SimMove.MoveY,-m_SimMove.MoveZ);
    glScaled(m_SimScale,m_SimScale,m_SimScale);
    glRotatef(m_SimRotate.RotateX,1.0,0.0,0.0);
    glRotatef(m_SimRotate.RotateY,0.0,1.0,0.0);
    glRotatef(m_SimRotate.RotateZ,0.0,0.0,1.0);

        //画轴线
    glDisable(GL_LIGHTING);
    DrawAxis(); if(m_SimMode==SIM_PART_MODE)
    {
    glLightfv(GL_LIGHT0,GL_AMBIENT,m_SimLight.Ambient);
    glLightfv(GL_LIGHT0,GL_DIFFUSE,m_SimLight.Diffuse);
    glLightfv(GL_LIGHT0,GL_SPECULAR,m_SimLight.Specular);
    // glLightfv(GL_LIGHT0,GL_POSITION,m_SimLight.Position);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    }
    else
    {
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    }
    }
    void CNCSimView::DrawAxis()
    {
    glPushMatrix();
    glBegin(GL_LINES);
      glColor3f(1.0f,0.0f,0.0f);
      glVertex3f(0.0f,0.0f,0.0f);
      glVertex3f(500.0f,0.0f,0.0f);
       
      glColor3f(0.0f,1.0f,0.0f);
      glVertex3f(0.0f,0.0f,0.0f);
          glVertex3f(0.0f,500.0f,0.0f);
        
      glColor3f(0.0f,0.0f,1.0f);
      glVertex3f(0.0f,0.0f,0.0f);
      glVertex3f(0.0f,0.0f,500.0f);
        glEnd();
        glPopMatrix();//1

    }void CNCSimView::DrawScreen()
    {
    InitDraw();/* if(m_SimMode==SIM_PART_MODE)
    {
    DrawPart();
    }
    else
    {
    DrawNodeList();
    }
    DrawTool();*/
    SwapBuffers(wglGetCurrentDC());
    }BOOL CNCSimView::OnEraseBkgnd(CDC* pDC) 
    {
    // TODO: Add your message handler code here and/or call default
    DrawScreen();
    return TRUE;
    // return CView::OnEraseBkgnd(pDC);
    }