Quadrics and Display Lists Jason Goffeney 3202006 Quadrics

  • Slides: 20
Download presentation
Quadrics and Display Lists Jason Goffeney 3/20/2006

Quadrics and Display Lists Jason Goffeney 3/20/2006

Quadrics • The Open. GL utility library contains a set of functions for constructing

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

Quadrics: Construction • A series of steps are followed for the construction of a

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

Quadrics: Construction • The generic quadric object is created by the following call. GLUquadric.

Quadrics: Construction • The generic quadric object is created by the following call. GLUquadric. Obj * quad. Obj = glu. New. Quadric(); • It is destroyed by the corresponding call. glu. Delete. Quadric(quad. Obj);

Quadrics: Construction • A single quadric object can be used in the creation of

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

Quadric Properties • Several properties can be set in the generic quadric object before

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

glu. Quadric. Draw. Style • void glu. Quadric. Draw. Style (GLUquadric. Obj * qobj,

glu. Quadric. Draw. Style • void glu. Quadric. Draw. Style (GLUquadric. Obj * qobj, GLenum draw. Style) The quadric object GLU_POINT GLU_LINE GLU_SILHOUETTE GLU_FILL

glu. Quadric. Normals • void glu. Quadric. Normals (GLUquadric. Obj * qobj, GLenum normals);

glu. Quadric. Normals • void glu. Quadric. Normals (GLUquadric. Obj * qobj, GLenum normals); The quadric object GLU_NONE GLU_FLAT GLU_SMOOTH

Quadric Primitives: Sphere • void glu. Sphere(GLUquadric. Obj * qobj, GLdouble radius, GLint slices,

Quadric Primitives: Sphere • void glu. Sphere(GLUquadric. Obj * qobj, GLdouble radius, GLint slices, GLint stacks)

Quadric Primitives: Cylinder • void glu. Cylinder(GLUquadric. Obj * qobj, GLdouble base. Radius, GLdouble

Quadric Primitives: Cylinder • void glu. Cylinder(GLUquadric. Obj * qobj, GLdouble base. Radius, GLdouble top. Radius, GLdouble height, GLint slices, GLint stacks) Note: the resulting cylinder will have an open top and bottom.

Quadric Primitives: Disk • void glu. Disk(GLUquadric. Obj * qobj, GLdouble inner. Radius, GLdouble

Quadric Primitives: Disk • void glu. Disk(GLUquadric. Obj * qobj, GLdouble inner. Radius, GLdouble outer. Radius, GLint slices, GLint rings) inner outer

Quadric Primitives: Partial Disk • void glu. Partial. Disk(GLUquadric. Obj * qobj, GLdouble inner.

Quadric Primitives: Partial Disk • void glu. Partial. Disk(GLUquadric. Obj * qobj, GLdouble inner. Radius, GLdouble outer. Radius, GLint slices, GLint rings, GLdouble start. Angle, GLdouble sweep. Angle) 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.

Quadric Primitives • Each primitive has a default starting location with the “top” pointing

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.

Display Lists • What is it? – A display list is a way of

Display Lists • What is it? – A display list is a way of performing a set of Open. GL 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 Open. GL calls and stores them – Also it provides you with an almost database like approach to calling your objects to be used.

Display Lists • int gl. Gen. Lists(int num. Lists) • This call takes the

Display Lists • int gl. Gen. Lists(int num. Lists) • 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: list. Idx = gl. Gen. Lists(4); //Setup up 4 contiguous list ids … gl. Call. List(list. Idx + 2); //Calls the 3 rd list

Display Lists • void gl. New. List(int list. Index, GLenum mode) The display list

Display Lists • void gl. New. List(int list. Index, GLenum mode) The display list id number Example: GL_COMPILE compile and save for later GL_COMPILE_AND_EXECUTE compile and run now gl. New. List(list. Idx + 1, GL_COMPILE); //Create 2 nd list //make Open. GL calls here gl. End. List(); //Ends the list

Display Lists • void gl. Call. List(int list. Index) – This call invokes the

Display Lists • void gl. Call. List(int list. Index) – This call invokes the Open. GL commands stored in list. Index. – If the list is for an object then it will be called during the paint step of your code • Example: list. Idx = gl. Gen. Lists(4); //Setup up 4 contiguous list ids … gl. Call. List(list. Idx + 2); //Calls the 3 rd list

Display List Usage //Called via initialize. GL • I want to display 2 spheres

Display List Usage //Called via initialize. GL • 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 initialize. GL. //Create a new quadric object GLUquadric. Obj * quad. Obj = glu. New. Quadric(); //Allocate 2 contiguous list id numbers display. Idx = gl. Gen. Lists(2); //Setup object properties glu. Quadric. Draw. Style(quad. Obj, GLU_FILL); glu. Quadric. Normals(quad. Obj, GLU_FLAT); //Start List gl. New. List(display. Idx, GL_COMPILE); gl. Translatef(100, -400. 0); glu. Sphere(quad. Obj, 50, 15); gl. End. List(); //Setup object properties glu. Quadric. Draw. Style(quad. Obj, GLU_FILL); glu. Quadric. Normals(quad. Obj, GLU_SMOOTH); //Start List gl. New. List(display. Idx + 1, GL_COMPILE); gl. Translatef(-100, -400. 0); glu. Sphere(quad. Obj, 50, 15); gl. End. List(); //Delete the quadric object glu. Delete. Quadric(quad. Obj);

Display List Usage • I want to display 2 spheres objects side by side.

Display List Usage • I want to display 2 spheres objects side by side. gl. Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); • Now I can call them in paint. GL //Clear Model View Matrix and call 2 nd list gl. Load. Identity(); gl. Call. List(display. Idx + 1); gl. Matrix. Mode(GL_MODELVIEW); //Clear Model View Matrix and call 1 st list gl. Load. Identity(); gl. Call. List(display. Idx);

Other Display List Uses • Load an entire model and perform the drawing as

Other Display List Uses • Load an entire model and perform the drawing as a list. • Rather than allocating a set of list indices using gl. Gen. Lists 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.