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.
本文介绍OpenGL Quadrics库,展示如何用几行代码轻松创建球体、圆盘、圆柱和锥体等复杂几何形状。通过创建Quadric对象并调用相关函数,如设置平滑法线和纹理坐标,可以实现这些几何体的绘制。虽然Quadrics在游戏编程中较少使用,但对于图形编辑器或快速测试的小程序来说,它是一个很好的选择。
418

被折叠的 条评论
为什么被折叠?



