NeHe OpenGL Lesson23 – Sphere Mapping Quadrics In OpenGL
This sample shows us how to do a Sphere Mapping when work with auto-generate texture coordinates in OpenGL.
For sphere mapping, you need a sphere map. What you need to do in PS is selecting distort and apply a spherize modifier from filter menu.
To set up the sphere mapping in OpenGL, you need to set up the auto-generate texture coordinates mode to sphere instead of providing the coordinates with glTexCoord function. Just as following code:
//Texture use for automatic coordinate generation glBindTexture(GL_TEXTURE_2D, texture); glEnable(GL_TEXTURE_2D); //Sphere mapping and enable s & t texture generation glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); //Draw the shapes to apply the texture ... glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_2D);
Environment Mapping: GL_REFLECTION_MAP & GL_TEXTURE_CUBE_MAP. This feature was used a lots in the game, like a metal ball or a small pool of water to reflect the around scene. The following are the code to set up a cube map:
glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_X, cubeMap[0]); glBindTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, cubeMap[1]); glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, cubeMap[2]); glBindTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, cubeMap[3]); glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, cubeMap[4]); glBindTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, cubeMap[5]); glEnable(GL_TEXTURE_CUBE_MAP); //Environment mapping (see underneath) ... glDisable(GL_TEXTURE_CUBE_MAP);
The following code used to set up the reflect map mode:
//GL_REFLECTION_MAP for s,t,r texture coordinates glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); //Draw shape to aply reflection on it ... glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R);
An article about auto-generate texture coordinates mode in OpenGL could be found from here, http://jerome.jouvie.free.fr/opengl-tutorials/Tutorial11.php.
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:你的「微服务管家」又秀新绝活了