计算机图形学computer graph(1)
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
《计算机图形学computer graph(1)》由会员资****亨分享,可在线阅读,更多相关《计算机图形学computer graph(1)》请在金锄头文库上搜索。
输油设备计算机辅助仿真系统
数显式顶板离层仪B
树立科学发展观(1)
数电组合逻辑电路应用举例、竞争冒险
数电实验0GOS6051型二踪示波器实验一常用电子仪器的使用练习
数电84第五版—康华光
数码裂隙灯图像系统操作
数理统计12主成分分析
数控系统的备份与还原训练
数控技术及应用清华版7数控机床进给伺服系统的控制原理
数据解读PPT(BNU金融协会)
数控技术及应用清华版8数控机床的精度
数控机床故障诊断 (2)
数据质量评估与控制体系-刘思琦组
数控技术及应用清华版17数控机床进给伺服系统的控制原理
数控技术2011-2-数控系统
数控加工工艺与设备》电子教案
数控加工的程序编制车床
数据通信与计算机网络第二版》电子教案西南
数据资料的收集方法
2024-05-14 5页
2024-05-14 6页
2024-05-14 40页
2024-05-14 38页
2024-05-14 15页
2024-05-14 22页
2024-05-14 31页
2024-05-14 42页
2024-05-14 23页
2024-05-14 25页