Tutorial -2
IS F311
Computer Graphics
Date: 26/08/14
Q1: In DDA algorithm, show how x and y will be incremented for each of these cases?
a)
b)
c)
d)
Slope 0 < m 1.
Slope m > 1.
Slope -1 m < 0.
Slope m < -1.
Q2: Consider the Brenhams line drawing algorithm. Now fill the following table for drawing a line
between (20,10) and (30, 18).
dy = ______; dx = _______; d = _____; incrE = _____; incrNE = ______;
Iteration #
Test
Value of d
Value of x
Value of y
Q3: Consider the code for ellipse drawing. Fill the blanks and show the deduction of the expressions.
Q4: Type in the following openGL Program and run it .
#include
#include
#include
#include
<iostream>
<stdlib.h>
<GL/glut.h>
<time.h>
using namespace std;
void myInit()
{
/* attributes */
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f (1.0, 0.0, 0.0);
/* setting up viewing */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 50.0, 0.0, 50.0);
glMatrixMode(GL_MODELVIEW);
}
void myDisplay()
{
cout<<"Inside myDisplay()"<<endl;
/*triangle*/
GLfloat vertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}};
int i,j,k;
srand(time(NULL)); /*random no. generator*/
/* arbitrary point*/
GLfloat p[2] = {7.5,5.0};
/*clear the window*/
glClear(GL_COLOR_BUFFER_BIT);
/*draw the triangle */
glBegin(GL_LINE_LOOP);
glVertex2f(0.0,0.0);
glVertex2f(25.0,50.0);
glVertex2f(50.0,0.0);
glEnd();
/*compute and output 5000 new points*/
glBegin(GL_POINTS);
for(k=0; k < 5000; k++)
{
j = rand()%3; /*pick a vertex at random*/
p[0] = (p[0] + vertices[j][0])/2.0;
p[1] = (p[1] + vertices[j][1])/2.0;
glVertex2fv(p);
}
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
// initialize the toolkit
// set the display mode
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500); // set window size
// set window upper left corner position on screen
glutInitWindowPosition(300, 300);
// open the screen window (Title: SIERPINSKI Gasket attempt)
glutCreateWindow("SIERPINSKI Gasket attempt");
// register the callback functions
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop(); // go into a perpetual loop
return 0;
}