Presentation is loading. Please wait.

Presentation is loading. Please wait.

Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.

Similar presentations


Presentation on theme: "Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13."— Presentation transcript:

1 Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13. Selection and Feedback OpenGL Programming Guide Third Edition Presented by Jung Lee

2 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory2 Chapter Objectives Select a region of the screen Select a region of the screen Pick an object drawn on the screen Pick an object drawn on the screen Use the OpenGL feedback mode Use the OpenGL feedback mode To obtain the results of rendering calculations To obtain the results of rendering calculations

3 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory3 Interactive Applications Identify, modify, delete, and manipulate Identify, modify, delete, and manipulate Difficult to know which object is selected Difficult to know which object is selected Since objects on the screen typically undergo Since objects on the screen typically undergo Multiple rotations, translations, and perspective transformations Multiple rotations, translations, and perspective transformations

4 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory4 Selection and Feedback Modes In both selection and feedback modes In both selection and feedback modes Drawing information is returned Drawing information is returned Rather than being sent to the framebuffer Rather than being sent to the framebuffer The contents the other buffers are not affected The contents the other buffers are not affected Section overview Section overview Selection / Picking Selection / Picking How to use selection mode and related routines How to use selection mode and related routines Feedback Feedback How to obtain drawing information How to obtain drawing information How that information is formatted How that information is formatted

5 Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Selection

6 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory6 Overview Process Process Draw your scene into the framebuffer Draw your scene into the framebuffer Enter selection mode Enter selection mode Redraw the scene Redraw the scene In selection mode In selection mode The contents of the framebuffer don’t change The contents of the framebuffer don’t change When exiting selection mode When exiting selection mode Returns a list of the primitives that intersect the viewing volume Returns a list of the primitives that intersect the viewing volume

7 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory7 Hit Each primitive that intersects the viewing volume Each primitive that intersects the viewing volume Causes a selection hit Causes a selection hit The list of primitives is returned as The list of primitives is returned as An array of integer-valued names and An array of integer-valued names and Related data – the hit records Related data – the hit records Correspond to the current contents of the name stack Correspond to the current contents of the name stack

8 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory8 The Basic Steps (1/2) Specify the array to be used for the returned hit records Specify the array to be used for the returned hit records glSelectBuffer() glSelectBuffer() Enter selection mode Enter selection mode glRenderMode(GL_SELECT) glRenderMode(GL_SELECT) Initialize the name stack Initialize the name stack glInitNames() and glPushName() glInitNames() and glPushName()

9 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory9 The Basic Steps (2/2) Define the viewing volume Define the viewing volume Usually different from the viewing volume to draw the scene Usually different from the viewing volume to draw the scene Save and then restore the current transformation state Save and then restore the current transformation state glPushMatrix() and glPopMatrix() glPushMatrix() and glPopMatrix() Primitive drawing commands and commands to manipulate the name stack Primitive drawing commands and commands to manipulate the name stack Each primitive of interest is assigned an appropriate name Each primitive of interest is assigned an appropriate name Exit selection mode Exit selection mode Process the returned selection data Process the returned selection data Hit records Hit records

10 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory10 void glSelectBuffer (GLsizei size, GLuint *buffer); Specify the array to be used for the returned selection data Specify the array to be used for the returned selection data buffer buffer A pointer to an array of unsigned integers A pointer to an array of unsigned integers size size Maximum number of values that can be stored Maximum number of values that can be stored

11 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory11 GLint glRenderMode (GLenum mode); Controls whether the application is in Controls whether the application is in Rendering, selection, or feedback mode Rendering, selection, or feedback mode mode  glGetIntegerv(GL_RENDER_MODE) mode  glGetIntegerv(GL_RENDER_MODE) GL_RENDER (default), GL_SELECT, GL_FEEDBACK GL_RENDER (default), GL_SELECT, GL_FEEDBACK Before selection/feedback mode is entered Before selection/feedback mode is entered glSelectBuffer() or glFeedbackBuffer() glSelectBuffer() or glFeedbackBuffer() Return value when either mode is exited Return value when either mode is exited The number of selection hits or The number of selection hits or The number of values in the feedback array The number of values in the feedback array Negative value: the array is overflowed Negative value: the array is overflowed

12 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory12 Creating the Name Stack Initialize with glInitNames() Initialize with glInitNames() Add integer names Add integer names While issuing corresponding drawing commands While issuing corresponding drawing commands Commands to manipulate the name stack Commands to manipulate the name stack glPushName(), glPopName(), glLoadName() glPushName(), glPopName(), glLoadName() Calls are ignored if not in selection mode Calls are ignored if not in selection mode Same drawing code to simplify your code Same drawing code to simplify your code For both selection and rendering modes For both selection and rendering modes

13 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory13 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 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory14 void glInitNames(void); Clears the name stack Clears the name stack

15 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory15 void glPushName (GLuint name); Pushes name onto the name stack Pushes name onto the name stack Pushing a name beyond the capacity of the stack generates error Pushing a name beyond the capacity of the stack generates error GL_STACK_OVERFLOW GL_STACK_OVERFLOW The name stack’s depth The name stack’s depth Vary among different OpenGL implementations Vary among different OpenGL implementations At least 64 names At least 64 names glGetIntegerv(GL_NAME_STACK_DEPTH) glGetIntegerv(GL_NAME_STACK_DEPTH)

16 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory16 void glPopName(void); Pops a name off the top of the name stack Pops a name off the top of the name stack Popping an empty stack Popping an empty stack Generates the error, GL_STACK_UNDERFLOW Generates the error, GL_STACK_UNDERFLOW

17 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory17 void glLoadName (GLuint name); Replace the value at the top of the name stack with name Replace the value at the top of the name stack with name If the stack is empty If the stack is empty Generates the error, GL_INVALID_OPERATION Generates the error, GL_INVALID_OPERATION

18 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory18 The Hit Record Whenever a name stack manipulation command is executed or Whenever a name stack manipulation command is executed or glRenderMode() is called glRenderMode() is called Written into the selection array Written into the selection array If there has been a hit since the last time If there has been a hit since the last time Valid coordinates produced by glRasterPos() Valid coordinates produced by glRasterPos() Can cause a selection hit Can cause a selection hit If the polygon would have been culled If the polygon would have been culled No hit occurs No hit occurs

19 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory19 Contents of the Hit Record The number of names on the name stack The number of names on the name stack Both the minimum and maximum z-values Both the minimum and maximum z-values Of all vertices of the primitives Of all vertices of the primitives Lie in the range [0, 1] Lie in the range [0, 1] Multiplied by 2 32 -1(0x7fffffff) Multiplied by 2 32 -1(0x7fffffff) The contents of the name stack at the hit The contents of the name stack at the hit With the bottommost element first With the bottommost element first

20 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory20 Example 13-2. select

21 Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Picking

22 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory22 Overview Use a special picking matrix Use a special picking matrix In conjunction with the projection matrix In conjunction with the projection matrix To restrict drawing to a small region of the viewport To restrict drawing to a small region of the viewport Differences from regular selection mode Differences from regular selection mode Usually triggered by an input device Usually triggered by an input device gluPickMatrix() gluPickMatrix() Multiply the current projection matrix by a picking matrix Multiply the current projection matrix by a picking matrix Called prior to multiplying a standard projection matrix Called prior to multiplying a standard projection matrix gluPerspective() or glOrtho() gluPerspective() or glOrtho() Save the projection matrix first Save the projection matrix first

23 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory23 Simple Example glMatrixMode(GL_PROJECTION);glPushMatrix();glLoadIdentity(); gluPickMatrix(...); gluPerspective, glOrtho, gluOrtho2D, or glFrustum /* draw scene for picking ; perform picking */ /* draw scene for picking ; perform picking */glPopMatrix();

24 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory24 gluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4]); Creates a projection matrix Creates a projection matrix Restricts drawing to a small region of the viewport Restricts drawing to a small region of the viewport Be multiplied onto the current matrix stack Be multiplied onto the current matrix stack Parameters Parameters (x, y) : the center of the picking region (x, y) : the center of the picking region In window coordinates ex) cursor location In window coordinates ex) cursor location width and height : the size of the picking region width and height : the size of the picking region In screen coordinates In screen coordinates viewport[] : current viewport boundaries viewport[] : current viewport boundaries glGetIntegerv(GL_VIEWPORT, GLint *viewport) glGetIntegerv(GL_VIEWPORT, GLint *viewport)

25 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory25 Window Coordinates

26 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory26 Miscellaneous Another way to perform picking Another way to perform picking Described in chapter 14 Described in chapter 14 Use color values Use color values To identify different components of an object To identify different components of an object Hints for writing a program with selection Hints for writing a program with selection For 2D drawing programs For 2D drawing programs Easier to do your own picking calculations Easier to do your own picking calculations ex) Bounding boxes for 2D objects ex) Bounding boxes for 2D objects Extremely fast and simple Extremely fast and simple

27 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory27 Example 13-3. picksquare

28 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory28 Example 13-6. pickdepth

29 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory29 pickdepth2

30 Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Feedback

31 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory31 Characteristics Similar to selection Similar to selection The information that is sent back The information that is sent back In selection mode In selection mode Assigned names Assigned names To an array of integer values To an array of integer values In feedback mode In feedback mode Drawing information about transformed primitives Drawing information about transformed primitives To an array of floating-point values To an array of floating-point values Type of primitive, vertex, color, or other data Type of primitive, vertex, color, or other data Transformed by lighting and viewing operations Transformed by lighting and viewing operations glRenderMode(GL_FEEDBACK); glRenderMode(GL_FEEDBACK);

32 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory32 How You Enter and Exit Feedback Mode Call glFeedbackBuffer() Call glFeedbackBuffer() Specify the array to hold the feedback information Specify the array to hold the feedback information Call glRenderMode(GL_FEEDBACK) Call glRenderMode(GL_FEEDBACK) Draw the primitives Draw the primitives Can make several calls to glPassThrough() Can make several calls to glPassThrough() Insert markers into the returned feedback data Insert markers into the returned feedback data Exit feedback mode Exit feedback mode By calling glRenderMode(GL_RENDER) By calling glRenderMode(GL_RENDER) The returned integer value The returned integer value The number of values stored in the feedback array The number of values stored in the feedback array

33 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory33 void glFeedbackBuffer (GLsizei size, GLenum type, GLfloat *buffer); Establishes a buffer for the feedback data Establishes a buffer for the feedback data Must be called before feedback mode is entered Must be called before feedback mode is entered buffer buffer Pointer to an array Pointer to an array size size Maximum number of values Maximum number of values type type Information fed back for each vertex Information fed back for each vertex

34 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory34 glFeedbackBuffer() type Values type Arguments CoordinatesColorTexture Total Values GL_2D x, y --2 GL_3D x, y, z --3 GL_3D_COLOR k-3+k GL_3D_COLOR_TEXTURE k47+k GL_4D_COLOR_TEXTURE x, y, z, w k48+k

35 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory35 The Feedback Array Begins with a code indicating the primitive type Begins with a code indicating the primitive type Followed by the values Followed by the values The primitive’s vertices The primitive’s vertices Associated data Associated data Pass-through markers can be returned Pass-through markers can be returned

36 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory36 Feedback Array Syntax Primitive Type Code Associated Data PointGL_POINT_TOKENvertex Line GL_LINE_TOKEN or GL_LINE_RESET_TOKEN vertex vertex PolygonGL_POLYGON_TOKEN n vertex vertex... vertex BitmapGL_BITMAP_TOKENVertex Pixel Rectangle GL_DRAW_PIXEL_TOKEN or GL_COPY_PIXEL_TOKENVertex Pass-throughGL_PASS_THROUGH_TOKEN a floating-point number

37 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory37 Using Markers in Feedback Mode Feedback occurs after Feedback occurs after Transformations, lighting, polygon culling, and interpretation of polygons Transformations, lighting, polygon culling, and interpretation of polygons By glPolygonMode() By glPolygonMode() Polygons with more than three edges Polygons with more than three edges Broken up into triangles Broken up into triangles Call glPassThrough() Call glPassThrough() Cause GL_PASS_THROUGH_TOKEN to be written into the feedback array Cause GL_PASS_THROUGH_TOKEN to be written into the feedback array To help parse the feedback data To help parse the feedback data To separate the feedback values To separate the feedback values

38 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory38 void glPassThrough (GLfloat token); Inserts a marker into the stream of values in feedback array Inserts a marker into the stream of values in feedback array The marker consists of The marker consists of The code GL_PASS_THROUGH_TOKEN The code GL_PASS_THROUGH_TOKEN Followed by a single floating-point value, token Followed by a single floating-point value, token No effect when called outside of feedback mode No effect when called outside of feedback mode Calling between glBegin() and glEnd() Calling between glBegin() and glEnd() Generates a GL_INVALID_OPERATION error Generates a GL_INVALID_OPERATION error

39 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory39 Example 13-7. feedback

40 Korea University Korea University Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Computer Graphics Laboratory Computer Graphics Laboratory40 glGetIntegerv() GL_MAX_CLIP_PLANES : 6 GL_MAX_CLIP_PLANES : 6 GL_MAX_LIGHTS : 8 GL_MAX_LIGHTS : 8 GL_MAX_MODELVIEW_STACK_DEPTH : 32 GL_MAX_MODELVIEW_STACK_DEPTH : 32 GL_MAX_NAME_STACK_DEPTH : 128 GL_MAX_NAME_STACK_DEPTH : 128 GL_MAX_PROJECTION_STACK_DEPTH : 10 GL_MAX_PROJECTION_STACK_DEPTH : 10 GL_POINT_SIZE_RANGE : 1~64 GL_POINT_SIZE_RANGE : 1~64


Download ppt "Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13."

Similar presentations


Ads by Google