Sie sind auf Seite 1von 6

OpenGL 3D: 3D Modeling Techniques 1.

Recursive subdivision

2. Revolution (lathing)

3. Extrusion

4. Manual assembly from primitives

OpenGL 3D: Glut 3D Primitives void void void void void void glutSolidSphere (Gldouble radius, Glint slices, Glint stacks); glutWireSphere (Gldouble radius, Glint slices, Glint stacks); glutSolidCube (Gldouble size); glutWireCube (Gldouble size); glutSolidCone (Gldouble base, Gldouble height, Glint slices, Glint stacks); glutWireCone (Gldouble base, Gldouble height, Glint slices, Glint stacks);

void glutSolidTorus (GldoubleinnerRadius, Gldouble outerRadius, Glint nsides, Glint rings); void glutWireTorus (GldoubleinnerRadius, Gldouble outerRadius, Glint nsides, Glint rings); void void void void void void void void void void glutSolidDodecahedron (void); glutWireDodecahedron (void); glutSolidOctahedron (void); glutWireOctahedron (void); glutSolidTetrahedron (void); glutWireTetrahedron (void); glutSolidIcosahedron (void); glutWireIcosahedron (void); glutSolidTeapot (Gldouble size); glutWireTeapot (Gldouble size);

Components: Slices Stacks Normals

OpenGL 3D: Quadrics Curves of form a1 x2 + a2 y 2 + a3 z 2 + a4 xy + a5 yz + a6 xz + a7 x + a8 y + a9 z + a10 = 0 Steps in using: 1. Create quadric objects GLUquadricObj* gluNewQuadric(void); Generally only create one May be used for many shapes 2. Specify attributes void gluQuadricDrawStyle(GLUquadricObj *obj, GLenum drawStyle); drawStyle: GLU POINT, GLU LINE, GLU SILHOUETTE, GLU FILL void gluQuadricOrientation(GLUquadricObj *obj, GLenum orientation); orientation: GLU OUTSIDE, GLU INSIDE void gluQuadricNormals(GLUquadricObj *obj, GLenum normals); normals: GLU NONE, GLU FLAT, GLU SMOOTH void gluQuadricTexture(GLUquadricObj *obj, GLboolean textureCoords); textureCoords: GL TRUE, GL FALSE 3. Register error handler void gluQuadricCallback(GLUquadricObj *obj, GLenum type, void(*fn(GLenum)); type: GLU ERROR

OpenGL 3D: Quadrics (2) 4. Draw quadric object void gluSphere(GLUquadricObj *obj, GLdouble radius, GLint slices, GLint stacks); void gluCylinder(GLUquadricObj *obj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks); void gluDisk(GLUquadricObj *obj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint rings); void gluPartialDisk(GLUquadricObj *obj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint rings, GLdouble startAngle, GLdouble sweepAngle); 5. Destroy quadric void gluDeleteQuadric(GLUquadricObj *obj);

OpenGL 3D: Depth Buering OpenGL displays objects in order they are drawn Do not want objects closer to camera obscured by objects farther away Manually drawing objects from back to front problemmatic Programmer must keep track of objects Z coordinates and keep objects ordered by Z values Prohibits change of perspective

Depth (Z) buering Relies on additional buer: Z buer Z buer stores depth info for each pixel

OpenGL 3D: Depth Buering (2) Use described by following algorithm initialize Z-buffer to infinity for (each point of each object) if (point.Z > Z-buffer[point.X][point.Y]) discard point; else { draw point; Z-buffer[point.X][point.Y] <- point.Z; } Relieves programmer of keeping track of depths Properly draws objects regardless order To enable in OpenGL/glut: 1. Initialize glut for depth buering glutInitDisplayMode(GLUT DEPTH); 2. Enable depth buering glEnable(GL DEPTH TEST); 3. Initialize the depth buer (i.e., set to innity) glClear(GL DEPTH BUFFER BIT);