Wednesday, 18 September 2013

3D OPENGL PROGRAM

#include<GL/glut.h>
#include<stdlib.h>

const int screenWidth=640;
const int screenHeight=480;
int x=0,y=0;


void
mykeyboard(unsigned char thekey ,int mx,int my)
{
          switch(thekey)
          {
                        case 'w':
                             y+=1;
                             break;
                             case 's':
                                  y-=1;
                                  break;
                                  case 'a':
                                       x-=1;
                                       break;
                                       case 'd':
                                            x+=1;
                                            break;
                                            case 'q':
                                                 x=0,y=0;
                                                 break;
                                           
                                            default:
                                                    break;
                                                    }
         
         gluLookAt(0,0,2.0,x,y,0.0,0.0,1.0,0.0);
         glutPostRedisplay();
      }

         

void myInit()
{
     glClearColor(0.0,0.0,0.0,0.0);
    
    
           glColor3f(0.0,1.0,0.0);
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
          glOrtho(-100,100,-100,100,0.1,100);
          glMatrixMode(GL_MODELVIEW);
          glLoadIdentity();

     }
    
    
     void myDisplay()
     {

          glClear(GL_COLOR_BUFFER_BIT);
          //glutWireCube(25.0);
          //glutWireSphere(20,15,15);
          glutWireTeapot(20);
          glFlush();
          }
         
          int main(int argc,char **argv)
          {
              glutInit(&argc,argv);
              glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
              glutInitWindowSize(screenWidth,screenHeight);
              glutCreateWindow("lines");
              glutDisplayFunc(myDisplay);
              glutKeyboardFunc(mykeyboard);
              myInit();
             
              glutMainLoop();
              }
             

No comments:

Post a Comment