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.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/23/2653318.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值