#include<GL/glut.h>
#include<stdlib.h>
void init(void)
{
glEnable(GL_DEPTH_TEST);
GLfloat position[]={1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0,GL_POSITION,position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat ambient[]={0.0,0.0,0.0,1.0};
GLfloat diffuse[]={0.95,0.05,0.95,1.0};
GLfloat specular[]={1.0,1.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
glMaterialf(GL_FRONT,GL_SHININESS,50.0);
}
void Display(void)
{
glClearColor(0.75f,0.75f,0.75f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glNewList(1,GL_COMPILE);
//glutSolidTeapot(0.5);//茶壶
//glutSolidSphere(0.75,25,25);//球体
glutWireSphere(0.75,25,25);//线框球体
glEndList();
glCallList(1);
glFlush();
}
void reshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB |GLUT_DEPTH);
glutInitWindowPosition(0,0);
glutInitWindowSize(500,500);
glutCreateWindow("myDEMO");
glutReshapeFunc(reshape);
glutDisplayFunc(Display);//调用绘图函数
init();//初始化函数
glutMainLoop();//进入循环
return 0;
}
第一次OpenGL
最新推荐文章于 2019-07-29 22:01:49 发布