‘壹’ 用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();
}
结果是这样:
希采纳