(ndc) systems · interaction actors.. k.. 4120/5120 9 opengl en ocessing olling: cpu asteful. en:...
Post on 25-Jul-2020
2 Views
Preview:
TRANSCRIPT
World Coordinate System
Application
�
ModelApplication
�
ProgramGraphics
�
System Workstation
�
� Normally, the User or Object Coordinate System.
� World Coordinate Window: A subset of the world coordinate system,defined by the application.
� For instance, this could be the coordinate system of reals.
ITCS 4120/5120 1 Graphics Packages and OpenGL
Normalized Device Coordinate System (NDC)
Application
�
ModelApplication
�
ProgramGraphics
�
System Workstation
�
� The standardized coordinate system for all devices.
� Ranges from (0.0− 1.0) in each dimension.
� Convenient for all device drivers.
� A convenient space for performain Pick operations.
ITCS 4120/5120 2 Graphics Packages and OpenGL
Device Coordinate System
Application
�
ModelApplication
�
ProgramGraphics
�
System Workstation
�
� Coordinate system of Device.
� Could be different for each device.
� Must specify device square for mapping from NDC.
ITCS 4120/5120 3 Graphics Packages and OpenGL
Example Coordinate Systems
(−20, −1)
(−10, 2)
(1.5, 3.3)
(−2.5, 4.5)
(−1000,−500)
(1000, 500)
World Coordinate Windows
(0.0, 0.0)
(1.0, 1.0)
Normalized Device Coordinates
(0,0)
(1280,1024)
Device Coordinates (example)
ITCS 4120/5120 4 Graphics Packages and OpenGL
A Simple Graphics Package
Graphics Primitives
� Point
� Line, Polyline, Polygon, Rectangle
� Circle, Ellipse
� Marker, Polymarker
� Text
ITCS 4120/5120 5 Graphics Packages and OpenGL
Graphics Primitives
PolylinePolygon
PolyMarker
StartAngle
EndAngleEllipse
ITCS 4120/5120 6 Graphics Packages and OpenGL
Graphics Attributes
� Lines: style (continuous, dashed, dotted), width
� Markers: style, size
� Color (color index or true color - RGB)
� Filled Primitives: style (opaque, transparent), pattern(bitmap/pixmap)
� Text: style (font), size, orientation
� Foreground/Background colors
� Inquiry
ITCS 4120/5120 7 Graphics Packages and OpenGL
Text
Heightbaseline
Text Origin
�
Text center
�
Width
quit
Attributes
� Font (Times, Helvetica, Roman)
� Appearance (Bold, italic, underlined)
� Size (points), Orientation
� Inter-character, Inter-line spacing
Implementation
� As Pixmaps
� As geometric descriptions (splines, for instance)ITCS 4120/5120 8 Graphics Packages and OpenGL
Interaction
Human Factors
� Simple, consistent interaction sequences.
� Not too many options, features.
� Appropriate feedback.
� Error recovery.
ITCS 4120/5120 9 Graphics Packages and OpenGL
Input Interaction: Sampling vs. Event-DrivenProcessing
� Polling: Continuous monitoring of all enabled input devices - CPUintensive, wasteful.
� Interrupt-driven: Application interrupted when device state changes- a little tricky.
� Event-driven: Application chooses to service the event at its conve-nience (GKS, PHIGS, X).
Application
�
Mouse
Keyboard
Event Queues
DeviceHandler
ITCS 4120/5120 10 Graphics Packages and OpenGL
Event Based Processing
Initialize and generate initial displaydo{
wait for user selectionswitch (on selection){
selection 1 : process selection 1selection 2 : process selection 1..................................................................selection n : process selection n
}} while (!quit)
ITCS 4120/5120 11 Graphics Packages and OpenGL
Transformations/Viewing
� Affine (modeling) transforms (scale,rotate, translate)
� Camera specification
� Projection transformations (parallel(orthographic), perspective)
� Clipping and View volume specification
ITCS 4120/5120 12 Graphics Packages and OpenGL
Lighting
� Local models (Ambient, Diffuse, Specular)
� Light sources (color, position, attenuation), types (spotlights)
� Material colors/properties
� Local vs. Infinite Viewpoint
ITCS 4120/5120 13 Graphics Packages and OpenGL
Raster Operations
� Exploits display hardware features, especially saving and restoringbitmaps.
� BITBLT operations.
Canvases
• Any bitmap or pixmap (2D array of pixels) is a canvas.
• Canvases have size, extent, mask and other attributes.
• Can be created, deleted, changed, copied.
• Offscreen or onscreen.
• Operations affect current canvas.
ITCS 4120/5120 14 Graphics Packages and OpenGL
Raster Operations(contd)
Source Destination
Op
Replace OR XOR AND
�
Write Masks:
� Write masks control bit planes that are to be modified
� Logical operations between source and destination canvases.
Application
� Pull down menus.
� Rubber Banding.ITCS 4120/5120 15 Graphics Packages and OpenGL
Other Package Features
� Pixels, Bitmaps, Images (BitBlt)
� Blending, Anti-aliasing, Fog
� Texture mapping (2D and 3D) and filtering
� Framebuffer Operations
� Modeling and representation (Polygons, Cubics (Bezier, B-Spline,NURBS)
ITCS 4120/5120 16 Graphics Packages and OpenGL
OpenGL: An Introduction
� A graphics language that is a current industry standard
� Widely deployed across multiple application domains, platforms,vendors
� Outgrowth of SGI GL
� Device independent
� Supports interfaces to modern graphics hardware/systems
ITCS 4120/5120 17 Graphics Packages and OpenGL
Graphics APIs
Generally these APIs support both 2D and 3D graphics:
� GKS (Graphics Kernal System)
� PHIGS (Programmer Hierarchical Interactive Graphics Standard)
� PHIGS+
� GL (Graphics Library) by SGI
� OpenGL
� DirectDraw, Direct3D by Microsoft
ITCS 4120/5120 18 Graphics Packages and OpenGL
What is OpenGL
� A software interface to graphics hardware
� Consists of about 250 different commands (200 core, 50 utility func-tions)
� Implemented on all major platforms/operating systems
� All windowing tasks, user input/output must be supported by under-lying windowing system (X, Direct X, etc)
� Limited modeling support - support for low level primitives only
� GLU - higher level utility library with support for modeling featureslike NURBS.
� OpenGL Utility Toolkit (GLUT) primitive window setup and eventhandling
ITCS 4120/5120 19 Graphics Packages and OpenGL
GL Output Examples
Wireframe Rendering
ITCS 4120/5120 20 Graphics Packages and OpenGL
Depth Cueing
ITCS 4120/5120 21 Graphics Packages and OpenGL
Anti-aliasing
ITCS 4120/5120 22 Graphics Packages and OpenGL
Flat Shaded Rendering
ITCS 4120/5120 23 Graphics Packages and OpenGL
Smooth (Gouraud) Shaded Renering
ITCS 4120/5120 24 Graphics Packages and OpenGL
Texture Mapping and Shadows
ITCS 4120/5120 25 Graphics Packages and OpenGL
Atmospheric (Fog) Effects
ITCS 4120/5120 26 Graphics Packages and OpenGL
Rendering Different Material TypesITCS 4120/5120 27 Graphics Packages and OpenGL
Environment Mapping
ITCS 4120/5120 28 Graphics Packages and OpenGL
What does GL do?
� Construct shapes from geometric primitives (points, lines, polygons,pixels, images)
� Arrange objects in 3D space and select location to view the com-posed scene.
� Calculate colors of objects, from specification or lighting conditions,pasting texture onto objects.
� Convert mathematical description of objects and colors into screenpixels, termed rasterization
ITCS 4120/5120 29 Graphics Packages and OpenGL
OpenGL Basic Syntax (C Language Binding)
� Functions: glXXXX glBegin, glEnd, glPolygonMode
� Constants: GL XXXX GL 2D, GL RGB, GL CCW
� Types: GLxxx GLbyte, GLshort, GLint, GLfloat, GLdouble, GL-boolean
ITCS 4120/5120 30 Graphics Packages and OpenGL
OpenGL Geometric Output Primitives
� Types: GL POINTS, GL LINES, GL LINE LOOP, GL LINE STRIP,GL POLYGON, GL QUADS, GL QUAD STRIP, GL TRIANGLE,GL TRIANGLE STRIP, GL TRIANGLE FAN
� Basic Syntax:
glBegin (PrimitiveConstant);glVertex3f (x1,y1,z1)glVertex3f (x2,y2,z2)· · · · · ·
glEnd();
ITCS 4120/5120 31 Graphics Packages and OpenGL
OpenGL: A State Machine
� OpenGL operates as a state machine - state remains in effect untilit is changed.
� Example states: current color, viewing/projection transformations,line/polygon patterns, light position/characteristics.
� Each state variable has a default value and can be queried, (glGet-Intv(), glGetFloatv(), etc). enabled/disabled (glEnable(), glDisable()).
� Can also save collections of attributes (glPushAttrib(), glPopAttrib()).ITCS 4120/5120 32 Graphics Packages and OpenGL
OpenGL Rendering Pipeline
ITCS 4120/5120 33 Graphics Packages and OpenGL
Display Lists
� OpenGL has 2 modes of operation: immediate, or retained.
� Display lists allow collections of geometry and attributes to be storedfor later use; allows optimization
� Display lists are write-only; no other structure within objects (in con-trast to OpenInventor, Java3D, VRML)
ITCS 4120/5120 34 Graphics Packages and OpenGL
Evaluators
� A set of functions that allows evaluation of curved surfaces (Bezier,B-Spline, NURBS), for conversion to points, lines, polygons
� A polynomial mapping, producing surface normals, texture coords,colors, surface coordinates from control points.
ITCS 4120/5120 35 Graphics Packages and OpenGL
Per-Vertex Operations
� Typically, vertices are transformed (modeling, projection) by 4 × 4matrices, in preparation for primitive assembly.
� Texture coordinates can be generated and transformed,
� Lighting calculations are also performed with transformed vertex,normal and lighting attributes.
ITCS 4120/5120 36 Graphics Packages and OpenGL
Primitive Assembly
� Involves clipping, perspective division
� Viewport and depth(Z coord) operations are applied
� Results are complete geometric primitives, in preparation for raster-ization.
ITCS 4120/5120 37 Graphics Packages and OpenGL
Points and Lines
glBegin (PrimitiveConstant);glVertex3f (x1,y1,z1)glVertex3f (x2,y2,z2)· · · · · ·
glEnd();ITCS 4120/5120 38 Graphics Packages and OpenGL
Polygons
glBegin (PrimitiveConstant);glVertex3f (x1,y1,z1)glVertex3f (x2,y2,z2)· · · · · ·
glEnd();
ITCS 4120/5120 39 Graphics Packages and OpenGL
Polygons
glBegin (PrimitiveConstant);glVertex3f (x1,y1,z1)glVertex3f (x2,y2,z2)· · · · · ·
glEnd();
ITCS 4120/5120 40 Graphics Packages and OpenGL
Why glBegin/glEnd?
� Trying to define a separate function for each possible combination ofvertex data too cumbersome:
� Last specified color, normal, texcoord used by vertex call.
� versions of calls based on type, eg., vertex3f(), vertex2i().
glBegin (PrimitiveConstant);glColor3f (c1,c1,c1)glTexCoord2f(t1,t2)glVertex3f (x1,y1,z1)glColor3i (c1,c2,c3)glNormal3f (n1,n2,n3)glVertex3f (x2,y2,z2)
glEnd()
ITCS 4120/5120 41 Graphics Packages and OpenGL
Why glBegin/glEnd?
� Allow maximum possible parallelism in host CPU and Graphics Pro-cessor
glBegin (PrimitiveConstant);compute x1,y1,z1 coordinateglVertex3f (x1,y1,z1)
compute x2,y2,z2 coordinateglVertex3f (x2,y2,z2) · · ·
glEnd()
◦ GPU can compute during CPU calls.
ITCS 4120/5120 42 Graphics Packages and OpenGL
Vertex Arrays
� downside of glBegin/glEnd is lots of function calls
� OpenGL Vertex Arrays
◦ drastically reduce function call overhead◦ support most common combinations of vertex data◦ allow sharing of vertex coordinates for adjacent primitives
glEnableClientState (GL VERTEX ARRAY);glVertexPointer ( 3 , GL FLOAT, 0, vertex coords);glDrawElements (GL QUADS, 24, GL UNSIGNED BYTE, vertex indices );
ITCS 4120/5120 43 Graphics Packages and OpenGL
Pixel Operations
� Pixels are unpacked into components, followed by scaling, bias cal-culations
� Results are clamped and written into texture memory or sent to ras-terization step.
� Pixel data from framebuffer - apply pixel transfer ops (scale, bias,clamping), then packed for storage in system memory.
ITCS 4120/5120 44 Graphics Packages and OpenGL
Pixel Array Primitives
glBitmap (width, height, x0, y0, xOffset, yOffset, bit array)
� width, height - size of bit map to draw (in last specified color)
� x0, y0 defines window coordinate of lower-left corner of bit array
� xOffset, yOffset added to current raster position (see glRaster-Pos2i); useful for text output
� bit array bits encode in unsigned byte array
� Figure 3.61, Hearn/Baker.
ITCS 4120/5120 45 Graphics Packages and OpenGL
OpenGL Raster Operations
� Raster operations, bitblts (bit-block transfers), pixblts
� glDrawPixels (width, height, dataFormat, dataType, pixel array)
� glReadPixels (xmin, ymin, width, height, dataFormat, dataType,pixel array)
� glCopyPixels from glReadBuffer to glDrawBuffer
ITCS 4120/5120 46 Graphics Packages and OpenGL
Texture Assembly
� Textures (images + lots of texture rendering options) can be boundto texture objects; then you can switch between texture objects
� Multiple textures may be assembled into texture objects, for efficientswitching.
ITCS 4120/5120 47 Graphics Packages and OpenGL
Rasterization
� Scan conversion of geometry and pixel data into fragments.
� Line, polygon attributes, shading model and coverage calculationsare accounted for rastering lines, polygons into pixels.
� fragment is pixel color + depth value + stencil + accumulation
ITCS 4120/5120 48 Graphics Packages and OpenGL
Fragment Operations
� Series of operations that might result in discarding fragment.
� Texturing, fog calculatons, scissor test, alpha test, stencil test, depthbuffer (Z) test, are performed (if enabled)
� Followed by blending, dithering, logical ops, masking performed.
� Processed and fragments that survive are drawn into the appropriatebuffer, becoming a rendered pixel.
ITCS 4120/5120 49 Graphics Packages and OpenGL ITCS 4120/5120 50 Graphics Packages and OpenGL
top related