40
Korea Universit Korea Universit Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Jung Lee, [email protected] Chapter 13. Chapter 13. Selection and Feedback Selection and Feedback OpenGL Programming Guide Third Edition OpenGL Programming Guide Third Edition Presented by Jung Lee Presented by Jung Lee

Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, [email protected] [email protected] Chapter 13

Embed Size (px)

Citation preview

Page 1: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Computer Graphics LaboratoryComputer Graphics LaboratoryJung Lee, Jung Lee, [email protected]

Chapter 13.Chapter 13.Selection and FeedbackSelection and Feedback

OpenGL Programming Guide Third EditionOpenGL Programming Guide Third Edition

Presented by Jung LeePresented by Jung Lee

Page 2: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory22

Chapter ObjectivesChapter Objectives

Select a regionSelect a region of the screen of the screen

Pick an objectPick an object drawn on the screen drawn on the screen

Use the Use the OpenGL feedback modeOpenGL feedback mode To obtain the results of rendering calculationsTo obtain the results of rendering calculations

Page 3: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory33

Interactive ApplicationsInteractive Applications

Identify, modify, delete, and Identify, modify, delete, and manipulatemanipulate

Difficult to know which object is Difficult to know which object is selectedselected Since objects on the screen typically undergoSince objects on the screen typically undergo

Multiple rotations, translations, and perspective Multiple rotations, translations, and perspective transformationstransformations

Page 4: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory44

Selection and Feedback ModesSelection and Feedback Modes

In both selection and feedback modesIn both selection and feedback modes Drawing informationDrawing information is returned is returned

Rather than being sent to the framebufferRather than being sent to the framebuffer The contents the other buffers are not affectedThe contents the other buffers are not affected

Section overviewSection overview Selection / PickingSelection / Picking

How to use selection mode and related routinesHow to use selection mode and related routines FeedbackFeedback

How to obtain drawing informationHow to obtain drawing information How that information is formattedHow that information is formatted

Page 5: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Computer Graphics LaboratoryComputer Graphics LaboratoryJung Lee, Jung Lee, [email protected]

SelectionSelection

Page 6: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory66

OverviewOverview

ProcessProcess Draw your scene into the framebufferDraw your scene into the framebuffer Enter selection modeEnter selection mode Redraw the sceneRedraw the scene

In selection modeIn selection mode The contents of the framebuffer don’t changeThe contents of the framebuffer don’t change

When exiting selection modeWhen exiting selection mode Returns a list of the primitives that intersect Returns a list of the primitives that intersect

the viewing volumethe viewing volume

Page 7: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory77

HitHit

Each primitive that intersects the Each primitive that intersects the viewing volumeviewing volume Causes a selection hitCauses a selection hit

The list of primitives is returned asThe list of primitives is returned as An array of integer-valued An array of integer-valued namesnames and and Related data – the Related data – the hit recordshit records

Correspond to the current contents of the Correspond to the current contents of the name name stackstack

Page 8: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory88

The Basic Steps (1/2)The Basic Steps (1/2)

Specify the array to be used for the returned hit rSpecify the array to be used for the returned hit recordsecords glSelectBuffer()glSelectBuffer()

Enter selection modeEnter selection mode glRenderMode(GL_SELECT)glRenderMode(GL_SELECT)

Initialize the name stackInitialize the name stack glInitNames() and glPushName()glInitNames() and glPushName()

Page 9: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory99

The Basic Steps (2/2)The Basic Steps (2/2)

Define the viewing volumeDefine the viewing volume Usually different from the viewing volume to draw the Usually different from the viewing volume to draw the

scenescene Save and then restore the current transformation stateSave and then restore the current transformation state

glPushMatrix()glPushMatrix() and and glPopMatrix()glPopMatrix()

Primitive drawing commands and commands Primitive drawing commands and commands to manipulate the name stackto manipulate the name stack Each primitive of interest is assigned an appropriate nameEach primitive of interest is assigned an appropriate name

Exit selection modeExit selection mode Process the returned selection dataProcess the returned selection data

Hit recordsHit records

Page 10: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1010

void glSelectBuffervoid glSelectBuffer(GLsizei (GLsizei sizesize, GLuint *, GLuint *bufferbuffer););

Specify the array to be used for the Specify the array to be used for the returned selection datareturned selection data

bufferbuffer A pointer to an array of unsigned integersA pointer to an array of unsigned integers

sizesize Maximum number of values that can be storedMaximum number of values that can be stored

Page 11: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1111

GLint glRenderModeGLint glRenderMode(GLenum mode);(GLenum mode);

Controls whether the application is inControls whether the application is in Rendering, selection, or feedback modeRendering, selection, or feedback mode

mode mode glGetIntegerv(GL_RENDER_MODE)glGetIntegerv(GL_RENDER_MODE) GL_RENDERGL_RENDER(default), (default), GL_SELECTGL_SELECT, , GL_FEEDBACKGL_FEEDBACK

Before selection/feedback mode is enteredBefore selection/feedback mode is entered glSelectBuffer()glSelectBuffer() or or glFeedbackBuffer()glFeedbackBuffer()

Return value when either mode is exitedReturn value when either mode is exited The number of selection hits orThe number of selection hits or The number of values in the feedback arrayThe number of values in the feedback array Negative value: the array is overflowedNegative value: the array is overflowed

Page 12: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1212

Creating the Name StackCreating the Name Stack

Initialize with Initialize with glInitNames()glInitNames() Add Add integer namesinteger names

While issuing corresponding drawing commandsWhile issuing corresponding drawing commands Commands to manipulate the name stackCommands to manipulate the name stack

glPushName()glPushName(), , glPopName()glPopName(), , glLoadName()glLoadName() Calls are ignored if not in selection modeCalls are ignored if not in selection mode

Same drawing code to simplify your codeSame drawing code to simplify your code For both selection and rendering modesFor both selection and rendering modes

Page 13: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1313

Example 13-1Example 13-1

glInitNames();glInitNames();glPushName();glPushName();

glPushMatrix(); /* save the current transformation state */glPushMatrix(); /* save the current transformation state */

/* create your desired viewing volume here *//* create your desired viewing volume here */glLoadName(1);glLoadName(1);drawSomeObject();drawSomeObject();glLoadName(2);glLoadName(2);drawAnotherObject();drawAnotherObject();glLoadName(3);glLoadName(3);drawYetAnotherObject();drawYetAnotherObject();drawJustOneMoreObject();drawJustOneMoreObject();

glPopMatrix(); /* restore the previous transformation state */glPopMatrix(); /* restore the previous transformation state */

Page 14: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1414

void glInitNames(void);void glInitNames(void);

Clears the name stackClears the name stack

Page 15: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1515

void glPushNamevoid glPushName(GLuint name);(GLuint name);

Pushes name onto the name stackPushes name onto the name stack Pushing a name beyond the capacity of the stack Pushing a name beyond the capacity of the stack

generates errorgenerates error GL_STACK_OVERFLOWGL_STACK_OVERFLOW

The name stack’s depthThe name stack’s depth Vary among different OpenGL implementationsVary among different OpenGL implementations At least 64 namesAt least 64 names glGetIntegerv(GL_NAME_STACK_DEPTH)glGetIntegerv(GL_NAME_STACK_DEPTH)

Page 16: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1616

void glPopName(void);void glPopName(void);

Pops a name off the top of the name Pops a name off the top of the name stackstack

Popping an empty stackPopping an empty stack Generates the error, Generates the error, GL_STACK_UNDERFLOWGL_STACK_UNDERFLOW

Page 17: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1717

void glLoadNamevoid glLoadName(GLuint name);(GLuint name);

Replace the value at the top of the Replace the value at the top of the name stack with name stack with namename

If the stack is emptyIf the stack is empty Generates the error, Generates the error, GL_INVALID_OPERATIONGL_INVALID_OPERATION

Page 18: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1818

The Hit RecordThe Hit Record

Whenever a name stack manipulation command is exeWhenever a name stack manipulation command is executed orcuted or

glRenderMode()glRenderMode() is called is called Written into the selection arrayWritten into the selection array

If there has been a hit since the last timeIf there has been a hit since the last time Valid coordinates produced by Valid coordinates produced by glRasterPos()glRasterPos()

Can cause a selection hitCan cause a selection hit If the polygon would have been culledIf the polygon would have been culled

No hit occursNo hit occurs

Page 19: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory1919

Contents of the Hit RecordContents of the Hit Record

The number of names on the name The number of names on the name stackstack

Both the minimum and maximum z-Both the minimum and maximum z-valuesvalues Of all vertices of the primitivesOf all vertices of the primitives Lie in the range [0, 1]Lie in the range [0, 1] Multiplied by 2Multiplied by 23232-1(0x7fffffff)-1(0x7fffffff)

The contents of the name stack at the The contents of the name stack at the hithit With the bottommost element firstWith the bottommost element first

Page 20: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2020

Example 13-2. selectExample 13-2. select

Page 21: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Computer Graphics LaboratoryComputer Graphics LaboratoryJung Lee, Jung Lee, [email protected]

PickingPicking

Page 22: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2222

OverviewOverview

Use a special picking matrixUse a special picking matrix In conjunction with the projection matrixIn conjunction with the projection matrix

To restrict drawing to a small region of the viewportTo restrict drawing to a small region of the viewport

Differences from regular selection modeDifferences from regular selection mode Usually triggered by an input deviceUsually triggered by an input device gluPickMatrix()gluPickMatrix()

Multiply the current projection matrix by a picking matrixMultiply the current projection matrix by a picking matrix Called prior to multiplying a standard projection matrixCalled prior to multiplying a standard projection matrix

gluPerspective()gluPerspective() or or glOrtho()glOrtho() Save the projection matrix firstSave the projection matrix first

Page 23: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2323

Simple ExampleSimple Example

glMatrixMode(GL_PROJECTION);glMatrixMode(GL_PROJECTION);

glPushMatrix();glPushMatrix();

glLoadIdentity();glLoadIdentity();

gluPickMatrixgluPickMatrix(...);(...);

gluPerspective, glOrtho, gluOrtho2D, or glFrustumgluPerspective, glOrtho, gluOrtho2D, or glFrustum

/* draw scene for picking ; perform picking *//* draw scene for picking ; perform picking */

glPopMatrix();glPopMatrix();

Page 24: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2424

gluPickMatrix(GLdouble x, GLdouble y, GLdoublgluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4]);e width, GLdouble height, GLint viewport[4]);

Creates a projection matrixCreates a projection matrix Restricts drawing to a small region of the viewportRestricts drawing to a small region of the viewport Be multiplied onto the current matrix stackBe multiplied onto the current matrix stack

ParametersParameters (x, y)(x, y): the center of the picking region: the center of the picking region

In window coordinates ex) cursor locationIn window coordinates ex) cursor location widthwidth and and heightheight: the size of the picking region: the size of the picking region

In screen coordinatesIn screen coordinates viewport[]viewport[]: current viewport boundaries: current viewport boundaries

glGetIntegerv(GL_VIEWPORT, GLint *viewport)glGetIntegerv(GL_VIEWPORT, GLint *viewport)

Page 25: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2525

Window CoordinatesWindow Coordinates

Page 26: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2626

MiscellaneousMiscellaneous

Another way to perform pickingAnother way to perform picking Described in chapter 14Described in chapter 14

Use color valuesUse color values To identify different components of an objectTo identify different components of an object

Hints for writing a program with Hints for writing a program with selectionselection For 2D drawing programsFor 2D drawing programs

Easier to do your own picking calculationsEasier to do your own picking calculations ex) Bounding boxes for 2D objectsex) Bounding boxes for 2D objects

Extremely fast and simpleExtremely fast and simple

Page 27: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2727

Example 13-3. picksquareExample 13-3. picksquare

Page 28: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2828

Example 13-6. pickdepthExample 13-6. pickdepth

Page 29: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory2929

pickdepth2pickdepth2

Page 30: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Computer Graphics LaboratoryComputer Graphics LaboratoryJung Lee, Jung Lee, [email protected]

FeedbackFeedback

Page 31: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3131

CharacteristicsCharacteristics

Similar to selectionSimilar to selection The information that is sent backThe information that is sent back

In selection modeIn selection mode Assigned namesAssigned names

To an array of integer valuesTo an array of integer values In feedback modeIn feedback mode

Drawing informationDrawing information about transformed primitives about transformed primitives To an array of floating-point valuesTo an array of floating-point values Type of primitive, vertex, color, or other dataType of primitive, vertex, color, or other data Transformed by lighting and viewing operationsTransformed by lighting and viewing operations

glRenderMode(GL_FEEDBACK);glRenderMode(GL_FEEDBACK);

Page 32: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3232

How You Enter and Exit How You Enter and Exit Feedback ModeFeedback Mode

Call Call glFeedbackBuffer()glFeedbackBuffer() Specify the array to hold the feedback informationSpecify the array to hold the feedback information

Call Call glRenderMode(GL_FEEDBACK)glRenderMode(GL_FEEDBACK) Draw the primitivesDraw the primitives

Can make several calls to Can make several calls to glPassThrough()glPassThrough() Insert markers into the returned feedback dataInsert markers into the returned feedback data

Exit feedback modeExit feedback mode By calling By calling glRenderMode(GL_RENDER)glRenderMode(GL_RENDER)

The returned integer valueThe returned integer value The number of values stored in the feedback arrayThe number of values stored in the feedback array

Page 33: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3333

void glFeedbackBuffervoid glFeedbackBuffer(GLsizei size, GLenum type, GLfloat *bu(GLsizei size, GLenum type, GLfloat *buffer);ffer); Establishes a buffer for the feedback Establishes a buffer for the feedback

datadata Must be called before feedback mode is Must be called before feedback mode is

enteredentered bufferbuffer

Pointer to an arrayPointer to an array sizesize

Maximum number of valuesMaximum number of values typetype

Information fed back for each vertexInformation fed back for each vertex

Page 34: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3434

glFeedbackBuffer()glFeedbackBuffer() typetype Values Values

typetype Arguments Arguments CoordinatCoordinateses

ColoColorr

TexturTexturee

Total Total ValuesValues

GL_2DGL_2D x, yx, y -- -- 22

GL_3DGL_3D x, y, zx, y, z -- -- 33

GL_3D_COLORGL_3D_COLOR x, y, zx, y, z kk -- 3+k3+k

GL_3D_COLOR_TEXTUREGL_3D_COLOR_TEXTURE x, y, zx, y, z kk 44 7+k7+k

GL_4D_COLOR_TEXTUREGL_4D_COLOR_TEXTURE x, y, z, wx, y, z, w kk 44 8+k8+k

<Table 13-1><Table 13-1>

Page 35: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3535

The Feedback ArrayThe Feedback Array

Begins with a code indicating the Begins with a code indicating the primitive typeprimitive type Followed by the valuesFollowed by the values

The primitive’s verticesThe primitive’s vertices Associated dataAssociated data Pass-through markers can be returnedPass-through markers can be returned

Page 36: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3636

Feedback Array SyntaxFeedback Array SyntaxPrimitive Primitive

TypeType CodeCode Associated Associated DataData

PointPoint GL_POINT_TOKENGL_POINT_TOKEN vertexvertex

LineLineGL_LINE_TOKEN GL_LINE_TOKEN oror

GL_LINE_RESET_TOKENGL_LINE_RESET_TOKENvertex vertexvertex vertex

PolygonPolygon GL_POLYGON_TOKENGL_POLYGON_TOKEN nn vertex vertex ... vert vertex vertex ... vertexex

BitmapBitmap GL_BITMAP_TOKENGL_BITMAP_TOKEN VertexVertex

Pixel Pixel RectangleRectangle

GL_DRAW_PIXEL_TOKEN GL_DRAW_PIXEL_TOKEN oror

GL_COPY_PIXEL_TOKENGL_COPY_PIXEL_TOKENVertexVertex

Pass-Pass-throughthrough

GL_PASS_THROUGH_TOKENGL_PASS_THROUGH_TOKEN a floating-point a floating-point numbernumber<Table 13-2><Table 13-2>

Page 37: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3737

Using Markers in Using Markers in Feedback ModeFeedback Mode

Feedback occurs afterFeedback occurs after Transformations, lighting, polygon culling, and interpreTransformations, lighting, polygon culling, and interpre

tation of polygonstation of polygons By By glPolygonMode()glPolygonMode()

Polygons with more than three edgesPolygons with more than three edges Broken up into trianglesBroken up into triangles

Call Call glPassThrough()glPassThrough() Cause Cause GL_PASS_THROUGH_TOKENGL_PASS_THROUGH_TOKEN to be written into t to be written into t

he feedback arrayhe feedback array To help parse the feedback dataTo help parse the feedback data To separate the feedback valuesTo separate the feedback values

Page 38: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3838

void glPassThroughvoid glPassThrough(GLfloat token);(GLfloat token);

Inserts a Inserts a markermarker into the stream of values in fee into the stream of values in feedback arraydback array

The marker consists ofThe marker consists of The code The code GL_PASS_THROUGH_TOKENGL_PASS_THROUGH_TOKEN Followed by a single floating-point value, tokenFollowed by a single floating-point value, token

No effect when called outside of feedback modeNo effect when called outside of feedback mode Calling between Calling between glBegin()glBegin() and and glEnd()glEnd()

Generates a Generates a GL_INVALID_OPERATIONGL_INVALID_OPERATION error error

Page 39: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory3939

Example 13-7. feedbackExample 13-7. feedback

Page 40: Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, airjung@korea.ac.kr airjung@korea.ac.kr Chapter 13

Korea UniversityKorea University

Jung Lee, Jung Lee, [email protected] Computer Graphics LaboratoryComputer Graphics Laboratory4040

glGetIntegerv()glGetIntegerv()

GL_MAX_CLIP_PLANESGL_MAX_CLIP_PLANES: 6: 6 GL_MAX_LIGHTSGL_MAX_LIGHTS: 8: 8 GL_MAX_MODELVIEW_STACK_DEPTHGL_MAX_MODELVIEW_STACK_DEPTH: 32: 32 GL_MAX_NAME_STACK_DEPTHGL_MAX_NAME_STACK_DEPTH: 128: 128 GL_MAX_PROJECTION_STACK_DEPTHGL_MAX_PROJECTION_STACK_DEPTH: 10: 10 GL_POINT_SIZE_RANGEGL_POINT_SIZE_RANGE: 1~64: 1~64