Top Banner
Graphics System Rendering pipeline Logical Devices Recap Computer Graphics Lecture 2 Dr. Marc Eduard Frˆ ıncu West University of Timisoara Mar 3, 2020 1 / 19
34

Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Jun 18, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Computer GraphicsLecture 2

Dr. Marc Eduard Fr̂ıncuWest University of Timisoara

Mar 3, 2020

1 / 19

Page 2: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Outline

1 Graphics SystemGraphics DevicesFrame Buffer

2 Rendering pipeline

3 Logical Devices

4 Recap

2 / 19

Page 3: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Graphics System

Basic Graphic System

– set of equipment ⊕ programs specialized in visual representation of the information

Figure: Angel: Interactive Computer Graphics 4E c©Addison-Wesley 2005

3 / 19

Page 4: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Graphics Devices

Graphics Devices (GD)

GD: equipment (hardware) required in order to interact with ⊕ create graphics

Sutherland (MIT ’63) established the basic interactive human-computer paradigm:

1 user “sees” object on the display

2 user “points” to the object by using an input device

3 object reacts

4 repeat from 1

Types

physical devices:

Raster video display: CRT, LCD, Plasma, LED, video projector, . . .Hard-copy devices: printers (Ink-ket, laser), film recorder, pen plotter, . . .Input devices: light pen, keyboard, mouse, joystick, scanner, touch screen, tablet,eye-tracker, gloves, electro-magnetic, VR display, . . .

logical devices: Graphics APIs, e.g., OpenGL, WebGL, DirectX/XNA, JavaScriptbased (Three.js, Box2D), X3D, . . .

The separation of physical & logical devices allows for more flexible programs,independent from the actual physical device

4 / 19

Page 5: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Graphics Devices

Graphics Devices (GD)

GD: equipment (hardware) required in order to interact with ⊕ create graphics

Sutherland (MIT ’63) established the basic interactive human-computer paradigm:

1 user “sees” object on the display

2 user “points” to the object by using an input device

3 object reacts

4 repeat from 1

Types

physical devices:Raster video display: CRT, LCD, Plasma, LED, video projector, . . .

Hard-copy devices: printers (Ink-ket, laser), film recorder, pen plotter, . . .Input devices: light pen, keyboard, mouse, joystick, scanner, touch screen, tablet,eye-tracker, gloves, electro-magnetic, VR display, . . .

logical devices: Graphics APIs, e.g., OpenGL, WebGL, DirectX/XNA, JavaScriptbased (Three.js, Box2D), X3D, . . .

The separation of physical & logical devices allows for more flexible programs,independent from the actual physical device

4 / 19

Page 6: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Graphics Devices

Graphics Devices (GD)

GD: equipment (hardware) required in order to interact with ⊕ create graphics

Sutherland (MIT ’63) established the basic interactive human-computer paradigm:

1 user “sees” object on the display

2 user “points” to the object by using an input device

3 object reacts

4 repeat from 1

Types

physical devices:Raster video display: CRT, LCD, Plasma, LED, video projector, . . .Hard-copy devices: printers (Ink-ket, laser), film recorder, pen plotter, . . .

Input devices: light pen, keyboard, mouse, joystick, scanner, touch screen, tablet,eye-tracker, gloves, electro-magnetic, VR display, . . .

logical devices: Graphics APIs, e.g., OpenGL, WebGL, DirectX/XNA, JavaScriptbased (Three.js, Box2D), X3D, . . .

The separation of physical & logical devices allows for more flexible programs,independent from the actual physical device

4 / 19

Page 7: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Graphics Devices

Graphics Devices (GD)

GD: equipment (hardware) required in order to interact with ⊕ create graphics

Sutherland (MIT ’63) established the basic interactive human-computer paradigm:

1 user “sees” object on the display

2 user “points” to the object by using an input device

3 object reacts

4 repeat from 1

Types

physical devices:Raster video display: CRT, LCD, Plasma, LED, video projector, . . .Hard-copy devices: printers (Ink-ket, laser), film recorder, pen plotter, . . .Input devices: light pen, keyboard, mouse, joystick, scanner, touch screen, tablet,eye-tracker, gloves, electro-magnetic, VR display, . . .

logical devices: Graphics APIs, e.g., OpenGL, WebGL, DirectX/XNA, JavaScriptbased (Three.js, Box2D), X3D, . . .

The separation of physical & logical devices allows for more flexible programs,independent from the actual physical device

4 / 19

Page 8: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Graphics Devices

Graphics Devices (GD)

GD: equipment (hardware) required in order to interact with ⊕ create graphics

Sutherland (MIT ’63) established the basic interactive human-computer paradigm:

1 user “sees” object on the display

2 user “points” to the object by using an input device

3 object reacts

4 repeat from 1

Types

physical devices:Raster video display: CRT, LCD, Plasma, LED, video projector, . . .Hard-copy devices: printers (Ink-ket, laser), film recorder, pen plotter, . . .Input devices: light pen, keyboard, mouse, joystick, scanner, touch screen, tablet,eye-tracker, gloves, electro-magnetic, VR display, . . .

logical devices: Graphics APIs, e.g., OpenGL, WebGL, DirectX/XNA, JavaScriptbased (Three.js, Box2D), X3D, . . .

The separation of physical & logical devices allows for more flexible programs,independent from the actual physical device

4 / 19

Page 9: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Graphics Devices

Graphics Devices (GD)

GD: equipment (hardware) required in order to interact with ⊕ create graphics

Sutherland (MIT ’63) established the basic interactive human-computer paradigm:

1 user “sees” object on the display

2 user “points” to the object by using an input device

3 object reacts

4 repeat from 1

Types

physical devices:Raster video display: CRT, LCD, Plasma, LED, video projector, . . .Hard-copy devices: printers (Ink-ket, laser), film recorder, pen plotter, . . .Input devices: light pen, keyboard, mouse, joystick, scanner, touch screen, tablet,eye-tracker, gloves, electro-magnetic, VR display, . . .

logical devices: Graphics APIs, e.g., OpenGL, WebGL, DirectX/XNA, JavaScriptbased (Three.js, Box2D), X3D, . . .

The separation of physical & logical devices allows for more flexible programs,independent from the actual physical device

4 / 19

Page 10: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Graphics Devices

Raster Device

General notions

a raster (bitmap) display consists of a two-dimensional array of pixels (i.e.,picture elements) ⇒ discretized image

shape and size of a pixel: square with a diagonal of 0.5mm

the size of the array gives the display resolution (i.e., no. vertical pixels × no.horizontal pixels)

images are stored inside RAM in an area called a frame buffer

a hardware device called video controller reads the frame buffer line by line andproduces images on the display

Figure: Raster graphics with Display Processor,www.cs.umd.edu/~mount/427/Lects/427lects.pdf

5 / 19

Page 11: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Frame Buffer

Frame Buffer

Refresh rate

or vertical scan rate usually at 30-75Hz (i.e., 30-75 Frames Per Second – FPS)includes repeated drawing of identical frames

Frame rate

6= refresh ratedoes NOT include the repeated drawing of identical framesusually lower than the refresh rate

Interlaced vs. progressive display

interlace: technique in which the apparent flickering is diminished by doublingthe frame rate (e.g., 50Hz monitor – PAL & SECAM set): paint first the oddlines then the even ones

only ALiS plasma panels and traditional Cathode Ray Tube (CRT) TV sets use itmodern CRT TV: flicker free by using the 100Hz technology

progressive: technique in which all lines are drawn in sequencemost CRT computer monitors, LCD monitors, HDTV displaysLCDs: as much as 120 (i.e., lcm between 24FPS, cinema, and 30FPS, NTSC TV) or240 Hzadvantages over interlace:

no visual artifacts (e.g., interline twitter) & no need for blurring to reduce interline twitterclearer and faster results for scaling to higher resolutionsframes can be captured as still photos

6 / 19

Page 12: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Frame Buffer

Frame Buffer

Refresh rate

or vertical scan rate usually at 30-75Hz (i.e., 30-75 Frames Per Second – FPS)includes repeated drawing of identical frames

Frame rate

6= refresh ratedoes NOT include the repeated drawing of identical framesusually lower than the refresh rate

Interlaced vs. progressive display

interlace: technique in which the apparent flickering is diminished by doublingthe frame rate (e.g., 50Hz monitor – PAL & SECAM set): paint first the oddlines then the even ones

only ALiS plasma panels and traditional Cathode Ray Tube (CRT) TV sets use itmodern CRT TV: flicker free by using the 100Hz technology

progressive: technique in which all lines are drawn in sequencemost CRT computer monitors, LCD monitors, HDTV displaysLCDs: as much as 120 (i.e., lcm between 24FPS, cinema, and 30FPS, NTSC TV) or240 Hzadvantages over interlace:

no visual artifacts (e.g., interline twitter) & no need for blurring to reduce interline twitterclearer and faster results for scaling to higher resolutionsframes can be captured as still photos

6 / 19

Page 13: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Frame Buffer

Color Frame Buffer

About colors

the method to represent colors → depends on pixel depth and on the outputdevice:

additive: video displayssubtractive: printers

pixel depth: the number of bits to represent the color of a pixel (e.g., 24bitRed-Green-Blue model for most video and color LCDs/LEDs)

8 bits for each color component in the 24 bit model (true-color): 0 for black and255 for white

usually a forth component called alpha (denoted A) is used to achieve variouseffects such as opacity and transparency

sometimes 24 bits are too much (e.g., at the beginning of the Internet whendownload speeds were low 8 bit web images were used)

color map (or color Look-Up-Table): used for web GIF images

each pixel stores an 8bit index (i.e., 256 possible colors)the index points to a LUP containing 24bit colors

digital halftoning: technique to trick the eye into seeing many shades of a color wherein reality only a small number of distinct colors exist (e.g., web images)

colors are approximated by putting combinations of similar colors in the same area. The humaneye averages them out.technique used by newspapers (i.e., dots of various sizes)

7 / 19

Page 14: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Frame Buffer

Color Frame Buffers

Figure: Halftoning, www.cs.umd.edu/~mount/427/Lects/427lects.pdf

8 / 19

Page 15: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Frame Buffer

Visible Light

Light

visible light frequencies (electromagnetic spectrum): from red (700nm) to violet(400nm)

light color characterized by:hue: dominant frequency (i.e., highest peak or primary wavelength) of a colorsaturation: excitation purity (i.e., ratio of highest to rest) of a colorlightness: perceived luminance of a color

Figure: A diagram of the electromagnetic spectrum, www.wikipedia.org

9 / 19

Page 16: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Frame Buffer

Color Models

Red-Green-Blue

Cyan-Magenta-Yellow

Hue-Saturation-Lightness

. . .

Images on the right from:http://viz.aset.psu.edu/

gho/sem_notes/color_2d/

html/primary_systems.html

Figure: RGB colorcube

Figure: CMY cube Figure: HSV –“Perceptual” ColorSpaces

10 / 19

Page 17: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Rendering pipeline

“The rendering (graphics) pipeline typically accepts some representation of athree-dimensional primitives as an input and results in a 2D raster image as output”(source: www.wikipedia.org)

Figure: Rendering pipelinehttp://goanna.cs.rmit.edu.au/~gl/teaching/Interactive3D/2011/lecture2.html

11 / 19

Page 18: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Rendering pipeline

points → vertices → fragments → pixels

in mathematics a point is a zero-dimensional primitivein CG a vertex is a data structure that describes a point in 2D/3D space:

positioncolornormaltexturesreflectance

pixel basic unit of the rendering device (e.g., screen).in CG a fragment is in general a pre-pixel, i.e., data necessary to generate asingle pixel (shade ⊕ test):

raster positiondepthcolor, texture coordinates, . . .stencilalpha. . .

It is a sample-sized segment of a rasterized primitive (i.e., point, line, triangle,polygon). BUT . . . Fragments are corresponding portions of the scene geometryand are transformed into pixels.

at least one fragment produced per pixelmultisampling/antialiasing produces multiple fragments per pixel which are theninterpolated to form a single pixel

12 / 19

Page 19: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Rendering pipeline

points → vertices → fragments → pixels

in mathematics a point is a zero-dimensional primitivein CG a vertex is a data structure that describes a point in 2D/3D space:

positioncolornormaltexturesreflectance

pixel basic unit of the rendering device (e.g., screen).

in CG a fragment is in general a pre-pixel, i.e., data necessary to generate asingle pixel (shade ⊕ test):

raster positiondepthcolor, texture coordinates, . . .stencilalpha. . .

It is a sample-sized segment of a rasterized primitive (i.e., point, line, triangle,polygon). BUT . . . Fragments are corresponding portions of the scene geometryand are transformed into pixels.

at least one fragment produced per pixelmultisampling/antialiasing produces multiple fragments per pixel which are theninterpolated to form a single pixel

12 / 19

Page 20: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Rendering pipeline

points → vertices → fragments → pixels

in mathematics a point is a zero-dimensional primitivein CG a vertex is a data structure that describes a point in 2D/3D space:

positioncolornormaltexturesreflectance

pixel basic unit of the rendering device (e.g., screen).in CG a fragment is in general a pre-pixel, i.e., data necessary to generate asingle pixel (shade ⊕ test):

raster positiondepthcolor, texture coordinates, . . .stencilalpha. . .

It is a sample-sized segment of a rasterized primitive (i.e., point, line, triangle,polygon). BUT . . . Fragments are corresponding portions of the scene geometryand are transformed into pixels.

at least one fragment produced per pixelmultisampling/antialiasing produces multiple fragments per pixel which are theninterpolated to form a single pixel

12 / 19

Page 21: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Rendering pipeline - OpenGL 4.4 example

Figure: Pipeline overview of OpenGL 4.4

13 / 19

Page 22: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Rendering pipeline

Shaders

programs used primarily to calculate rendering effects on graphics hardwarethe process of altering the color of an object/surface/polygon in the 3D scene,based on (amongst others) light and material properties to create aphoto-realistic effecttypes:

vertex shader:

run once for each vertextransform each vertex’s 3D position in virtual space to the 2D coordinate in screen space

fragment (pixel) shader:

executed after the vertex shadercompute the color and other attributes of each pixelalone they cannot produce complex effects as they operate on a per pixel basisused for: bump mapping, shadows, specular highlights, translucency, . . .

geometry shader:

can generate new graphics primitives from primitives sent at the beginning of the graphicspipelineoperate between the vertex and a fragment shadersused for: point sprite generation, geometry tessellation, shadow volume extrusion, single passcube map rendering, . . .

compute shader:

relatively newnot part of the rendering pipelinecan perform arbitrary operationsused for: GPGPU operations (non CG applications)

14 / 19

Page 23: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Rendering pipeline

GLSL

(OpenGL Shading Language) – high level shading language based on C syntax. Noneed to use assembly language or hardware specific languages!

1: version version number2: in type in variable name;3: in type in variable name;4: out type out variable name;5: uniform type uniform name;6: void main()7: {8: // process input(s) and do some weird graphics stuff9: ...10: // output processed stuff to output variable11: out variable name = weird stuff we processed;12: }

Figure: General structure of a shader

15 / 19

Page 24: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Rendering pipeline

Vertex shader example

1: version 330 core2: layout (location = 0) in3: vec3 aPos; // the position variable has attribute position 04: out vec4 vertexColor; // specify a color output to the fragment shader5: void main()6: {7: gl Position = vec4(aPos, 1.0); // see how we directly give a vec3 to vec4’s constructor8: vertexColor = vec4(0.5, 0.0, 0.0, 1.0); // set the output variable to a dark-red color9: }

Fragment shader example

1: version 330 core2: out vec4 FragColor;3: in vec4 vertexColor; // the input variable from the vertex shader (same name and same type)4: void main()5: {6: FragColor = vertexColor;7: }

16 / 19

Page 25: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Logical Devices

Logical input

Consider the C code:

1: int x;2: scanf(”%d”, &x);

What is the input device?

cannot tell from the code

can be anything: keyboard, file, another file, . . .

The code provides logical input, i.e., an int is returned regardless of the physical device

Graphical logical devices

graphical input is more varied than input to standard programs

Six types of logical input (for older APIs: GKS, PHIGS):1 keyboard: returns ASCII characters2 locator: position in world coordinates through mouse, trackball, . . .3 pick: identifies an object4 choice: selection of a discrete number of objects5 dial: provides analog input to the program6 stroke: device returns an array of locations through mouse clicks (button down – start

transfer, release button – end transfer)

Newer APIs (e.g., OpenGL) do not take this approach

17 / 19

Page 26: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Logical Devices

Logical input

Consider the C code:

1: int x;2: scanf(”%d”, &x);

What is the input device?

cannot tell from the code

can be anything: keyboard, file, another file, . . .

The code provides logical input, i.e., an int is returned regardless of the physical device

Graphical logical devices

graphical input is more varied than input to standard programs

Six types of logical input (for older APIs: GKS, PHIGS):1 keyboard: returns ASCII characters2 locator: position in world coordinates through mouse, trackball, . . .3 pick: identifies an object4 choice: selection of a discrete number of objects5 dial: provides analog input to the program6 stroke: device returns an array of locations through mouse clicks (button down – start

transfer, release button – end transfer)

Newer APIs (e.g., OpenGL) do not take this approach

17 / 19

Page 27: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Logical Devices

Logical input

Consider the C code:

1: int x;2: scanf(”%d”, &x);

What is the input device?

cannot tell from the code

can be anything: keyboard, file, another file, . . .

The code provides logical input, i.e., an int is returned regardless of the physical device

Graphical logical devices

graphical input is more varied than input to standard programs

Six types of logical input (for older APIs: GKS, PHIGS):1 keyboard: returns ASCII characters2 locator: position in world coordinates through mouse, trackball, . . .3 pick: identifies an object4 choice: selection of a discrete number of objects5 dial: provides analog input to the program6 stroke: device returns an array of locations through mouse clicks (button down – start

transfer, release button – end transfer)

Newer APIs (e.g., OpenGL) do not take this approach

17 / 19

Page 28: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Logical Devices

Logical input

Consider the C code:

1: int x;2: scanf(”%d”, &x);

What is the input device?

cannot tell from the code

can be anything: keyboard, file, another file, . . .

The code provides logical input, i.e., an int is returned regardless of the physical device

Graphical logical devices

graphical input is more varied than input to standard programs

Six types of logical input (for older APIs: GKS, PHIGS):1 keyboard: returns ASCII characters2 locator: position in world coordinates through mouse, trackball, . . .3 pick: identifies an object4 choice: selection of a discrete number of objects5 dial: provides analog input to the program6 stroke: device returns an array of locations through mouse clicks (button down – start

transfer, release button – end transfer)

Newer APIs (e.g., OpenGL) do not take this approach

17 / 19

Page 29: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Logical Devices

Logical input

Consider the C code:

1: int x;2: scanf(”%d”, &x);

What is the input device?

cannot tell from the code

can be anything: keyboard, file, another file, . . .

The code provides logical input, i.e., an int is returned regardless of the physical device

Graphical logical devices

graphical input is more varied than input to standard programs

Six types of logical input (for older APIs: GKS, PHIGS):1 keyboard: returns ASCII characters2 locator: position in world coordinates through mouse, trackball, . . .3 pick: identifies an object4 choice: selection of a discrete number of objects5 dial: provides analog input to the program6 stroke: device returns an array of locations through mouse clicks (button down – start

transfer, release button – end transfer)

Newer APIs (e.g., OpenGL) do not take this approach

17 / 19

Page 30: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Logical Devices

Logical input

Consider the C code:

1: int x;2: scanf(”%d”, &x);

What is the input device?

cannot tell from the code

can be anything: keyboard, file, another file, . . .

The code provides logical input, i.e., an int is returned regardless of the physical device

Graphical logical devices

graphical input is more varied than input to standard programs

Six types of logical input (for older APIs: GKS, PHIGS):1 keyboard: returns ASCII characters2 locator: position in world coordinates through mouse, trackball, . . .3 pick: identifies an object4 choice: selection of a discrete number of objects5 dial: provides analog input to the program6 stroke: device returns an array of locations through mouse clicks (button down – start

transfer, release button – end transfer)

Newer APIs (e.g., OpenGL) do not take this approach17 / 19

Page 31: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Input Modes

Input devices contain triggers (e.g., mouse button, keys) which can be used to sendsignals (e.g., information: position – mouse –, ASCII code – keyboard) to the OS

Input modes

request mode: input provided only when user triggers the device (e.g., keyboardinput)

not sufficient for Human-Computer-Interface

event mode: input stored in an event queue for later examination each time thedevice is triggered (e.g., window : resize; mouse: click, move; keyboard : keypress/release)

ideal for environments with multiple input devices

Callbacks

programming interface for event-driven inputone callback function for each type of event the graphics system recognizesthe user defined callback function is executed when the corresponding eventoccurs:1: public void display(GLAutoDrawable canvas) {2: GL2 gl = canvas.getGL().getGL2();3: gl.glClear(GL.GL COLOR BUFFER BIT);4: //Add here the code for generating the scene5: //...6: gl.glFlush();7: }

Figure: Java for OpenGL: display callback, called each time the scene is rendered

18 / 19

Page 32: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Input Modes

Input devices contain triggers (e.g., mouse button, keys) which can be used to sendsignals (e.g., information: position – mouse –, ASCII code – keyboard) to the OS

Input modes

request mode: input provided only when user triggers the device (e.g., keyboardinput)

not sufficient for Human-Computer-Interface

event mode: input stored in an event queue for later examination each time thedevice is triggered (e.g., window : resize; mouse: click, move; keyboard : keypress/release)

ideal for environments with multiple input devices

Callbacks

programming interface for event-driven inputone callback function for each type of event the graphics system recognizesthe user defined callback function is executed when the corresponding eventoccurs:1: public void display(GLAutoDrawable canvas) {2: GL2 gl = canvas.getGL().getGL2();3: gl.glClear(GL.GL COLOR BUFFER BIT);4: //Add here the code for generating the scene5: //...6: gl.glFlush();7: }

Figure: Java for OpenGL: display callback, called each time the scene is rendered

18 / 19

Page 33: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Input Modes

Input devices contain triggers (e.g., mouse button, keys) which can be used to sendsignals (e.g., information: position – mouse –, ASCII code – keyboard) to the OS

Input modes

request mode: input provided only when user triggers the device (e.g., keyboardinput)

not sufficient for Human-Computer-Interface

event mode: input stored in an event queue for later examination each time thedevice is triggered (e.g., window : resize; mouse: click, move; keyboard : keypress/release)

ideal for environments with multiple input devices

Callbacks

programming interface for event-driven inputone callback function for each type of event the graphics system recognizesthe user defined callback function is executed when the corresponding eventoccurs:1: public void display(GLAutoDrawable canvas) {2: GL2 gl = canvas.getGL().getGL2();3: gl.glClear(GL.GL COLOR BUFFER BIT);4: //Add here the code for generating the scene5: //...6: gl.glFlush();7: }

Figure: Java for OpenGL: display callback, called each time the scene is rendered18 / 19

Page 34: Computer Graphics Lecture 2 - West University of Timișoaramarc.frincu/cg/c2.pdf · Computer Graphics Lecture 2 Dr. Marc Eduard Fr^ ncu West University of Timisoara Mar 3, 2020 ...

Graphics System Rendering pipeline Logical Devices Recap

Lecture Recap

graphics system = equipment (graphics devices) ⊕ specializedprograms/graphics APIs

physical ⊕ logical devices

images stored inside a memory zone called frame buffer before being rendered onthe display

real light (wave ⊕ particle), simulated light (various models: RGB, CMY, HSL)

rendering pipeline: converts a 3D model to a 2D raster image

points → vertices → fragments → pixels

input modes: request vs. event based ⇒ event based wins in graphics contest

19 / 19