You are on page 1of 13

Lab Assignment

COMPUTER GRAPHICS

1. What command could we use to set the color of an OpenGL display window to dark gray?
What command would we use to set the color of the display window to white?

Ans. The command we use to set the color of an OpenGL display window to dark gray is

glClearColor (0.30, 0.30, 0.30, 1.0);

The command we use to set the color of an OpenGL display window to white is

glClearColor(1.0, 1.0, 1.0, 1.0);

2. List the statements needed to set up an OpenGL display window whose lower-left corner is at pixel
position (75, 200) and has a window width of 200 pixels and a height of 150 pixels.

#include "stdafx.h"
#include<glut.h>
void myInit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 20.0, 0.0, 20.0);
}
void myDisplay()
{

}
void Main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(75, 200);
glutInitWindowPosition(200, 150);
glutCreateWindow("FA19-MCS-038");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}

3. Create a program in OpenGL that generates following output on graphics window.

#include "stdafx.h"
#include<glut.h>
void myInit()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0,480.0);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glVertex2i(100,50);
glVertex2i(100,130);
glVertex2i(150, 130);
glEnd();
glFlush();
}
void main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow("FA19-MCS-038");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
4. Create a program that shows the pattern of eight dots representing the big dipper as shown below.
#include "stdafx.h"
#include<glut.h>
void myInit()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glVertex2i(289, 190); // draw eight points
glVertex2i(320, 128);
glVertex2i(239, 67);
glVertex2i(194, 101);
glVertex2i(129, 83);
glVertex2i(75, 73);
glVertex2i(74, 74);
glVertex2i(20, 10);
glEnd();
glFlush();
}

void main(int argc, char**argv)


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow("FA19-MCS-038");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}

5. Draw the house given below using OpenGL primitives.

[Hint: Use GL_LINE_LOOP primitive to draw shell of house, GL_LINE_STRIP to draw the chimney]

#include "stdafx.h"
#include<glut.h>
void myInit()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 480.0, 0.0, 480.0);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
glVertex2i(40, 40);
glVertex2i(40, 90);
glVertex2i(70, 120);
glVertex2i(100, 90);
glVertex2i(100, 40);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2i(50, 100);
glVertex2i(50, 120);
glVertex2i(60, 120);
glVertex2i(60, 110);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(50, 40);
glVertex2i(50, 75);
glVertex2i(65, 75);
glVertex2i(65, 40);
glVertex2i(50, 40);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(80, 70);
glVertex2i(80, 80);
glVertex2i(90, 80);
glVertex2i(90, 70);
glVertex2i(80, 70);
glEnd();
glFlush();

void main(int argc, char**argv)


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow("FA19-MCS-038");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}

You might also like