Chapter 13 selection and feedback
Download
1 / 40

Chapter 13. - PowerPoint PPT Presentation


  • 296 Views
  • Updated 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.' - 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


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)


    Window coordinates
    Window Coordinates GLdouble height, GLint viewport[4]);


    Miscellaneous
    Miscellaneous GLdouble height, GLint viewport[4]);

    • 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


    Example 13 3 picksquare
    Example 13-3. picksquare GLdouble height, GLint viewport[4]);


    Example 13 6 pickdepth
    Example 13-6. pickdepth GLdouble height, GLint viewport[4]);


    Pickdepth2
    pickdepth2 GLdouble height, GLint viewport[4]);


    Feedback

    Feedback GLdouble height, GLint viewport[4]);


    Characteristics
    Characteristics GLdouble height, GLint viewport[4]);

    • 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 GLdouble height, GLint viewport[4]);

    • 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 GLdouble height, GLint viewport[4]);(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() GLdouble height, GLint viewport[4]);type Values

    <Table 13-1>


    The feedback array
    The Feedback Array GLdouble height, GLint viewport[4]);

    • Begins with a code indicating the primitive type

      • Followed by the values

        • The primitive’s vertices

        • Associated data

        • Pass-through markers can be returned


    Feedback array syntax
    Feedback Array Syntax GLdouble height, GLint viewport[4]);

    <Table 13-2>


    Using markers in feedback mode
    Using Markers in GLdouble height, GLint viewport[4]);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 GLdouble height, GLint viewport[4]);(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


    Example 13 7 feedback
    Example 13-7. feedback GLdouble height, GLint viewport[4]);


    Glgetintegerv
    glGetIntegerv() GLdouble height, GLint viewport[4]);

    • 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