Tuesday, 27 August 2013

opngl program to disppaly polygons

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

const int screenWidth=640;
const int screenHeight=480;


void myInit()
{
     glClearColor(1.0,1.0,1.0,0.0);
     glColor3f(1.0,0.0,0.0);
     glPointSize(3.0);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
      glViewport(0,10,0,10);
     gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
    
    
     }
    
     void myDisplay()
     {
         
          glClear(GL_COLOR_BUFFER_BIT);
         
          /*glBegin(GL_TRIANGLES);
          glVertex2i(0,0);
          glVertex2i(70,50);
          glVertex2i(50,0);
          glEnd();*/
         
         
         
/*          glBegin(GL_QUADS);
           glVertex2i(80,0);
           glVertex2i(220,50);
            glVertex2i(120,50);
             glVertex2i(110,0);
             glEnd();*/
            
            
            
             glBegin(GL_QUAD_STRIP);
              glVertex2i(50,100);
              glVertex2i(100,150);
              glVertex2i(150,200);
              glVertex2i(200,150);
             // glVertex2i(250,200);
             // glVertex2i(300,200);
              //glVertex2i(400,400);
             // glVertex2i(410,400);
              glEnd();
            
          glFlush();
          }
    

    
     int main(int argc, char **argv)
     {
         glutInit(&argc,argv);
         glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
         glutInitWindowSize(640,480);
         glutCreateWindow("sinc function = sin(PI*X)/PI*X");
         glutDisplayFunc(myDisplay);
      
         myInit();
        
         glutMainLoop();
         }

No comments:

Post a Comment