NeHe OpenGL Lesson18 – Quadrics (二次曲面)

screen_shot-300x235 This sample will introduce us to the wonderful world of quadrics. With quadrics you can easily create complex objects such as spheres, discs, cylinders and cones. These object can be created with just one line of code. With some fancy math and planning it should be possible to morph these objects from one object into another.
The function interfaces for OpenGL Quadrics are designed so well. All we need to is just some very few lines of code to make the whole thing work: create a Quadric object first, then draw one specified type Quadric during the main scene rendering part. The only thing that we need to take care is that such Quadric libraries comes from OpenGL utility library, instead of OpenGL native libraries.

 

Create Quadric Object

To create an OpenGL Quadric object:

quadratic=gluNewQuadric();                            // Create A Pointer To The Quadric Object (Return 0 If No Memory) (NEW)
gluQuadricNormals(quadratic, GLU_SMOOTH);            // Create Smooth Normals (NEW)
gluQuadricTexture(quadratic, GL_TRUE);                // Create Texture Coords (NEW)

There are some parameters for those functions. But I will not deep them further, because Quadrics feature rarely be used in the game programming. Game programmers perfer to use some controllable resource, they do not like some super functions like this allocate and release memory or other resource on fly and beyond their control. But if we want to write some small programs like graphic editor or do some quick test, those  Quadric function could be a very good option for us.

Draw Quadric Geometry

To draw an Quadric geometry, write code like this:

gluCylinder(quadratic,1.0f,1.0f,3.0f,32,32);

The meaning of this function parameters  are skipped. Because you could read some document about them carefully when you really want to understand them.

 

The full source code could be downloaded from here.

posted @ 2012-08-23 21:55  opencoder  阅读(289)  评论(0编辑  收藏  举报