1 / 20

Quadrics and Display Lists

Quadrics and Display Lists. Jason Goffeney 3/20/2006. Quadrics. The OpenGL utility library contains a set of functions for constructing polygonal quadric surfaces. The primitive shapes: Sphere Cylinder Disk Partial Disk. Quadrics: Construction.

kalb
Télécharger la présentation

Quadrics and Display Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Quadrics and Display Lists Jason Goffeney 3/20/2006

  2. Quadrics • The OpenGL utility library contains a set of functions for constructing polygonal quadric surfaces. • The primitive shapes: • Sphere • Cylinder • Disk • Partial Disk

  3. Quadrics: Construction • A series of steps are followed for the construction of a quadrics. • A generic quadric object is created • The quadric object’s properties are set • The quadric object is passed to one of the quadric primitive functions to create the final object

  4. Quadrics: Construction • The generic quadric object is created by the following call. GLUquadricObj * quadObj = gluNewQuadric(); • It is destroyed by the corresponding call. gluDeleteQuadric(quadObj);

  5. Quadrics: Construction • A single quadric object can be used in the creation of lots of primitive objects. • You don’t need to create a new one for each shape you want to make

  6. Quadric Properties • Several properties can be set in the generic quadric object before it is used to create a primitive shape. • Drawing Style • Normal Type • Normal Orientation • Texture Coordinates

  7. gluQuadricDrawStyle • void gluQuadricDrawStyle (GLUquadricObj * qobj, GLenum drawStyle) The quadric object GLU_POINT GLU_LINE GLU_SILHOUETTE GLU_FILL

  8. gluQuadricNormals • void gluQuadricNormals (GLUquadricObj * qobj, GLenum normals); The quadric object GLU_NONE GLU_FLAT GLU_SMOOTH

  9. Quadric Primitives: Sphere • void gluSphere(GLUquadricObj * qobj, GLdouble radius, GLint slices, GLint stacks)

  10. Quadric Primitives: Cylinder • void gluCylinder(GLUquadricObj * qobj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks) Note: the resulting cylinder will have an open top and bottom.

  11. Quadric Primitives: Disk • void gluDisk(GLUquadricObj * qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint rings) inner outer

  12. Quadric Primitives: Partial Disk • void gluPartialDisk(GLUquadricObj * qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint rings, GLdouble startAngle, GLdouble sweepAngle) The start angle is the distance from +y axis the disk will start at. The sweep angle is the distance the disk will proceed through. The stop angle is the start angle + sweep angle. This example starts at 45 degrees and sweeps 135 degrees.

  13. Quadric Primitives • Each primitive has a default starting location with the “top” pointing in the +z axis direction (toward the screen). • Each primitive is also created at the origin (0,0,0). You will need to translate it to place it in your scene.

  14. Display Lists • What is it? • A display list is a way of performing a set of OpenGL operations and then saving them to be called at a later time. • Why? • Mainly it is more efficient as some calls are very expensive to perform from scratch (like building a quadric or performing a group of matrix multiplications). • It basically pre-compiles the OpenGL calls and stores them • Also it provides you with an almost database like approach to calling your objects to be used.

  15. Display Lists • int glGenLists(int numLists) • This call takes the number of lists you are going to build and returns an index id number for the first object. • This number is used as a base index for looking up a list. • Example: listIdx = glGenLists(4); //Setup up 4 contiguous list ids … glCallList(listIdx + 2); //Calls the 3rd list

  16. Display Lists • void glNewList(int listIndex, GLenum mode) The display list id number • GL_COMPILE • compile and save for later • GL_COMPILE_AND_EXECUTE • compile and run now • Example: • glNewList(listIdx + 1, GL_COMPILE); //Create 2nd list • //make OpenGL calls here • glEndList(); //Ends the list

  17. Display Lists • void glCallList(int listIndex) • This call invokes the OpenGL commands stored in list listIndex. • If the list is for an object then it will be called during the paint step of your code • Example: listIdx = glGenLists(4); //Setup up 4 contiguous list ids … glCallList(listIdx + 2); //Calls the 3rd list

  18. Display List Usage //Called via initializeGL //Create a new quadric object GLUquadricObj * quadObj = gluNewQuadric(); //Allocate 2 contiguous list id numbers displayIdx = glGenLists(2); //Setup object properties gluQuadricDrawStyle(quadObj, GLU_FILL); gluQuadricNormals(quadObj, GLU_FLAT); //Start List glNewList(displayIdx, GL_COMPILE); glTranslatef(100, 100, -400.0); gluSphere(quadObj, 50, 15, 15); glEndList(); //Setup object properties gluQuadricDrawStyle(quadObj, GLU_FILL); gluQuadricNormals(quadObj, GLU_SMOOTH); //Start List glNewList(displayIdx + 1, GL_COMPILE); glTranslatef(-100, -100, -400.0); gluSphere(quadObj, 50, 15, 15); glEndList(); //Delete the quadric object gluDeleteQuadric(quadObj); • I want to display 2 spheres objects side by side. • Since I am setting these up before any rendering happens I can put them in initializeGL.

  19. Display List Usage • I want to display 2 spheres objects side by side. • Now I can call them in paintGL glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); //Clear Model View Matrix and call 1st list glLoadIdentity(); glCallList(displayIdx); //Clear Model View Matrix and call 2nd list glLoadIdentity(); glCallList(displayIdx + 1);

  20. Other Display List Uses • Load an entire model and perform the drawing as a list. • Rather than allocating a set of list indices using glGenLists with a number of lists as a parameter, you can call it for each object with a value of 1 as the parameter. If you store the returned value in some data structure then you can have as many lists as you want.

More Related