1 figures are extracted from angel's book (isbn 0-201-38597-x) the human visual system vs the...

49
1 Figures are extracted from An gel's book (ISBN 0-201-38597- x) The Human Visual System The Human Visual System vs The Pinhole camera vs The Pinhole camera Human Visual System Visible Spectrum Pinhole camera

Upload: rudolf-russell

Post on 02-Jan-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

1Figures are extracted from Angel's book

(ISBN 0-201-38597-x)

The Human Visual The Human Visual System vs The Pinhole System vs The Pinhole

cameracamera

Human Visual System

Visible Spectrum

Pinhole camera

Page 2: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

2Figures are extracted from Angel's book

(ISBN 0-201-38597-x)

The Synthetic-camera The Synthetic-camera ModelModel

Page 3: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Synthetic CameraSynthetic Cameray

(x,y,z)

X

Z

d

Xp, Yp, -d

Page 4: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Synthetic Camera Synthetic Camera Projection GeometryProjection Geometry

Z

X

Y

COP

d

(0,0,0)

x,y,z

x’ = x (d/z)y’ = y(d/z)z’ = d

(x’,y’,z’)

Projection Plane

Projected Point

Page 5: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Introduction to Introduction to Graphics ProgrammingGraphics Programming

Page 6: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Graphics APIGraphics API

Page 7: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Computer GraphicsComputer GraphicsConceptual ModelConceptual Model

ApplicationModel

ApplicationProgram Graphics

System

OutputDevices

InputDevices

API

Function Callsor Protocol

Data

Page 8: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Components of a Components of a Graphics APIGraphics API

Primitive functionsPrimitive functions What to drawWhat to draw

Attribute functionsAttribute functions How to draw itHow to draw it

Viewing functionsViewing functions (how to look at it) (how to look at it)

Transformation functionsTransformation functions Rotate, scale, translate objects (where, how big?)Rotate, scale, translate objects (where, how big?)

Input functionsInput functions Handle interactivityHandle interactivity

Control functionsControl functions Communicate with window systemCommunicate with window system Initialization, error handlingInitialization, error handling

Page 9: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

API Design API Design ConsiderationsConsiderations

ComplexPrimitives

SimplePrimitives

Stateless(Functional)

ComplexState

Page 10: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

OpenGL and OpenGL and GLUT OverviewGLUT Overview

Page 11: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

What Is OpenGL?What Is OpenGL?

Graphics rendering APIGraphics rendering API high-quality color images composed of high-quality color images composed of

geometric and image primitivesgeometric and image primitives window system independentwindow system independent operating system independentoperating system independent developed by SGIdeveloped by SGI

Page 12: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Major decisionsMajor decisions

Simple primitiveSimple primitive Retained State ApproachRetained State Approach Not interactive with native windowsNot interactive with native windows

Page 13: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Major decisionsMajor decisions

Simple primitiveSimple primitive Retained State ApproachRetained State Approach Not interactive with native windowsNot interactive with native windows

Page 14: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Point and Line Segment Point and Line Segment PrimitivesPrimitives

P0

P1P2

P3

P4

P5P6

P7

P0

P1P2

P3

P4

P5P6

P7

P0

P1P2

P3

P4

P5P6

P7

P0

P1P2

P3

P4

P5P6

P7

GL_POINTS GL_LINES

GL_LINE_STRIP GL_LINE_LOOP

Page 15: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Polygon PrimitivesPolygon Primitives

P0

P1P2

P3

P4

P5P6

P7

P0

P1P2

P3

P4

P5P6

P7

P0

P1P2

P3

P4

P5P6

P7

P0

P1P2

P3

P4

P5P6

P7

GL_POINTS GL_POLYGON

GL_QUADS GL_TRIANGLES

Page 16: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

PolygonsPolygons

Simple: Well defined interior Complex:

1. Closed2. Has an interior

Simple: No pair of edges of a polygon cross each other

OpenGL only supports rendering for simple, convex and flat polygon

Page 17: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Polygons: ConvexityPolygons: Convexity

P1

P2

Convex Non-Convex

Definition extensible to 3D.

Page 18: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

OpenGL Primitive SyntaxOpenGL Primitive Syntax

glBegin ( type );glVertex* ( . . . );

.

.

.

.

glVertex* ( . . . );glEnd ( );

Page 19: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Simple ExampleSimple Example glBegin( GL_QUADS );glBegin( GL_QUADS );

glColor3fv( color );glColor3fv( color ); glVertex2f( 0.0, 0.0 );glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 );glVertex2f( 1.0, 0.0 ); glVertex2f( 1.5, 1.118 );glVertex2f( 1.5, 1.118 ); glVertex2f( 0.5, 1.118 );glVertex2f( 0.5, 1.118 );glEnd();glEnd();

glBegin( GL_QUADS );glBegin( GL_QUADS ); glColor3fv( color );glColor3fv( color ); glVertex2f( 0.0, 0.0 );glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 );glVertex2f( 1.0, 0.0 ); glVertex2f( 1.5, 1.118 );glVertex2f( 1.5, 1.118 ); glVertex2f( 0.5, 1.118 );glVertex2f( 0.5, 1.118 );glEnd();glEnd();

Page 20: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

OpenGL Command OpenGL Command FormatsFormats

glVertex3fv( glVertex3fv( vv ) )

Number ofNumber ofcomponentscomponents

2 - (x,y) 2 - (x,y) 3 - (x,y,z)3 - (x,y,z)4 - (x,y,z,w)4 - (x,y,z,w)

Data TypeData Typeb - byteb - byteub - unsigned byteub - unsigned bytes - shorts - shortus - unsigned shortus - unsigned shorti - inti - intui - unsigned intui - unsigned intf - floatf - floatd - doubled - double

VectorVector

omit “v” foromit “v” forscalar formscalar form

glVertex2f( x, y )glVertex2f( x, y )

Page 21: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Major decisionsMajor decisions

Simple primitiveSimple primitive Retained State ApproachRetained State Approach Not interactive with native windowsNot interactive with native windows

Page 22: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Setting Color Attribute in Setting Color Attribute in OpenGLOpenGL

RGB ModeRGB Modevoid glColor3{b s i d f ub ud ui}(TYPE r,

TYPE g, TYPE b);

glColor3f(0.0, 0.0, 0.0); /*black*/

glColor3f(1.0, 0.0, 0.0); /*red*/

glColor3f(0.0, 1.0, 0.0); /*green*/

glColor3f(0.0, 0.0, 1.0); /*blue*/

glColor3f(1.0, 1.0, 0.0); /*yellow*/

glColor3f(0.0, 1.0, 1.0); /*cyan*/

glColor3f(1.0, 0.0, 1.0); /*magenta*/

glColor3f(1.0, 1.0, 1.0); /*white*/

Page 23: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Other Simple OpenGL Other Simple OpenGL AttributesAttributes

glClearColor(1.0, 1.0, 1.0, glClearColor(1.0, 1.0, 1.0, 0.0);0.0); Sets background color to whiteSets background color to white Fourth argument is transparency; 0.0 is Fourth argument is transparency; 0.0 is

opaqueopaque Sets a state variableSets a state variable

glPointSize(2.0);glPointSize(2.0); Sets point size to be 2 pixels wideSets point size to be 2 pixels wide Note that this is not a device-Note that this is not a device-

independent attributeindependent attribute Sets a state variableSets a state variable

glLinewidth (2.0);glLinewidth (2.0);

Page 24: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Immediate vs. Retained Immediate vs. Retained ModeMode

Display ListsDisplay ListsCreating the Display List:

glNewList(Name, GL_COMPILE);Attribute 1; Primitive 1;Primitive 2;

. . .Primitive n;

glEndList;

Executing the list:

glCallList(Name);

Page 25: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Major decisionsMajor decisions

Simple primitiveSimple primitive Retained State ApproachRetained State Approach Not interact with native windowsNot interact with native windows

Page 26: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

OpenGL Library OpenGL Library FunctionsFunctions

GLU

GL

GLUT

GL library contains all primitive and attribute functionsassociated with OpenGL

GLU library builds on the GL library to include morecomplex primitives (e.g. spheres) and convenience functions

GLUT (GL Utility Toolkit) includes functions to interfacewith the native window system, including window creation,management of input devices

Page 27: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

GL Library Organization GL Library Organization Under Microsoft Under Microsoft

WindowsWindows

OpenGlapplication

program

GLU

GL

GLUT Direct DrawFramebuffer

Page 28: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

GL Library Organization GL Library Organization (under X Windows)(under X Windows)

OpenGLapplication

program

GLU

GL

GLUT

GLX

Xlib, Xtk

Framebuffer

Page 29: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Geometry PipelineGeometry Pipeline

Page 30: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

VerticesVertices

Vertices in world coordinatesVertices in world coordinates void glVertex3f(GLfloat x, void glVertex3f(GLfloat x,

GLfloat y, GLfloat z)GLfloat y, GLfloat z) Vertex (x, y, z) sent down the Vertex (x, y, z) sent down the

pipelinepipeline

Page 31: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

TransformerTransformer

Transformer in world coordinatesTransformer in world coordinates Must be set before object is drawn!Must be set before object is drawn! glRotatef(45.0, 0.0, 0.0, -1.0);glRotatef(45.0, 0.0, 0.0, -1.0); glVertex2f(1.0, 0.0);glVertex2f(1.0, 0.0);

Complex [Angel Ch. 4]Complex [Angel Ch. 4]

Page 32: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Transformation Matrices Transformation Matrices in OpenGLin OpenGL

Stack

Current

Stack

Current

Load Matrix

Vertices

3DModel

Vertices3D

2D

Modelview Projection

Matrix Mode

Page 33: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Setting Viewing Matrix in Setting Viewing Matrix in GL:GL:

A Simple CaseA Simple CaseglMatrixMode(GL_PROJECTION);Sets the switch so that loaded matrix goes into the projection stack.

glLoadIdentity();Pushes an identity matrix onto the stack;

gluOrtho2D(GLdouble left, Gldouble right, Gldouble bottom, Gldouble top);Sets the current view to an orthographic projection with viewvolume bounded by x = left, x = right, y = bottom, y = top,z = -1.0 and z = 1.0.

Page 34: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

ClipperClipper

Page 35: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Viewport TransformationViewport TransformationMyWindow

x

y

h

w

void glViewport(Glint x, GLint y, GLsizei w, Glsizei h);

Default viewport corresponds to entire window drawable area.

ClippingWindow

Page 36: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

ProjectorProjector

Page 37: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Orthographic ProjectionOrthographic Projection

If d = z - and d

x’ = xy’ = y z = d

x’ = x (d/z)y’ = y(d/z)z’ = d

Page 38: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

RasterizerRasterizer

Page 39: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Simple GLUT Window Simple GLUT Window Management FunctionsManagement FunctionsglutInit(int *argc, char** argv);Initializes a window session.

glutCreateWindow(char *name);Creates a window with title *name.

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);Sets the display mode to single buffered and RGB color.

glutInitWindowSize (GLsizei h, GLsizei w);Sets initial window size to h x w.

glutInitWindowPosition(x,y);Sets initial window position to (x, y).

Page 40: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Form of SimplestForm of Simplestglut/OpenGL programglut/OpenGL program

#include <glut.h>

/* glut.h includes gl.h and glu.h */

void init (void)

{

/* Usually contains setting of the viewing transformation*/

}

void display (void)

{

/*This function contains all of the draw/redraw commands

}

Page 41: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Form of SimplestForm of Simplestglut/OpenGL program glut/OpenGL program

(slide 2)(slide 2)void reshape (int w, int h)

{

/* What to do whenever the window is resized. Usually includes resetting the viewport */

}

int main (int argc, char ** argv)

{glutInit(int *argc, char** argv); /* init glut */

glutCreate Window(char *name); /* create window */

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize (GLsizei h, GLsizei w);glutInitWindowPosition(x,y);

init ();

glutDisplayFunc(display); /* register display */

glutReshapeFunc(reshape); /* register reshape */

glutMainLoop(); /* enter event loop */

return 0;

}

Page 42: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

GLUT Callback FunctionsGLUT Callback Functions

Routine to call when something happens window resize or redraw user input animation

“Register” callbacks with GLUTglutDisplayFunc( display );glutIdleFunc( idle );glutKeyboardFunc( keyboard );

Page 43: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Rendering CallbackRendering Callback

Do all of your drawing hereDo all of your drawing hereglutDisplayFunc( display );glutDisplayFunc( display );

void display( void )void display( void ){{ glClear( GL_COLOR_BUFFER_BIT );glClear( GL_COLOR_BUFFER_BIT ); glBegin( GL_QUADS );glBegin( GL_QUADS ); glVertex3fv( v[0] );glVertex3fv( v[0] ); glVertex3fv( v[1] );glVertex3fv( v[1] ); glVertex3fv( v[2] );glVertex3fv( v[2] ); glVertex3fv( v[3] );glVertex3fv( v[3] ); glEnd();glEnd(); glFlush ();glFlush (); }}

Page 44: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Idle CallbacksIdle Callbacks

Use for animation and continuous update

glutIdleFunc( idle );

void idle( void ){ t += dt; glutPostRedisplay();}

Page 45: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Simple hello worldSimple hello world

Page 46: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Simple hello worldSimple hello world

Include Files:Include Files:

#include <windows.h>#include <windows.h>#include <glut.h>#include <glut.h>

Page 47: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Simple hello worldSimple hello world

void init (void)void init (void){{/* select clearing color *//* select clearing color */ glClearColor (0.0, 0.0, 0.0, 0.0);glClearColor (0.0, 0.0, 0.0, 0.0);

/* initialize viewing values *//* initialize viewing values */ glMatrixMode(GL_PROJECTION);glMatrixMode(GL_PROJECTION); glLoadIdentity();glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);}}

Page 48: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Simple hello worldSimple hello worldvoid display(void)void display(void){{/* clear all pixels *//* clear all pixels */ glClear (GL_COLOR_BUFFER_BIT);glClear (GL_COLOR_BUFFER_BIT);

/* draw colored polygon (rectangle) with corners at/* draw colored polygon (rectangle) with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) ….* (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) …. */*/ glColor3f (1.0, 0.0, 0.0); //redglColor3f (1.0, 0.0, 0.0); //red glBegin(GL_QUADS);glBegin(GL_QUADS); glVertex3f (0.25, 0.25, 0.0);glVertex3f (0.25, 0.25, 0.0); glVertex3f (0.75, 0.25, 0.0);glVertex3f (0.75, 0.25, 0.0); glColor3f (0.0, 0.0, 1.0); //blueglColor3f (0.0, 0.0, 1.0); //blue glVertex3f (0.75, 0.75, 0.0);glVertex3f (0.75, 0.75, 0.0); glVertex3f (0.25, 0.75, 0.0);glVertex3f (0.25, 0.75, 0.0); glEnd();glEnd(); glutSolidSphere(0.15,12,2); //draw a sphereglutSolidSphere(0.15,12,2); //draw a sphere glFlush ();glFlush ();}}

Page 49: 1 Figures are extracted from Angel's book (ISBN 0-201-38597-x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole

Simple hello worldSimple hello worldint main(int argc, char** argv)int main(int argc, char** argv){{ glutInit(&argc, argv);glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250);glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100);glutInitWindowPosition (100, 100); glutCreateWindow ("hello");glutCreateWindow ("hello"); init ();init (); glutDisplayFunc(display);glutDisplayFunc(display); glutMainLoop();glutMainLoop(); return 0; /* ANSI C requires main to return int. */return 0; /* ANSI C requires main to return int. */}}