Week01 (Introduction Primitives)
Week01 (Introduction Primitives)
1
Objectives
• To understand the basic objectives and scope of
computer graphics
• To identify computer graphics applications
• To understand the basic structures of 2D and 3D
graphics systems
• To understand evolution of graphics programming
environments
• To identify common graphics APIs
• To understand the roles of Java language, Java 2D and
Java 3D packages
• To identify computer graphics related fields 2
Computer graphics
• Computer graphics provides methods to generate
images using a computer.
• An image can represent a realistic scene from the
real world, but graphics like histograms or pie
charts as well as the graphical user interface of a
software tool are also considered as images.
3
Computer graphics- Application fields
• Graphical user interfaces
• Visualising high-dimensional data
• Generation of realistic images and sequences of images
• Designing, modelling and visualising objects
• The combination of real data and images with techniques from computer
graphics will probably gain more importance than it has today.
• Computer
games
• Advertising
• Virtual reality
4
From areal scene to an image
5
From areal scene to an image
• a. The objects in the scene have to be modelled with
the techniques and methods provided by a computer
graphics tool.
• b. Approximation by assuming that the computer
graphics tool is very restricted and the bowl in the
real scene can only be approximated by a semisphere.
• c. Projection from 2D to 3D
• d. Clipping, The whole process of generating a pixel
image from a three-dimensional
virtual scene is called rendering.
6
Computer Graphics
Main tasks of computer graphics: modeling a virtual
world and rendering a scene
Modeling: Creating a virtual world.
Rendering: Generating a visual image of a scene.
Rendering
7
Image of a scene
Virtual world model
Modeling- polygon shapes
8
Modeling- polygon shapes
Many shapes can be stored as
a list of polygons in terms of
vertex list.
9
Modeling- polygon shapes
failure
10
Modeling- polygon shapes
level of detail
11
Modeling- polygon shapes
level of details
12
Graphics System:
Components and Functions
• Modeler • Geometry
• Renderer • Transformation
• Hardware device • Illumination
• Virtual World • Interaction
• View • Animation
13
Computer Graphics
- Graphics objects to be modeled are in either a 2D or a
3D space.
- This common space to host all the graphic objects is
often called the world space
- The graphics objects to be modeled in a world space
are usually geometric entities such as lines and
surfaces, but they also include other special objects
such as lights, texts and images
- The graphics objects may possess many characteristics
14
and properties such as color, transparency and texture
Graphics System:
Components and Functions
• Modeler is responsible for the construction of
virtual world models
• Renderer perform the rendering of the scene
• Object transformations are geometric
transformations applied to the objects to achieve
the proper placement of the objects in the virtual
space
• GUI is based on the user interactions with graphic
systems.
15
Computer Graphics: Geometric
transformations
21
Operating System Level
Program through OS graphics support
Do not directly manipulate graphics hardware
Portable on the same platform
Graphics APIs (application programming interfaces)
provided at the operating system level offer a uniform
interface for graphics programming within the same
platform
Example: WIN32 is the API for 32 bit windows operating
systems
22
Operating System Level
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);
cx = (rc.left + rc.right)/2;
cy = (rc.top + rc.bottom)/2;
if (rc.bottom - rc.top < rc.right - rc.left)
r = (rc.bottom - rc.top) / 2 - 20;
else
r = (rc.right - rc.left) / 2 - 20;
Ellipse(hdc, cx-r, cy-r, cx+r, cy+r);
EndPaint (hwnd, &ps);
Problem: Graphics programs that rely on operating system are not portable across
different platforms
➢ example: In Windows and Mac OS, APIs are different
23
GKS and PHIGS
Graphics programming will provide a layer of abstraction necessary for device and
platform independence
Graphics Kernel System GKS
26
Java
An overview of the Java language and it graphics facilities
Graphics application
Java APIs Java 3D
Java VM OpenGL
OS
Display driver
Graphics card
Display
27
Java Programming Languages
• Simple
• Object Oriented (OOP)
• Write once, run anywhere
• Multithreaded
• Java contains two nearly parallel sets of facilities for GUI programing
• AWT(Abstract Window Toolkit) offers capabilities to control certain rendering
attributes such as drawing color and to draw some graphics primitives such as
lines, rectangles and ovals. However, these features are limited.
• Swing is a completely redesigned GUI programming API included in the Java 2
platform
28
JOGL
• One graphics programming for Java is OpenGL
• OpenGL Java language binding
• The two componenets GLCanvas and GLJpanel provide the
drawing surfaces for the openGL calls
• A typical procedure for programming JOGL is outlined below
1. Create a GLCanvas or GLJPanel object through the
GLDrawableFactory class.
2. Add a GLEvent listener to the canvas object.
3. Implement the listener by implementing the four methods: init,
display, reshape, and displayChanged.
29
Minimum Java graphics app.
package javaapplication1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
import java.util.Random;
import javax.imageio.*;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
30
public class JavaApplication1 extends JApplet{
public static void main(String[] args) {
// TODO code application logic here
JFrame frame=new JFrame();
frame.setTitle("hello");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JApplet applete =new JavaApplication1();
applete.init();
frame.getContentPane().add(applete);
frame.pack();
frame.setVisible(true);
}
public void init(){
JPanel panel=new JApp1Panel();
getContentPane().add(panel);
}}
31
class JApp1Panel extends JPanel{
public JApp1Panel(){
setPreferredSize(new Dimension(640,480));
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2=(Graphics2D) g;
SimpleClip(g2);
}
32
Java 2D
• Standard package of Java 2 platform
• Improvements over AWT
• Graphics2D class
• Java 2D provides a rather complete set of functionalities to
manipulate and render 2D graphics
• The enhancements include
• A separate class hierarchy for geometric objects is defined
in Java 2D
• The rendering process much more refined
• Completely new image processing features are introduced
• Color models, fonts, printing, and other related supports
are also greatly improved
33
• The Graphics2D class, a subclass of the Graphics class, is the
rendering for java 2D
Java 3D
• 3D graphics includes advanced features as animation, 3d
interactions and sophisticated viewing
•High-level API
• Scene graph contains the complete information of the virtual
graphics world
•The visual effects of the program are achieved by creating a
scene graph and placing the appropriate graphics elements into
it
•The scene graph for the program is a treelike structure
containing objects such as the sphere, the 3D text, appearance,
transforms, background, lights, and so on
•The rendering of the scene is done automatically by the java 3D
engine 34
• Modeler/Renderer
• Java Integration
Other Fields Related to Graphics
• Image processing
• Computer vision
• Mathematics
• Analytic geometry
• Linear algebra
35