




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1ObjectivesLearn to build more sophisticated interactive programs using PickingSelect objects from the displayThree methodsRubberbandingInteractive drawing of lines and rectanglesDisplay ListsRetained mode graphics 牛牛文库文档分享2PickingIdentify a user-defined object on the displayIn principle, it should
2、be simple because the mouse gives the position and we should be able to determine to which object(s) a position correspondsPractical difficultiesPipeline architecture is feed forward, hard to go from screen back to worldComplicated by screen being 2D, world is 3DHow close do we have to come to objec
3、t to say we selected it? 牛牛文库文档分享3Three ApproachesHit listMost general approach but most difficult to implementUse back or some other buffer to store object ids as the objects are renderedRectangular maps Easy to implement for many applicationsSee paint program in text 牛牛文库文档分享4Rendering ModesOpenGL
4、 can render in one of three modes selected by glRenderMode(mode)GL_RENDER: normal rendering to the frame buffer (default)GL_FEEDBACK: provides list of primitives rendered but no output to the frame bufferGL_SELECTION: Each primitive in the view volume generates a hit record that is placed in a name
5、stack which can be examined later 牛牛文库文档分享5Selection Mode FunctionsglSelectBuffer(): specifies name bufferglInitNames(): initializes name bufferglPushName(id): push id on name bufferglPopName(): pop top of name bufferglLoadName(id): replace top name on bufferid is set by application program to ident
6、ify objects 牛牛文库文档分享6Using Selection ModeInitialize name bufferEnter selection mode (using mouse)Render scene with user-defined identifiersReenter normal render modeThis operation returns number of hitsExamine contents of name buffer (hit records)Hit records include id and depth information 牛牛文库文档分享
7、7Selection Mode and PickingAs we just described it, selection mode wont work for picking because every primitive in the view volume will generate a hitChange the viewing parameters so that only those primitives near the cursor are in the altered view volumeUse gluPickMatrix (see text for details) 牛牛
8、文库文档分享8Using Regions of the ScreenMany applications use a simple rectangular arrangement of the screenExample: paint/CAD programEasier to look at mouse position and determine which area of screen it is in than using selection mode pickingdrawing areatoolsmenus 牛牛文库文档分享9Using another buffer and color
9、s for pickingFor a small number of objects, we can assign a unique color (often in color index mode) to each objectWe then render the scene to a color buffer other than the front buffer so the results of the rendering are not visibleWe then get the mouse position and use glReadPixels() to read the c
10、olor in the buffer we just wrote at the position of the mouseThe returned color gives the id of the object 牛牛文库文档分享10Writing Modesframe bufferapplicationbitwise logical operation 牛牛文库文档分享11XOR writeUsual (default) mode: source replaces destination (d = s)Cannot write temporary lines this way because
11、 we cannot recover what was “under” the line in a fast simple wayExclusive OR mode (XOR) (d = d s)x y x =yHence, if we use XOR mode to write a line, we can draw it a second time and line is erased!glLogicOp(mode); mode:GL_XOR 牛牛文库文档分享12RubberbandingSwitch to XOR write modeDraw objectFor line can use
12、 first mouse click to fix one endpoint and then use motion callback to continuously update the second endpointEach time mouse is moved, redraw line which erases it and then draw line from fixed first position to to new second positionAt end, switch back to normal drawing mode and draw lineWorks for
13、other objects: rectangles, circles 牛牛文库文档分享13Rubberband Linesinitial displaydraw line with mouse in XOR modemouse moved to new positionfirst pointsecond pointoriginal line redrawn with XORnew line drawn with XOR 牛牛文库文档分享14XOR in OpenGLThere are 16 possible logical operations between two bitsAll are
14、supported by OpenGLMust first enable logical operationsglEnable(GL_COLOR_LOGIC_OP)Choose logical operationglLogicOp(GL_XOR)glLogicOp(GL_COPY) (default) 牛牛文库文档分享15Immediate and Retained ModesRecall that in a standard OpenGL program, once an object is rendered there is no memory of it and to redisplay
15、 it, we must re-execute the code for itKnown as immediate mode graphicsCan be especially slow if the objects are complex and must be sent over a networkAlternative is define objects and keep them in some form that can be redisplayed easilyRetained mode graphicsAccomplished in OpenGL via display list
16、s 牛牛文库文档分享16Display ListsConceptually similar to a graphics fileMust define (name, create)Add contentsCloseIn client-server environment, display list is placed on serverCan be redisplayed without sending primitives over network each time 牛牛文库文档分享17Display List FunctionsCreating a display listGLuint
17、id;void init() id = glGenLists( 1 ); glNewList( id, GL_COMPILE ); /* other OpenGL routines */ glEndList();Call a created listvoid display() glCallList( id ); 牛牛文库文档分享18Display Lists and StateMost OpenGL functions can be put in display listsState changes made inside a display list persist after the display list is executedCan avoid unexpected results by using glPushAttrib and glPushMatrix upon entering a display list and glPopAttrib and glPopMatrix bef
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论