Quadrics and Display Lists

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

description

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. - PowerPoint PPT Presentation

Transcript of Quadrics and Display Lists

Page 1: Quadrics and Display Lists

Quadrics and Display Lists

Jason Goffeney

3/20/2006

Page 2: Quadrics and Display Lists

Quadrics

• The OpenGL utility library contains a set of functions for constructing polygonal quadric surfaces.

• The primitive shapes:– Sphere– Cylinder– Disk– Partial Disk

Page 3: Quadrics and Display Lists

Quadrics: Construction

• A series of steps are followed for the construction of a quadrics.

1. A generic quadric object is created

2. The quadric object’s properties are set

3. The quadric object is passed to one of the quadric primitive functions to create the final object

Page 4: Quadrics and Display Lists

Quadrics: Construction

• The generic quadric object is created by the following call.

GLUquadricObj * quadObj = gluNewQuadric();

• It is destroyed by the corresponding call.

gluDeleteQuadric(quadObj);

Page 5: Quadrics and Display Lists

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

Page 6: Quadrics and Display Lists

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

Page 7: Quadrics and Display Lists

gluQuadricDrawStyle

• void gluQuadricDrawStyle (GLUquadricObj * qobj, GLenum drawStyle)

The quadric object

GLU_POINT GLU_LINEGLU_SILHOUETTEGLU_FILL

Page 8: Quadrics and Display Lists

gluQuadricNormals

• void gluQuadricNormals (GLUquadricObj * qobj, GLenum normals);

The quadric object

GLU_NONEGLU_FLATGLU_SMOOTH

Page 9: Quadrics and Display Lists

Quadric Primitives: Sphere

• void gluSphere(GLUquadricObj * qobj, GLdouble radius,

GLint slices, GLint stacks)

Page 10: Quadrics and Display Lists

Quadric Primitives: Cylinder

• void gluCylinder(GLUquadricObj * qobj, GLdouble baseRadius,

GLdouble topRadius, GLdouble height,

GLint slices, GLint stacks)

Note: the resultingcylinder will have an opentop and bottom.

Page 11: Quadrics and Display Lists

Quadric Primitives: Disk

• void gluDisk(GLUquadricObj * qobj, GLdouble innerRadius,

GLdouble outerRadius, GLint slices, GLint rings)

inner

outer

Page 12: Quadrics and Display Lists

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 thedisk will proceed through. The stopangle is the start angle + sweep angle.

This example starts at 45 degreesand sweeps 135 degrees.

Page 13: Quadrics and Display Lists

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.

Page 14: Quadrics and Display Lists

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.

Page 15: Quadrics and Display Lists

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

Page 16: Quadrics and Display Lists

Display Lists

• void glNewList(int listIndex, GLenum mode)

The display list id number

GL_COMPILEcompile and save for later

GL_COMPILE_AND_EXECUTEcompile and run now

Example:

glNewList(listIdx + 1, GL_COMPILE); //Create 2nd list

//make OpenGL calls here

glEndList(); //Ends the list

Page 17: Quadrics and Display Lists

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

Page 18: Quadrics and Display Lists

Display List Usage

• 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.

//Called via initializeGL

//Create a new quadric objectGLUquadricObj * quadObj = gluNewQuadric();

//Allocate 2 contiguous list id numbersdisplayIdx = glGenLists(2);

//Setup object propertiesgluQuadricDrawStyle(quadObj, GLU_FILL);gluQuadricNormals(quadObj, GLU_FLAT);

//Start ListglNewList(displayIdx, GL_COMPILE); glTranslatef(100, 100, -400.0); gluSphere(quadObj, 50, 15, 15);glEndList();

//Setup object propertiesgluQuadricDrawStyle(quadObj, GLU_FILL);gluQuadricNormals(quadObj, GLU_SMOOTH);

//Start ListglNewList(displayIdx + 1, GL_COMPILE); glTranslatef(-100, -100, -400.0); gluSphere(quadObj, 50, 15, 15);glEndList();

//Delete the quadric objectgluDeleteQuadric(quadObj);

Page 19: Quadrics and Display Lists

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 listglLoadIdentity(); glCallList(displayIdx);

//Clear Model View Matrix and call 2nd listglLoadIdentity();glCallList(displayIdx + 1);

Page 20: Quadrics and Display Lists

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.