电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

计算机图形学computer graph(1)

20页
  • 卖家[上传人]:资****亨
  • 文档编号:480715889
  • 上传时间:2024-05-07
  • 文档格式:PPT
  • 文档大小:993.50KB
  • / 20 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、Working with CallbacksYuanfeng ZhouShandong University1精选pptObjectivesLearn to build interactive programs using GLUT callbacksMouseKeyboardReshapeIntroduce menus in GLUT2精选pptThe mouse callbackglutMouseFunc(mymouse)void mymouse(GLint button,GLint state,GLint x,GLint y)Returns which button(GLUT_LEFT_BUTTON,GLUT_MIDDLE_BUTTON,GLUT_RIGHT_BUTTON)caused event state of that button(GLUT_UP,GLUT_DOWN)Position in window3精选pptPositioningThe position in the screen window is usually measured in pixels with

      2、the origin at the topleft cornerConsequence of refresh done from top to bottomOpenGL uses a world coordinate system with origin at the bottom leftMust invert y coordinate returned by callback by height of windowy=h y;(0,0)hw4精选pptObtaining the window sizeTo invert the y position we need the window heightHeight can change during program executionTrack with a global variableNew height returned to reshape callback that we will look at in detail soonCan also use query functions glGetIntvglGetFloatvt

      3、o obtain any value that is part of the state5精选pptTerminating a programIn our original programs,there was no way to terminate them through OpenGLWe can use the simple mouse callbackvoid mouse(int btn,int state,int x,int y)if(btn=GLUT_RIGHT_BUTTON&state=GLUT_DOWN)exit(0);6精选pptUsing the mouse positionIn the next example,we draw a small square at the location of the mouse each time the left mouse button is clickedThis example does not use the display callback but one is required by GLUT;We can use

      4、 the empty display callback functionmydisplay()7精选pptDrawing squares at cursor locationvoid mymouse(int btn,int state,int x,int y)if(btn=GLUT_RIGHT_BUTTON&state=GLUT_DOWN)exit(0);if(btn=GLUT_LEFT_BUTTON&state=GLUT_DOWN)drawSquare(x,y);void drawSquare(int x,int y)y=w-y;/*invert y position*/glColor3ub(char)rand()%256,(char)rand)%256,(char)rand()%256);/*a random color*/glBegin(GL_POLYGON);glVertex2f(x+size,y+size);glVertex2f(x-size,y+size);glVertex2f(x-size,y-size);glVertex2f(x+size,y-size);glEnd()

      5、;8精选pptUsing the motion callbackWe can draw squares(or anything else)continuously as long as a mouse button is depressed by using the motion callbackglutMotionFunc(drawSquare)We can draw squares without depressing a button using the passive motion callbackglutPassiveMotionFunc(drawSquare)9精选pptUsing the keyboardglutKeyboardFunc(mykey)void mykey(unsigned char key,int x,int y)Returns ASCII code of key depressed and mouse locationvoid mykey()if(key=Q|key=q)exit(0);10精选pptSpecial and Modifier KeysGL

      6、UT defines the special keys in glut.hFunction key 1:GLUT_KEY_F1Up arrow key:GLUT_KEY_UPif(key=GLUT_KEY_F1 Can also check of one of the modifiersGLUT_ACTIVE_SHIFTGLUT_ACTIVE_CTRLGLUT_ACTIVE_ALTis depressed byglutGetModifiers()Allows emulation of threebutton mouse with one or twobutton mice11精选pptReshaping the windowWe can reshape and resize the OpenGL display window by pulling the corner of the windowWhat happens to the display?Must redraw from applicationTwo possibilitiesDisplay part of worldDis

      7、play whole world but force to fit in new windowCan alter aspect ratio12精选pptReshape possiblitiesoriginalreshaped13精选pptThe Reshape callbackglutReshapeFunc(myreshape)void myreshape(int w,int h)Returns width and height of new window(in pixels)A redisplay is posted automatically at end of execution of the callbackGLUT has a default reshape callback but you probably want to define your ownThe reshape callback is good place to put viewing functions because it is invoked when the window is first opene

      8、d14精选pptExample ReshapeThis reshape preserves shapes by making the viewport and world window have the same aspect ratiovoid myReshape(int w,int h)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);/*switch matrix mode*/glLoadIdentity();if(w=h)gluOrtho2D(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w);else gluOrtho2D(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-2.0,2.0);glMatrixMode(GL_MODELVIEW);/*return to modelview mode*/15精选pptToolkits and WidgetsMost window systems provi

      9、de a toolkit or library of functions for building user interfaces that use special types of windows called widgetsWidget sets include tools such asMenusSlidebarsDialsInput boxesBut toolkits tend to be platform dependentGLUT provides a few widgets including menus16精选pptMenusGLUT supports popup menusA menu can have submenusThree stepsDefine entries for the menuDefine action for each menu itemAction carried out if entry selectedAttach menu to a mouse button17精选pptDefining a simple menuIn main.cmenu

      10、_id=glutCreateMenu(mymenu);glutAddmenuEntry(“clear Screen,1);gluAddMenuEntry(“exit,2);glutAttachMenu(GLUT_RIGHT_BUTTON);entries that appear whenright button depressedidentifiersclear screenexit18精选pptMenu actionsMenu callbackNote each menu has an id that is returned when it is createdAdd submenus byglutAddSubMenu(char*submenu_name,submenu id)void mymenu(int id)if(id=1)glClear();if(id=2)exit(0);entry in parent menu19精选pptOther functions in GLUTDynamic WindowsCreate and destroy during executionSub

      《计算机图形学computer graph(1)》由会员资****亨分享,可在线阅读,更多相关《计算机图形学computer graph(1)》请在金锄头文库上搜索。

      点击阅读更多内容
    最新标签
    监控施工 信息化课堂中的合作学习结业作业七年级语文 发车时刻表 长途客运 入党志愿书填写模板精品 庆祝建党101周年多体裁诗歌朗诵素材汇编10篇唯一微庆祝 智能家居系统本科论文 心得感悟 雁楠中学 20230513224122 2022 公安主题党日 部编版四年级第三单元综合性学习课件 机关事务中心2022年全面依法治区工作总结及来年工作安排 入党积极分子自我推荐 世界水日ppt 关于构建更高水平的全民健身公共服务体系的意见 空气单元分析 哈里德课件 2022年乡村振兴驻村工作计划 空气教材分析 五年级下册科学教材分析 退役军人事务局季度工作总结 集装箱房合同 2021年财务报表 2022年继续教育公需课 2022年公需课 2022年日历每月一张 名词性从句在写作中的应用 局域网技术与局域网组建 施工网格 薪资体系 运维实施方案 硫酸安全技术 柔韧训练 既有居住建筑节能改造技术规程 建筑工地疫情防控 大型工程技术风险 磷酸二氢钾 2022年小学三年级语文下册教学总结例文 少儿美术-小花 2022年环保倡议书模板六篇 2022年监理辞职报告精选 2022年畅想未来记叙文精品 企业信息化建设与管理课程实验指导书范本 草房子读后感-第1篇 小数乘整数教学PPT课件人教版五年级数学上册 2022年教师个人工作计划范本-工作计划 国学小名士经典诵读电视大赛观后感诵读经典传承美德 医疗质量管理制度 2
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.