Korea University Chapter 13 Selection and Feedback Open
Korea University Chapter 13. Selection and Feedback Open. GL Programming Guide Third Edition Presented by Jung Lee, airjung@korea. ac. kr Computer Graphics Laboratory
Korea University Chapter Objectives n Select a region of the screen n Pick an object drawn on the screen n Use the Open. GL feedback mode n To obtain the results of rendering calculations Jung Lee, airjung@korea. ac. kr 2 Computer Graphics Laboratory
Korea University Interactive Applications n Identify, modify, delete, and manipulate n Difficult to know which object is selected n Since objects on the screen typically undergo n Multiple rotations, translations, and perspective transformations Jung Lee, airjung@korea. ac. kr 3 Computer Graphics Laboratory
Korea University Selection and Feedback Modes n In both selection and feedback modes n Drawing information is returned n n n Rather than being sent to the framebuffer The contents the other buffers are not affected Section overview n Selection / Picking n n How to use selection mode and related routines Feedback n n How to obtain drawing information How that information is formatted Jung Lee, airjung@korea. ac. kr 4 Computer Graphics Laboratory
Korea University Selection Jung Lee, airjung@korea. ac. kr Computer Graphics Laboratory
Korea University Overview n Process n n In selection mode n n Draw your scene into the framebuffer Enter selection mode Redraw the scene The contents of the framebuffer don’t change When exiting selection mode n Returns a list of the primitives that intersect the viewing volume Jung Lee, airjung@korea. ac. kr 6 Computer Graphics Laboratory
Korea University Hit n Each primitive that intersects the viewing volume n n Causes a selection hit The list of primitives is returned as n An array of integer-valued names and n Related data – the hit records n Correspond to the current contents of the name stack Jung Lee, airjung@korea. ac. kr 7 Computer Graphics Laboratory
Korea University The Basic Steps (1/2) n Specify the array to be used for the returned hit records n n Enter selection mode n n gl. Select. Buffer() gl. Render. Mode(GL_SELECT) Initialize the name stack n gl. Init. Names() and gl. Push. Name() Jung Lee, airjung@korea. ac. kr 8 Computer Graphics Laboratory
Korea University The Basic Steps (2/2) n Define the viewing volume n Usually different from the viewing volume to draw the scene n Save and then restore the current transformation state n n gl. Push. Matrix() and gl. Pop. Matrix() Primitive drawing commands and commands to manipulate the name stack n Each primitive of interest is assigned an appropriate name n Exit selection mode n Process the returned selection data n Hit records Jung Lee, airjung@korea. ac. kr 9 Computer Graphics Laboratory
Korea University void gl. Select. Buffer (GLsizei size, GLuint *buffer); n n Specify the array to be used for the returned selection data buffer n n A pointer to an array of unsigned integers size n Maximum number of values that can be stored Jung Lee, airjung@korea. ac. kr 10 Computer Graphics Laboratory
Korea University GLint gl. Render. Mode (GLenum mode); n Controls whether the application is in n n mode gl. Get. Integerv(GL_RENDER_MODE) n n GL_RENDER(default), GL_SELECT, GL_FEEDBACK Before selection/feedback mode is entered n n Rendering, selection, or feedback mode gl. Select. Buffer() or gl. Feedback. Buffer() Return value when either mode is exited n The number of selection hits or n The number of values in the feedback array n Negative value: the array is overflowed Jung Lee, airjung@korea. ac. kr 11 Computer Graphics Laboratory
Korea University Creating the Name Stack n Initialize with gl. Init. Names() n Add integer names n n Commands to manipulate the name stack n n While issuing corresponding drawing commands gl. Push. Name(), gl. Pop. Name(), gl. Load. Name() Calls are ignored if not in selection mode n Same drawing code to simplify your code n For both selection and rendering modes Jung Lee, airjung@korea. ac. kr 12 Computer Graphics Laboratory
Korea University Example 13 -1 gl. Init. Names(); gl. Push. Name(); gl. Push. Matrix(); /* save the current transformation state */ /* create your desired viewing volume here */ gl. Load. Name(1); draw. Some. Object(); gl. Load. Name(2); draw. Another. Object(); gl. Load. Name(3); draw. Yet. Another. Object(); draw. Just. One. More. Object(); gl. Pop. Matrix(); /* restore the previous transformation state */ Jung Lee, airjung@korea. ac. kr 13 Computer Graphics Laboratory
Korea University void gl. Init. Names(void); n Clears the name stack Jung Lee, airjung@korea. ac. kr 14 Computer Graphics Laboratory
Korea University void gl. Push. Name (GLuint name); n n Pushes name onto the name stack Pushing a name beyond the capacity of the stack generates error n n GL_STACK_OVERFLOW The name stack’s depth n n n Vary among different Open. GL implementations At least 64 names gl. Get. Integerv(GL_NAME_STACK_DEPTH) Jung Lee, airjung@korea. ac. kr 15 Computer Graphics Laboratory
Korea University void gl. Pop. Name(void); n Pops a name off the top of the name stack n Popping an empty stack n Generates the error, GL_STACK_UNDERFLOW Jung Lee, airjung@korea. ac. kr 16 Computer Graphics Laboratory
Korea University void gl. Load. Name (GLuint name); n n Replace the value at the top of the name stack with name If the stack is empty n Generates the error, GL_INVALID_OPERATION Jung Lee, airjung@korea. ac. kr 17 Computer Graphics Laboratory
Korea University The Hit Record n n n Written into the selection array n n Whenever a name stack manipulation command is executed or gl. Render. Mode() is called If there has been a hit since the last time Valid coordinates produced by gl. Raster. Pos() n n Can cause a selection hit If the polygon would have been culled n No hit occurs Jung Lee, airjung@korea. ac. kr 18 Computer Graphics Laboratory
Korea University Contents of the Hit Record n n The number of names on the name stack Both the minimum and maximum z-values n n Of all vertices of the primitives Lie in the range [0, 1] Multiplied by 232 -1(0 x 7 fffffff) The contents of the name stack at the hit n With the bottommost element first Jung Lee, airjung@korea. ac. kr 19 Computer Graphics Laboratory
Korea University Example 13 -2. select Jung Lee, airjung@korea. ac. kr 20 Computer Graphics Laboratory
Korea University Picking Jung Lee, airjung@korea. ac. kr Computer Graphics Laboratory
Korea University Overview n Use a special picking matrix n In conjunction with the projection matrix n n To restrict drawing to a small region of the viewport Differences from regular selection mode n n Usually triggered by an input device glu. Pick. Matrix() n n Multiply the current projection matrix by a picking matrix Called prior to multiplying a standard projection matrix n n glu. Perspective() or gl. Ortho() Save the projection matrix first Jung Lee, airjung@korea. ac. kr 22 Computer Graphics Laboratory
Korea University Simple Example gl. Matrix. Mode(GL_PROJECTION); gl. Push. Matrix(); gl. Load. Identity(); glu. Pick. Matrix(. . . ); glu. Perspective, gl. Ortho, glu. Ortho 2 D, or gl. Frustum /* draw scene for picking ; perform picking */ gl. Pop. Matrix(); Jung Lee, airjung@korea. ac. kr 23 Computer Graphics Laboratory
Korea University glu. Pick. Matrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4]); n Creates a projection matrix n n n Restricts drawing to a small region of the viewport Be multiplied onto the current matrix stack Parameters n (x, y): the center of the picking region n n width and height: the size of the picking region n n In window coordinates ex) cursor location In screen coordinates viewport[]: current viewport boundaries n gl. Get. Integerv(GL_VIEWPORT, GLint *viewport) Jung Lee, airjung@korea. ac. kr 24 Computer Graphics Laboratory
Korea University Window Coordinates Jung Lee, airjung@korea. ac. kr 25 Computer Graphics Laboratory
Korea University Miscellaneous n Another way to perform picking n Described in chapter 14 n Use color values n n To identify different components of an object Hints for writing a program with selection n For 2 D drawing programs n Easier to do your own picking calculations n ex) Bounding boxes for 2 D objects n Extremely fast and simple Jung Lee, airjung@korea. ac. kr 26 Computer Graphics Laboratory
Korea University Example 13 -3. picksquare Jung Lee, airjung@korea. ac. kr 27 Computer Graphics Laboratory
Korea University Example 13 -6. pickdepth Jung Lee, airjung@korea. ac. kr 28 Computer Graphics Laboratory
Korea University pickdepth 2 Jung Lee, airjung@korea. ac. kr 29 Computer Graphics Laboratory
Korea University Feedback Jung Lee, airjung@korea. ac. kr Computer Graphics Laboratory
Korea University Characteristics n n Similar to selection The information that is sent back n In selection mode n Assigned names n n In feedback mode n Drawing information about transformed primitives n n To an array of integer values To an array of floating-point values Type of primitive, vertex, color, or other data Transformed by lighting and viewing operations gl. Render. Mode(GL_FEEDBACK); Jung Lee, airjung@korea. ac. kr 31 Computer Graphics Laboratory
Korea University How You Enter and Exit Feedback Mode n Call gl. Feedback. Buffer() n n n Specify the array to hold the feedback information Call gl. Render. Mode(GL_FEEDBACK) Draw the primitives n Can make several calls to gl. Pass. Through() n n Insert markers into the returned feedback data Exit feedback mode n By calling gl. Render. Mode(GL_RENDER) n The returned integer value n The number of values stored in the feedback array Jung Lee, airjung@korea. ac. kr 32 Computer Graphics Laboratory
Korea University void gl. Feedback. Buffer (GLsizei size, GLenum type, GLfloat *buffer); n Establishes a buffer for the feedback data n n buffer n n Pointer to an array size n n Must be called before feedback mode is entered Maximum number of values type n Information fed back for each vertex Jung Lee, airjung@korea. ac. kr 33 Computer Graphics Laboratory
Korea University gl. Feedback. Buffer() type Values type Arguments Coordinates Color Texture Total Values GL_2 D x, y - - 2 GL_3 D x, y, z - - 3 GL_3 D_COLOR x, y, z k - 3+k GL_3 D_COLOR_TEXTURE x, y, z k 4 7+k GL_4 D_COLOR_TEXTURE x, y, z, w k 4 8+k <Table 13 -1> Jung Lee, airjung@korea. ac. kr 34 Computer Graphics Laboratory
Korea University The Feedback Array n Begins with a code indicating the primitive type n Followed by the values n The primitive’s vertices n Associated data n Pass-through markers can be returned Jung Lee, airjung@korea. ac. kr 35 Computer Graphics Laboratory
Korea University Feedback Array Syntax Primitive Type Code Associated Data Point GL_POINT_TOKEN vertex Line GL_LINE_TOKEN or GL_LINE_RESET_TOKEN vertex Polygon GL_POLYGON_TOKEN n vertex. . . vertex Bitmap GL_BITMAP_TOKEN Vertex Pixel Rectangle GL_DRAW_PIXEL_TOKEN or GL_COPY_PIXEL_TOKEN Vertex Pass-through GL_PASS_THROUGH_TOKEN a floating-point number Jung Lee, airjung@korea. ac. kr <Table 13 -2> 36 Computer Graphics Laboratory
Using Markers in Feedback Mode n Feedback occurs after n Transformations, lighting, polygon culling, and interpretation of polygons n n By gl. Polygon. Mode() Polygons with more than three edges n n Korea University Broken up into triangles Call gl. Pass. Through() n Cause GL_PASS_THROUGH_TOKEN to be written into the feedback array n n To help parse the feedback data To separate the feedback values Jung Lee, airjung@korea. ac. kr 37 Computer Graphics Laboratory
Korea University void gl. Pass. Through (GLfloat token); n n Inserts a marker into the stream of values in feedback array The marker consists of n The code GL_PASS_THROUGH_TOKEN n n n Followed by a single floating-point value, token No effect when called outside of feedback mode Calling between gl. Begin() and gl. End() n Generates a GL_INVALID_OPERATION error Jung Lee, airjung@korea. ac. kr 38 Computer Graphics Laboratory
Korea University Example 13 -7. feedback Jung Lee, airjung@korea. ac. kr 39 Computer Graphics Laboratory
Korea University gl. Get. Integerv() n GL_MAX_CLIP_PLANES: 6 n GL_MAX_LIGHTS: 8 n GL_MAX_MODELVIEW_STACK_DEPTH: 32 n GL_MAX_NAME_STACK_DEPTH: 128 n GL_MAX_PROJECTION_STACK_DEPTH: 10 n GL_POINT_SIZE_RANGE: 1~64 Jung Lee, airjung@korea. ac. kr 40 Computer Graphics Laboratory
- Slides: 40