Wednesday, 19 September 2012

LAB 2A


BIT20203: Graphics Programming

LAB SHEET 2

Title                          : Graphics Programming using OpenGL
Objectives           : At the end of the session, students are able to:
                                          i.         Draw a simple 2D graphics using OpenGL.

Duration               : 2 Hours
Tasks                       :
 

1.     Write the following code. Compile and run.
#include <GL/glut.h>
 
void display(void)
 
{
        /* clear window */
 
         glClear(GL_COLOR_BUFFER_BIT); 
 
        /* draw unit square polygon */
 
        glBegin(GL_POLYGON);
                glVertex2f(-0.5, -0.5);
                glVertex2f(-0.5, 0.5);
                glVertex2f(0.5, 0.5);
                glVertex2f(0.5, -0.5);
        glEnd();
 
        /* flush GL buffers */
 
        glFlush(); 
}
 
void init()
{
 
        /* set clear color to black */
 
        /*      glClearColor (0.0, 0.0, 0.0, 0.0); */
        /* set fill  color to white */
 
        /*      glColor3f(1.0, 1.0, 1.0); */
 
        /* set up standard orthogonal view with clipping */
        /* box as cube of side 2 centered at origin */
        /* This is default view and these statement could be removed */
 
        /* glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);  */
}
 
int main(int argc, char** argv)
{
 
        /* Initialize mode and open a window in upper left corner of screen */
        /* Window title is name of program (arg[0]) */
 
        /* You must call glutInit before any other OpenGL/GLUT calls */
        glutInit(&argc,argv); 
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);  
        glutInitWindowSize(500,500);
        glutInitWindowPosition(0,0); 
        glutCreateWindow("simple"); 
        glutDisplayFunc(display);
        init();
        glutMainLoop();
 
        return 0;
}


2.     Copy the sample code in the Page 80 of your textbook. Compile and run.




~ end ~




2 comments:

  1. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. programming lab

    ReplyDelete
  2. Your website is really cool and this is a great inspiring article. programming lab

    ReplyDelete