用opengl画一个长方体,画出来的没有立体感,怎么设置视角
在vc.net平台上,在对话框窗口的一个Edit Control控件上用opengl画一个长方体,画出来的没有立体感,不知道怎么设置视角。
语句如下:
初始化工作:
CWnd* pWnd = GetDlgItem(IDC_EDIT1);
m_pDC = pWnd->GetDC();
m_hDC = m_pDC->GetSafeHdc();
SetDCPixelFormat(); //调整该DC的象素格式
m_hRC=wglCreateContext(m_hDC); //用这种DC去创建一个RC
wglMakeCurrent(m_hDC,m_hRC); //指定当前DC、当前RC为hDC、hRC
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
CRect rect;
GetClientRect(&rect); //得到绘图窗口区域的结构体
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f,rect.Width()/rect.Height(),0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-0.0f,0.0f,-4.0f);
glColor3f(0.0,1.0,0.0); //绿色
RenderScene里:
CWnd* pWnd = GetDlgItem(IDC_EDIT1);
pWnd->UpdateWindow();
auxWireBox(1,1,1);
SwapBuffers(m_hDC);