OpenGL【C++】图形学实验一:画球加光照
#include <GL/glut.h>
void OnDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
GLfloat light_position[] = { 0.0, 0.0, 100.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// glColor3f(1.0,0.0,0.0);
// glRectf(0.0f,0.0f,10.0f,10.0f);
glutSolidSphere(50.0, 20, 20);
/* glTranslatef(0.0f,50.0,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glutSolidSphere(10.0f,20,20);
glLoadIdentity();
glTranslatef(50.0f,0.0,0.0);
glColor3f(0.0,0.0,1.0);
glutSolidSphere(10.0,20,20);*/
glFlush();
glutSwapBuffers();
}
void OnReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluOrtho2D(0,100,0,100);
glOrtho(-200, 200, -200, 200, 0.1, 100);
gluLookAt(0.0, 0.0, 100, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(400, 400);
glutCreateWindow("kkk");
glutDisplayFunc(OnDisplay);
glutReshapeFunc(OnReshape);
glutMainLoop();
}