loading...

CS602 Computer Graphics Assignment 4 Solution Spring 2014

Q1. Write a program in C/C++ to draw a house on the screen using Opengl library. Follow the instructions given below.                                                                                                                                          10 Marks

  1. 1.       Declare a BuildHouse(void) function.
  2. 2.       In this function call 5 independent glBegin(GL_POLYGON) functions of glut utility to draw each object like: to start house, to start 1st window, to start 2nd window, to start ceiling and to start door.
  3. 3.       Use glColor3f( ,  , ); function to set color of each object.
  4. 4.       Use glVertex2i( , ); function to draw vertices of each object.
  5. 5.       Window position should be (50, 100).
  6. 6.       Window size should be (500, 500).


void init(void)
{
glClearColor(0.0, 0.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void buildHouse(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);

glBegin(GL_POLYGON); //start house
glColor3f(1.0, 1.0, 0.0);
glVertex2i(50, 0);
glColor3f(0.0, 1.0, 0.0);
glVertex2i(50, 100);
glColor3f(0.0, 1.0, 1.0);
glVertex2i(150, 100);
glColor3f(1.0, 1.0, 0.0);
glVertex2i(150,0);
glEnd(); //end house

glBegin(GL_POLYGON); //start window
glColor3f(0.3, 0.2, 0.0);
glVertex2i(60, 80);
glVertex2i(80, 80);
glVertex2i(80, 65);
glVertex2i(60, 65);
glEnd(); //end window

glBegin(GL_POLYGON); //start window
glColor3f(0.3, 0.2, 0.0);
glVertex2i(120, 80);
glVertex2i(140, 80);
glVertex2i(140, 65);
glVertex2i(120, 65);
glEnd(); //end window

glBegin(GL_POLYGON); //start ceiling
glColor3f(0.8, 0.0, 0.0);
glVertex2i(50, 100);
glColor3f(0.5, 0.0, 0.3);
glVertex2i(150, 100);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(100, 130);
glEnd(); //end ceiling
glBegin(GL_POLYGON); //start door
glColor3f(0.3, 0.2, 0.0);
glVertex2i(80, 0);
glVertex2i(80, 50);
glVertex2i(120, 50);
glVertex2i(120,0);
glEnd(); //end door
glFlush();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(50, 100);
glutInitWindowSize(500, 500);
glutCreateWindow(“House Section OpenGL”);
init();
glutDisplayFunc(buildHouse);
glutMainLoop();
}

Q2. What are NURBS (Non Uniform Rational B-Splines). What is the use of NURBS in computer graphics?

NURBS are industry standard tools for the representation and design of geometry. Some reasons for the use of NURBS are, that they:

  • offer one common mathematical form for both, standard analytical shapes (e.g. conics) and free form shapes;
  • provide the flexibility to design a large variety of shapes;
  • can be evaluated reasonably fast by numerically stable and accurate algorithms;
  • are invariant under affine as well as perspective transformations
  • are generalizations of non-rational B-splines and non-rational and rational Bezier curves and surfaces.

DOWNLOAD SOLUTION HERE
loading...