『壹』 用OpenGL中的函數glutSolidSphere畫圓為何結果只顯示了四分之一個圓
#pragma comment( linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#include<gl/glut.h>
void Initial()
{
//glEnable(GL_DEPTH_TEST);//啟用深度測試,根據坐標的遠近自動隱藏被遮住的圖形
glClearColor(1.0f,1.0f,1.0f,0.0f);
}
void ChangeSize(int w,int h)
{
GLfloat aspect;
aspect=(float)w/(float)h;
glViewport(w/2,h/2,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
{
glOrtho(0.0f,500.0f,0.0f,500.0f*h/w,1.0f,-1.0f);
}
else
{
glOrtho(0.0f,500.0f*w/h,0.0f,500.0f,1.0f,-1.0f);
}
gluPerspective(90,aspect,1.0,5000000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//清除顏色緩沖以及深度緩沖
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0f,0.0f,0.0f);//繪圖色
//該函數用於渲染一個球體。球體球心位於原點,參數分別為:
glutSolidSphere(50.0,90.0,90.0);
//半徑,以Z軸上線段為直徑分布的圓周線的條數(將Z軸看成地球的地軸,類似於經線),圍繞在Z軸周圍的線的條數(類似於地球上緯線)
glFlush();
}
void main(void)
{
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE );
glutCreateWindow("球體");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(Display);
Initial();
glutMainLoop();
}
結果是這樣:
希採納