0% found this document useful (0 votes)
109 views21 pages

Lab 05 Chap 03

This document outlines the objectives and tasks for an OpenGL lab, including: 1) Drawing polylines from files 2) Using turtle graphics to draw shapes 3) Setting the viewport 4) Using world window transformations for zooming and panning 5) Plotting parametric equations It also lists several case studies and exercises for students to work on related to computer graphics concepts.

Uploaded by

Muzammil Rahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views21 pages

Lab 05 Chap 03

This document outlines the objectives and tasks for an OpenGL lab, including: 1) Drawing polylines from files 2) Using turtle graphics to draw shapes 3) Setting the viewport 4) Using world window transformations for zooming and panning 5) Plotting parametric equations It also lists several case studies and exercises for students to work on related to computer graphics concepts.

Uploaded by

Muzammil Rahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Open GL Lab 05

BSCS – 514 Computer Graphics


Instructor Humera Tariq 1
Lab Objectives /Tasks

1. Drawing polylines from a file


2. Turtle Graphics
3. Using Viewport
4. Using WW for ZoomIn Zoom out
5. Plotting Parametric Eqn

BSCS – 514 Computer Graphics 2


Instructor Humera Tariq
BSCS – 514 Computer Graphics 3
Instructor Humera Tariq
Download Code Dino PolyLines

BSCS – 514 Computer Graphics 4


Instructor Humera Tariq
1. Drawing polylines from a file

1(a) Add given dino.cpp and dino.dat file into your project and
run the code.

1(b) Uncomment //drawPolyLineFile("birdhead.dat");&


//drawPolyLineFile("house.dat"); one by one to
see the following outputs:

BSCS – 514 Computer Graphics 5


Instructor Humera Tariq
No output seen Why??

BSCS – 514 Computer Graphics 6


Instructor Humera Tariq
Thinking about Solution

BSCS – 514 Computer Graphics 7


Instructor Humera Tariq
Thinking about Solution

BSCS – 514 Computer Graphics 8


Instructor Humera Tariq
3. Try the given code to Set Viewport

for(int i = 0; i < 5; i++) // for each column for(int i = 0; i < 5; i++)


for(int j = 0; j < 5; j++) // for each row for(int j = 0; j < 5; j++)
{ {
// set the next viewport if((i + j) % 2 == 0) // if (i + j) is even
glViewport(i * 64, j * 44, 64, 44); gluOrtho2D(0.0, 640.0, 0.0, 480.0); // right side up window
// draw it again
drawPolyLineFile("dino.dat"); else
} gluOrtho2D(0.0, 640.0, 480.0, 0.0); // upside down window

glViewport(i * 64, j * 44, 64, 44); // set the next viewport


drawPolyLineFile("dino.dat"); // draw it again
}

BSCS – 514 Computer Graphics 9


Instructor Humera Tariq
Be Careful in screen Management when:

1. You have Buttons to click

2. Reshape Handler is needed glutReshapeFunc()

3. Creating Different views of Same Object

4. Showing a part of World onto a portion of screen

BSCS – 514 Computer Graphics 10


Instructor Humera Tariq
BSCS – 514 Computer Graphics 11
Instructor Humera Tariq
2. Download Turtle.h and Canvas.h

BSCS – 514 Computer Graphics 12


Instructor Humera Tariq
2. Turtle Graphics
• 2(a) Add turtle.h file into your project.
• 2(b) Make Turtle class object in main file as follows:
Turtle ninja(Point2(0,0),90);
• 2(c ) Add following function into your main file and call it
from display function:

2(d) Wrap above code in a loop to get given output.

BSCS – 514 Computer Graphics 13


Instructor Humera Tariq
2. Turtle Graphics continued (1)
• Try following code to get given output:

BSCS – 514 Computer Graphics 14


Instructor Humera Tariq
2. Turtle Graphics continued (2)
To draw a regular polygon you need to implement eqn on LHS. We
already use it in circle function.

With the help of Turtle graphics this is only a matter of


two lines as shown on RHS:

BSCS – 514 Computer Graphics 15


Instructor Humera Tariq
4. Using WW for zoom & moving bg
• Declare following variable for moving frame and zooming
– float WL = -1.0,WR = 1.0,WB =-1.0,WT = 1.0;
– float zoomFactor = 1.0;
• Add and check following Keyboard interaction

Add following in display()

BSCS – 514 Computer Graphics 16


Instructor Humera Tariq
BSCS – 514 Computer Graphics 17
Instructor Humera Tariq
5. Plotting Parametric Eqns

BSCS – 514 Computer Graphics 18


Instructor Humera Tariq
Follow given steps to plot parametric
eqns.

BSCS – 514 Computer Graphics 19


Instructor Humera Tariq
Case Studies to Work on:
1. Case Study 2.2 Introduction to IFS
2. Case Study 2.3 The Golden Ratio and Other Jewels
3. Case Study 2.6 PolyLine Editor
4. Case Study 2.7 Building and Running Mazes
5. Case Study 3.1 Logistic Map (Related to case study 2.2)
6. Case Study 3.4 Drawing Arches
7. Case Study 3.6 Tiling
8. Case Study 3.7 PlayFul Variations on a Theme
9. Case Study 3.8 Circles Rolling Around Circles

BSCS – 514 Computer Graphics 20


Instructor Humera Tariq
Exercise to solve and work on:
• Practice Exercise 3.2.1 (WW to VP mapping)

• Examples 3.2.7 , 3.2.8(Aspect Ratio problems)

• Practice Exercise 3.2.3 till 3.2.7 (Point Storage & VP problems)

• Example 3.6.2 , 3.6.3 (Rosette and n-gons)


• Practice Exercise 3.6.8 and 3.6.14 (stars and Pentagram Animation)

• Practice Exercises 3.7.7 ,3.7.8,3.7.9 (teardrop and piecharts)

BSCS – 514 Computer Graphics 21


Instructor Humera Tariq

You might also like