Graphics - Villanova Computer Science

CSC 8470
Computer Graphics
What is Computer Graphics?
For us, it is primarily the study of how
pictures can be generated using a computer.
But it also includes:
–
–
–
–
software tools used to make pictures
hardware for efficient graphics processing
input devices for interacting with these pictures
output devices for displaying the pictures
Graphics Application: Information
Visualization
‰
GOAL:
– Visualization of complex multidimensional data
for analysis and presentation.
‰
Examples:
– Clinical trial data
– Business consultancy data
Graphics application: Direct Volume
Rendering
‰
GOAL:
‰
– Visualization of highly complex data
Texture adds a high visual dimension
Graphics Application: Biomedical
Visualization
‰
GOAL:
– Improve the perception, analysis, understanding
of interactions between complex data
Graphics Application:Virtual Reality
‰
GOAL:
– Design effective simulation and education
applications by combining real and virtual
elements
– Reduce cost & improve safety of applications
Graphics Application: Computer Aided Design
‰
GOAL:
– Develop novel interfaces for the efficient design of
products, scenes and characters. In general focus is
on real-time performance and rapid prototyping,
and/or visual realism.
Graphics Application: Advertisements
Graphics Application: Arts and Publishing
Graphics Application: Everyday Use
Course Goals
Learn the Process of Creating an Image
Learn Animation Basics
Animation Example
Data Crunching behind Avatar
Tools we Will Use
www.opengl.org
www.blender.org
www.povray.org
Main Topics
‰
‰
‰
‰
‰
‰
‰
‰
Basic Graphics Concepts
Graphics System and Architecture
Algorithms for simple graphics
Geometric Objects and Transformations
Viewing and Projection
Shading and Rendering
Texture Mapping
Lighting and Ray Tracing
Resources
‰
Recommended:
‰
Online material
– References on the
class website
Grading
‰
Assignments (60%)
–
–
–
–
‰
‰
‰
‰
Pencil and paper
Clean, readable, working code
On time (no late submission)
First assignment is available now
Exam (30%)
Class Participation (10%)
No makeup assignments or exams
Lecture attendance is mandatory
Any questions before we start?
Graphics Systems Basics
What is a digital image?
Pixel:
Raster image:
Pixel Depth
Pixel depth:
Effect of Pixel Depth
____ bits
Banding:
____ bits
____ bits
Effect of Pixel Depth
2 bits (4 colors)
4 bits (16 colors)
Source: Wikipedia, http://en.wikipedia.org/wiki/Pixel_depth
Raster Displays
Path of electron beam
Display surface: Dotted with material that emits light when
stimulated by electron beam. Beam must repeatedly stimulate
dots row by row, b/c intensity fades when not stimulated.
Refresh rate:
Resolution:
Light
White light:
Raster Displays Revisited
LCD displays
LCD:
Color Models
Additive Color Model:
Subtractive Color Model:
Color Raster Images
Pixel color is encoded
as ordered triple.
Color value
(R,G,B)
Displayed
(0, 0, 0)
Black
(0, 0, 1)
Blue
(0, 1, 0)
Green
(1, 0, 0)
Red
(1, 0, 1)
Magenta
(1, 1, 0)
Yellow
(0, 1, 1)
Cyan
(1, 1, 1)
White
Frame Buffer
‰
Special memory where pixel colors are stored.
System Bus
CPU
Main Memory
Graphics Card
-- Graphics
Processing Unit
(GPU)
-- Frame Buffer
Modeling-Rendering Paradigm
Modeling
Rendering
The Concept of Pipeline
a
b
c
*
+
Graphics Pipeline
Raster
Image
3D Vertices
Vertex
Processor
Clipper
Rasterizer
ALL done by the GPU on the graphics card!
Hands-On Session
Fragment
Processor
‰
‰
‰
A cross-platform Application Programming
Interface (API) for producing 2D and 3D
computer graphics
Developed by Silicon Graphics Inc. (1992)
See: http://www.opengl.org
OpenGL Graphics Programming
‰
OpenGL
– Industry standard API for 3D graphics
– Cross-platform – Windows, MAC, Unix
– Supported on all hardware platforms
‰
OpenGL API (gl)
– core of OpenGL API
‰
OpenGL Utility API (glu)
– additional functionality built on top of GL
‰
OpenGL Utility Toolkit (glut)
– Handles the windowing system, menus, events, etc.
Hands-on Activities
‰
In the future you will write your own OpenGL
program, but this time you’ll copy an existing
program (squares.cpp) from the course website.
‰
Get the activities handout from your instructor.
OpenGL Introduction
‰
‰
‰
OpenGL Geometric Primitives
OpenGL Attributes
Sierpinski’s Triangle
Points, Lines, Polygons
Vertices
‰
A vertex is a location in the plane
– Specified by its x and y coordinates
– Used to define geometric primitives
– The simplest geometric primitive is a point
‰
General form: glVertex*
– Examples:
• glVertex2i(int x, int y);
• glVertex3f(float x, float y, float z);
• glVertex3fv(float vcoord);
glVertex*
OpenGL Primitives
y
glBegin( GL_POINTS );
glVertex2i(100, 100);
glVertex2i(400, 100);
glVertex2i(250, 400);
glEnd();
glBegin( GL_LINE_LOOP );
glVertex2i(100, 100);
glVertex2i(400, 100);
glVertex2i(250, 400);
glEnd(); 500
x
500
y
500
x
500
Many Questions
‰
‰
‰
‰
‰
‰
How to interpret the values of x, y?
In what units are they? Feet, meters or pixels?
Where is the origin?
Where on the screen does our image appear?
How large will the image be?
In what color are we drawing?
Screen (Graphics) vs.
Viewing (Clipping) Window
‰
glutInitWindowSize(600, 500);
‰
glutInitPosition(200, 150);
x
screen win
‰
glOrtho2D(0, 600, 0, 500);
y
y
x
viewing window
OpenGL Attributes
Examples:
glColor3f( 1.0, 0.0, 0.0 );
glClearColor( 1.0, 1.0, 1.0, 1.0 );
glPointSize( 4.0 );
glLineWidth( 2.0 );
Once an attribute is set, it stays that value until
you later change it.
Hands-On Session
‰
‰
The primitives.cpp Program
Compile, Run & Play, eg:
– Change point size to 8
– Change `GL_POINTS’ to:
•
•
•
•
•
•
•
•
•
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP
GL_POLYGON
GL_QUADS
GL_TRIANGLES
GL_QUAD_STRIP
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
The Sierpinski Gasket
Algorithm:
Start with 3 corner vertices v1, v2, v3 and one
interior point p
Repeat the following
Hands-on Session
‰
‰
‰
‰
The gasket.cpp Program
Compile, Run & Play
Change ‘GL_POINTS’ to GL_LINES
Comment out certain lines, e.g.
– glClear(GL_COLOR_BUFFER_BIT);
(and resize your window)
‰
What happens when you resize your window?
Sierpinski Gasket -- Triangle Bisection
Algorithm:
Start with 3 corner vertices v1, v2, v3
Repeat the following
Hands-on Session
‰
‰
Save a copy of your gasket.cpp code
Alter the code for the gasket to generate the
Sierpinski gasket using triangle bisection