WAP to draw a 3D Sphere

 #include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>

static GLfloat rotAngle = 0.0;
static GLfloat rotAngle1 = 0.0;

void display() {
  glClear(GL_COLOR_BUFFER_BIT);


  glPushMatrix();
  glRotatef(rotAngle, 0.0, 1.0, 0.0);

  glutWireSphere(2,50,50);

  glPopMatrix();



  glFlush();
  glutSwapBuffers();
  glutPostRedisplay();
}

void init() {


  glClearColor(0.5, 0.55, .13, 1.0);
  glColor3f(1.0, 0.0, 0.0);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(80.0, 4.0/3.0, 1, 10);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
 gluLookAt(0, 4, 0, 0, 0, 0, 0, 0, 1);
}


void keyboard(unsigned char k, int x, int y)
{
    switch (k)
    {
    case 'a':
    {
    rotAngle += 1;
    rotAngle1 -= 1;
    }
    break;
    case 'l':
    {
    rotAngle -= 1;
    rotAngle1 += 1;
    }
    break;
    case 'q':
    exit(0);
    }

    glutPostRedisplay();
}


int main(int argc, char** argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  glutInitWindowPosition(10, 50);
  glutInitWindowSize(800,600);
  glutCreateWindow("Square");
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
 init();
  glutMainLoop();
}

Popular posts from this blog

Shutdown Pc

Ellipse using OpenGl

String Comparisons