NeHe OpenGL Lesson18 – Quadrics (二次曲面)
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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了