chapter 13 selection and feedback
Download
Skip this Video
Download Presentation
Chapter 13. Selection and Feedback

Loading in 2 Seconds...

play fullscreen
1 / 40

Chapter 13. Selection and Feedback - PowerPoint PPT Presentation


  • 296 Views
  • Uploaded on

Chapter 13. Selection and Feedback. OpenGL Programming Guide Third Edition Presented by Jung Lee. 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. Interactive Applications.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Chapter 13. Selection and Feedback' - niveditha


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
chapter 13 selection and feedback

Chapter 13.Selection and Feedback

OpenGL Programming Guide Third Edition

Presented by Jung Lee

chapter objectives
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
interactive applications
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
selection and feedback modes
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
overview
Overview
  • Process
    • Draw your scene into the framebuffer
    • Enter selection mode
    • Redraw the scene
  • In selection mode
    • The contents of the framebuffer don’t change
  • When exiting selection mode
    • Returns a list of the primitives that intersect the viewing volume
slide7
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
the basic steps 1 2
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()
the basic steps 2 2
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
void glselectbuffer glsizei size gluint buffer
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
glint glrendermode glenum mode
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
creating the name stack
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
example 13 1
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 */

void glinitnames void
void glInitNames(void);
  • Clears the name stack
void glpushname gluint name
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 stack’s depth
    • Vary among different OpenGL implementations
    • At least 64 names
    • glGetIntegerv(GL_NAME_STACK_DEPTH)
void glpopname void
void glPopName(void);
  • Pops a name off the top of the name stack
  • Popping an empty stack
    • Generates the error, GL_STACK_UNDERFLOW
void glloadname gluint name
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
the hit record
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
contents of the hit record
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
overview1
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
simple example
Simple Example

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glLoadIdentity();

gluPickMatrix(...);

gluPerspective, glOrtho, gluOrtho2D, or glFrustum

/* draw scene for picking ; perform picking */

glPopMatrix();

glupickmatrix gldouble x gldouble y gldouble width gldouble height glint viewport 4
gluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4]);
  • 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)
miscellaneous
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
characteristics
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);
how you enter and exit feedback mode
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
void glfeedbackbuffer glsizei size glenum type glfloat buffer
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
glfeedbackbuffer type values
glFeedbackBuffer()type Values

the feedback array
The Feedback Array
  • Begins with a code indicating the primitive type
    • Followed by the values
      • The primitive’s vertices
      • Associated data
      • Pass-through markers can be returned

using markers in feedback mode
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
void glpassthrough glfloat token
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
glgetintegerv
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: 1~64
ad