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.
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 ratings0% 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.
//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
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
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)