孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

#define GLUT_DISABLE_ATEXIT_HACK
#include <Windows.h>
#include <math.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <gl/GLAux.h>

void init();
void CALLBACK reshape(GLsizei w,GLsizei h);
void CALLBACK display();
GLfloat s,h;

void CALLBACK display()
{
 glClearColor(1,1,1,1);
 glClear(GL_COLOR_BUFFER_BIT);
 glLoadIdentity();
 gluLookAt(5,5,h,s,0,0,0,1,0);
 glColor3f(0,0,0);
 GLfloat RAD=0.07145;
 GLfloat x,y,z,r;
 int i,j;
 for (i=0;i<180;i+=5)
 {
  glBegin(GL_LINE_LOOP);
  r=2*sin(i*RAD);
  z=2*cos(i*RAD);
  for (j=0;j<360;j+=10)
  {
   x=r*cos(j*RAD);
   y=r*sin(j*RAD);
   glVertex3f(x,y,z);
  }
  glEnd();
 }
 for (j=0;j<360;j+=10)
 {
  glBegin(GL_LINE_LOOP);
    for (i=0;j<=180;i+=10)
    {
     r=2*sin(i*RAD);
     z=2*cos(i*RAD);
     x=2*cos(i*RAD);
     y=2*sin(i*RAD);
     glVertex3f(x,y,z);
    }
       glEnd();
 }
 glFlush();
}

void init()
{
 glShadeModel(GL_FLAT);
 s=0;
 h=5;
}

void CALLBACK reshape(GLsizei w,GLsizei h)
{
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(30,1,-3,3);
 glMatrixMode(GL_MODELVIEW);
 glViewport(0,0,w,h);
}

void CALLBACK Left()
{
 s+=0.1;
}

void CALLBACK Right()
{
 s-=0.1;
}

void CALLBACK Up()
{
 h-=0.1;
}

void CALLBACK Down()
{
 h+=0.1;
}

void main()
{
 auxInitDisplayMode(AUX_SINGLE|AUX_RGB);
 auxInitPosition(0,0,300,300);
 auxInitWindow(TEXT("OpenGL Demo"));
 init();
 auxKeyFunc(AUX_LEFT,Left);
 auxKeyFunc(AUX_RIGHT,Right);
 auxKeyFunc(AUX_UP,Up);
 auxKeyFunc(AUX_DOWN,Down);
 auxReshapeFunc(reshape);
 auxMainLoop(display);
}

posted on 2011-03-05 17:55  孤独的猫  阅读(398)  评论(0编辑  收藏  举报