计算机图形学computergraphics课件5.ppt
《计算机图形学computergraphics课件5.ppt》由会员分享,可在线阅读,更多相关《计算机图形学computergraphics课件5.ppt(23页珍藏版)》请在第壹文秘上搜索。
1、1Programming with OpenGLPart 2:Complete Programs2ObjectivesRefine the first program Alter the default values Introduce a standard program structureSimple viewing Twodimensional viewing as a special case of threedimensional viewingFundamental OpenGL primitivesAttributes3Program Structure Most OpenGL
2、programs have a similar structure that consists of the following functionsmain():defines the callback functions opens one or more windows with the required properties enters event loop(last executable statement)init():sets the state variables Viewing Attributes callbacks Display function Input and w
3、indow functions4simple.c revisitedIn this version,we shall see the same output but we have defined all the relevant state values through function calls using the default valuesIn particular,we set Colors Viewing conditions Window properties5simple.c#include void mydisplay()glClear(GL_COLOR_BUFFER_BI
4、T);/glColor3f(1.0f,0.0f,0.0f);glBegin(GL_POLYGON);glVertex2f(-0.5,-0.5);glVertex2f(-0.5,0.5);glVertex2f(0.5,0.5);glVertex2f(0.5,-0.5);glEnd();glFlush();int main(int argc,char*argv)glutCreateWindow(simple);glutDisplayFunc(mydisplay);glutMainLoop();6main.c#include int main(int argc,char*argv)glutInit(
5、&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(500,500);glutInitWindowPosition(0,0);glutCreateWindow(simple);glutDisplayFunc(mydisplay);init();glutMainLoop();includes gl.hdefine window propertiesset OpenGL stateenter event loopdisplay callback7GLUT functionsglutInit allows
6、application to get command line arguments and initializes systemgluInitDisplayMode requests properties for the window(the rendering context)RGB color Single buffering Properties logically ORed togetherglutWindowSize in pixelsglutWindowPosition from topleft corner of displayglutCreateWindow create wi
7、ndow with title“simple”glutDisplayFunc display callbackglutMainLoop enter infinite event loop8init.cvoid init()glClearColor(0.0,0.0,0.0,1.0);glColor3f(1.0,1.0,1.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);black clear coloropaque windowfill/draw with whiteviewi
8、ng volume9Coordinate SystemsThe units in glVertex are determined by the application and are called object or world coordinatesThe viewing specifications are also in object coordinates and it is the size of the viewing volume that determines what will appear in the imageInternally,OpenGL will convert
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 图形学 computergraphics 课件