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();
}
原文地址:https://blog.csdn.net/hgaohr1021/article/details/143714586
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!