Programming with OpenGL Part 3: Three dimensions Yuanfeng Zhou Shandong University
1 Programming with OpenGL Part 3: Three Dimensions Yuanfeng Zhou Shandong University
Review Keywords 1.Development 2. State machine 3. Functions(formats), callback function 4. Simple cube program 5.Simple viewing 6. OpenGL primitives(polygon) 7. Attributes(color)
2 Review •Keywords: 1.Development 2.State machine 3.Functions (formats), callback function 4.Simple cube program 5.Simple viewing 6.OpenGL primitives (polygon) 7.Attributes (color)
Objectives Develop a more sophisticated three dimensional example Sierpinski gasket: a fractal Introduce hidden -surface removal Plotting implicit functions
3 Objectives •Develop a more sophisticated threedimensional example - Sierpinski gasket: a fractal •Introduce hidden-surface removal •Plotting implicit functions
Random Sierpinski Gasket
Random Sierpinski Gasket 4
main code void main(int argc, char*x argv) / Standard glut initialization glutlnit (&argc, argv) glutlnitDisplayMode(GLUT SINGLE GLUT RGB) glutlnitWindowSize (500, 500); /*500 X 500 pixel window * glutInitWindowPosition(0,0); /*place window top left on display * glut CreateWindow ("Sierpinski Gasket); /*window title */ glutDisplay Func(display) / display callback invoked when window opened * myinit(; /*set attributes*/ glutMainLoopo; /*enter event loop *
main code void main(int argc, char** argv) { /* Standard GLUT initialization */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); /* 500 × 500 pixel window */ glutInitWindowPosition(0,0); /* place window top left on display */ glutCreateWindow("Sierpinski Gasket"); /* window title */ glutDisplayFunc(display); /* display callback invoked when window opened */ myinit(); /* set attributes */ glutMainLoop(); /* enter event loop */ } 5