#include<GL/glut.h>
int x=0,y=0,z=0;
float radius=7.0;
float u=0.0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// glColor3f(1.0,0.0,1.0);
glutSolidSphere(1.0,30,30);
GLfloat direction[]={1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0,GL_POSITION,direction);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
x=radius* cos(u);
y=0;
z=radius* sin(u);
gluLookAt(x,y,z,0,0,0,0,1,0);
glFlush();
glutSwapBuffers();
}
/*
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat direction[] = {-1.0, -1.0, -1.0, 0.0};
glLightfv(GL_LIGHT0, GL_POSITION, direction);
glutSolidSphere(1.0, 25, 25);
glMatrixMode(GL_MODELVIEW);
// glPushMatrix();
glLoadIdentity();
x = radius * cos(u);
y = 0;
z = radius * sin(u);
gluLookAt(x, y, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
//glPopMatrix();
glFlush();
glutSwapBuffers();
}
*/
void init(void)
{
GLfloat yellow[]={1.0,1.0,0.0};
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluOrtho2D(0.0,640.0,0.0,480.0);
glLightfv(GL_LIGHT0,GL_DIFFUSE,yellow);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}
void timer(int v)
{
u=u+0.1;
glutPostRedisplay();
glutTimerFunc(1000/60,timer,v);
}
void reshape(GLint w,GLint h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40,((GLfloat)w/(GLfloat)(h)),1,10.0);
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Going for a SMILEY :-)");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutTimerFunc(100,timer,0);
init();
glutMainLoop();
}
No comments:
Post a Comment