Chapter 13. Selection and Feedback - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

Chapter 13. Selection and Feedback

Description:

Select a region of the screen. Pick an object drawn on the ... Bitmap. n vertex vertex ... vertex. GL_POLYGON_TOKEN. Polygon. vertex vertex. GL_LINE_TOKEN or ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 41
Provided by: kucgKo
Category:

less

Transcript and Presenter's Notes

Title: Chapter 13. Selection and Feedback


1
Chapter 13.Selection and Feedback
  • OpenGL Programming Guide Third Edition
  • Presented by Jung Lee

2
Chapter Objectives
  • Select a region of the screen
  • Pick an object drawn on the screen
  • Use the OpenGL feedback mode
  • To obtain the results of rendering calculations

3
Interactive Applications
  • Identify, modify, delete, and manipulate
  • Difficult to know which object is selected
  • Since objects on the screen typically undergo
  • Multiple rotations, translations, and perspective
    transformations

4
Selection and Feedback Modes
  • In both selection and feedback modes
  • Drawing information is returned
  • Rather than being sent to the framebuffer
  • The contents the other buffers are not affected
  • Section overview
  • Selection / Picking
  • How to use selection mode and related routines
  • Feedback
  • How to obtain drawing information
  • How that information is formatted

5
Selection
6
Overview
  • Process
  • Draw your scene into the framebuffer
  • Enter selection mode
  • Redraw the scene
  • In selection mode
  • The contents of the framebuffer dont change
  • When exiting selection mode
  • Returns a list of the primitives that intersect
    the viewing volume

7
Hit
  • Each primitive that intersects the viewing volume
  • Causes a selection hit
  • The list of primitives is returned as
  • An array of integer-valued names and
  • Related data the hit records
  • Correspond to the current contents of the name
    stack

8
The Basic Steps (1/2)
  • Specify the array to be used for the returned hit
    records
  • glSelectBuffer()
  • Enter selection mode
  • glRenderMode(GL_SELECT)
  • Initialize the name stack
  • glInitNames() and glPushName()

9
The Basic Steps (2/2)
  • Define the viewing volume
  • Usually different from the viewing volume to draw
    the scene
  • Save and then restore the current transformation
    state
  • glPushMatrix() and glPopMatrix()
  • Primitive drawing commands and commands to
    manipulate the name stack
  • Each primitive of interest is assigned an
    appropriate name
  • Exit selection mode
  • Process the returned selection data
  • Hit records

10
void glSelectBuffer(GLsizei size, GLuint
buffer)
  • Specify the array to be used for the returned
    selection data
  • buffer
  • A pointer to an array of unsigned integers
  • size
  • Maximum number of values that can be stored

11
GLint glRenderMode(GLenum mode)
  • Controls whether the application is in
  • Rendering, selection, or feedback mode
  • mode ? glGetIntegerv(GL_RENDER_MODE)
  • GL_RENDER(default), GL_SELECT, GL_FEEDBACK
  • Before selection/feedback mode is entered
  • glSelectBuffer() or glFeedbackBuffer()
  • Return value when either mode is exited
  • The number of selection hits or
  • The number of values in the feedback array
  • Negative value the array is overflowed

12
Creating the Name Stack
  • Initialize with glInitNames()
  • Add integer names
  • While issuing corresponding drawing commands
  • Commands to manipulate the name stack
  • glPushName(), glPopName(), glLoadName()
  • Calls are ignored if not in selection mode
  • Same drawing code to simplify your code
  • For both selection and rendering modes

13
Example 13-1
  • glInitNames()
  • glPushName()
  • glPushMatrix() / save the current
    transformation state /
  • / create your desired viewing volume here /
  • glLoadName(1)
  • drawSomeObject()
  • glLoadName(2)
  • drawAnotherObject()
  • glLoadName(3)
  • drawYetAnotherObject()
  • drawJustOneMoreObject()
  • glPopMatrix() / restore the previous
    transformation state /

14
void glInitNames(void)
  • Clears the name stack

15
void glPushName(GLuint name)
  • Pushes name onto the name stack
  • Pushing a name beyond the capacity of the stack
    generates error
  • GL_STACK_OVERFLOW
  • The name stacks depth
  • Vary among different OpenGL implementations
  • At least 64 names
  • glGetIntegerv(GL_NAME_STACK_DEPTH)

16
void glPopName(void)
  • Pops a name off the top of the name stack
  • Popping an empty stack
  • Generates the error, GL_STACK_UNDERFLOW

17
void glLoadName(GLuint name)
  • Replace the value at the top of the name stack
    with name
  • If the stack is empty
  • Generates the error, GL_INVALID_OPERATION

18
The Hit Record
  • Whenever a name stack manipulation command is
    executed or
  • glRenderMode() is called
  • Written into the selection array
  • If there has been a hit since the last time
  • Valid coordinates produced by glRasterPos()
  • Can cause a selection hit
  • If the polygon would have been culled
  • No hit occurs

19
Contents of the Hit Record
  • The number of names on the name stack
  • Both the minimum and maximum z-values
  • Of all vertices of the primitives
  • Lie in the range 0, 1
  • Multiplied by 232-1(0x7fffffff)
  • The contents of the name stack at the hit
  • With the bottommost element first

20
Example 13-2. select
21
Picking
22
Overview
  • Use a special picking matrix
  • In conjunction with the projection matrix
  • To restrict drawing to a small region of the
    viewport
  • Differences from regular selection mode
  • Usually triggered by an input device
  • gluPickMatrix()
  • Multiply the current projection matrix by a
    picking matrix
  • Called prior to multiplying a standard projection
    matrix
  • gluPerspective() or glOrtho()
  • Save the projection matrix first

23
Simple Example
  • glMatrixMode(GL_PROJECTION)
  • glPushMatrix()
  • glLoadIdentity()
  • gluPickMatrix(...)
  • gluPerspective, glOrtho, gluOrtho2D, or
    glFrustum
  • / draw scene for picking perform picking /
  • glPopMatrix()

24
gluPickMatrix(GLdouble x, GLdouble y, GLdouble
width, GLdouble height, GLint viewport4)
  • Creates a projection matrix
  • Restricts drawing to a small region of the
    viewport
  • Be multiplied onto the current matrix stack
  • Parameters
  • (x, y) the center of the picking region
  • In window coordinates ex) cursor location
  • width and height the size of the picking region
  • In screen coordinates
  • viewport current viewport boundaries
  • glGetIntegerv(GL_VIEWPORT, GLint viewport)

25
Window Coordinates
26
Miscellaneous
  • Another way to perform picking
  • Described in chapter 14
  • Use color values
  • To identify different components of an object
  • Hints for writing a program with selection
  • For 2D drawing programs
  • Easier to do your own picking calculations
  • ex) Bounding boxes for 2D objects
  • Extremely fast and simple

27
Example 13-3. picksquare
28
Example 13-6. pickdepth
29
pickdepth2
30
Feedback
31
Characteristics
  • Similar to selection
  • The information that is sent back
  • In selection mode
  • Assigned names
  • To an array of integer values
  • In feedback mode
  • Drawing information about transformed primitives
  • To an array of floating-point values
  • Type of primitive, vertex, color, or other data
  • Transformed by lighting and viewing operations
  • glRenderMode(GL_FEEDBACK)

32
How You Enter and Exit Feedback Mode
  • Call glFeedbackBuffer()
  • Specify the array to hold the feedback
    information
  • Call glRenderMode(GL_FEEDBACK)
  • Draw the primitives
  • Can make several calls to glPassThrough()
  • Insert markers into the returned feedback data
  • Exit feedback mode
  • By calling glRenderMode(GL_RENDER)
  • The returned integer value
  • The number of values stored in the feedback array

33
void glFeedbackBuffer(GLsizei size, GLenum type,
GLfloat buffer)
  • Establishes a buffer for the feedback data
  • Must be called before feedback mode is entered
  • buffer
  • Pointer to an array
  • size
  • Maximum number of values
  • type
  • Information fed back for each vertex

34
glFeedbackBuffer() type Values
ltTable 13-1gt
35
The Feedback Array
  • Begins with a code indicating the primitive type
  • Followed by the values
  • The primitives vertices
  • Associated data
  • Pass-through markers can be returned

36
Feedback Array Syntax
ltTable 13-2gt
37
Using Markers in Feedback Mode
  • Feedback occurs after
  • Transformations, lighting, polygon culling, and
    interpretation of polygons
  • By glPolygonMode()
  • Polygons with more than three edges
  • Broken up into triangles
  • Call glPassThrough()
  • Cause GL_PASS_THROUGH_TOKEN to be written into
    the feedback array
  • To help parse the feedback data
  • To separate the feedback values

38
void glPassThrough(GLfloat token)
  • Inserts a marker into the stream of values in
    feedback array
  • The marker consists of
  • The code GL_PASS_THROUGH_TOKEN
  • Followed by a single floating-point value, token
  • No effect when called outside of feedback mode
  • Calling between glBegin() and glEnd()
  • Generates a GL_INVALID_OPERATION error

39
Example 13-7. feedback
40
glGetIntegerv()
  • GL_MAX_CLIP_PLANES 6
  • GL_MAX_LIGHTS 8
  • GL_MAX_MODELVIEW_STACK_DEPTH 32
  • GL_MAX_NAME_STACK_DEPTH 128
  • GL_MAX_PROJECTION_STACK_DEPTH 10
  • GL_POINT_SIZE_RANGE 164
Write a Comment
User Comments (0)
About PowerShow.com