#include<GL/glut.h>
float angle=0.0;
float angle1=0.0;
void init(void)
{
/*float mat_specular[]={1.0,1.0,1.0,1.0};
float mat_shininess[]={50.0};
float light_position[]={10.0,10.0,10.0,0.0};
float white_light[]={10.0,10.0,10.0,1.0};
float lmodel_ambient[]={0.1,0.1,0.1,1.0};*/
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
/*glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT1,GL_POSITION,light_position);
glLightfv(GL_LIGHT1,GL_DIFFUSE,white_light);
glLightfv(GL_LIGHT1,GL_SPECULAR,white_light);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient);*/
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1.0,0.0,1.0);
glTranslated(0.0,0.0,0.0);
glutSolidSphere(2,40,32);
glPopMatrix();
glPushMatrix();
glColor3f(1.0,0.0,0.0);
glRotatef(angle,0.0,1.0,0.0);
glTranslated(5.0,0.0,0.0);
glutSolidSphere(0.5,40,32);
glColor3f(1.0,1.0,0.0);
glRotatef(angle1,0.0,1.0,0.0);
glTranslated(1.0,0.0,0.0);
glutSolidSphere(0.1,40,32);
glPopMatrix();
glutSwapBuffers();
}
void idle()
{
angle+=1;
if(angle>360)
{
angle=0;
}
angle1+=2;
if(angle1>360)
{
angle1=0;
}
display();
Sleep(30);
}
void reshape(int w,int h)
{
glViewport(0,0,(int)w,(int)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float ratio=w/h;
if(w<=h)
glOrtho(-10,10,-10*(float)h/(float)w,10*(float)h/(float)w,-10.0,10.0);
else
glOrtho(-10*(float)w/(float)h,10*(float)w/(float)h,-10,10,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
openGL
最新推荐文章于 2023-06-04 11:14:48 发布