NeHe OpenGL Lesson23 – Sphere Mapping Quadrics In OpenGL
2012-08-23 21:26
309 查看
![](http://images.cnblogs.com/cnblogs_com/open-coder/201208/201208232126261164.png)
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.
相关文章推荐
- NeHe OpenGL Lesson18 – Quadrics (二次曲面)
- NeHe OpenGL Lesson35 – Playing AVI Files In OpenGL
- NeHe OpenGL Lesson34 – Beautiful Landscapes By Means Of Height Mapping
- NeHe OpenGL Lesson20 – Masking
- OpenGL In C# 04 Nehe 第二课 绘制多边形
- NeHe OpenGL Lesson19 – Particle Engine Using Triangle Strips(粒子引擎)
- OpenGL In C# 05 Nehe 第三课 添加颜色
- NeHe OpenGL Lesson39 – Introduction to Physical Simulations
- NeHe OpenGL Lesson38 – Loading Textures From A Resource File
- NeHe OpenGL Lesson43 - FreeType Fonts in OpenGL
- NeHe OpenGL Lesson15 – Texture Mapped Outline Fonts
- NeHe OpenGL Lesson36 – Radial Blur(径向模糊)
- NeHe OpenGL Lesson14 – Outline Fonts
- NeHe OpenGL Lesson29 – Blitter Function, RAW Texture Loading
- NeHe OpenGL Lesson13 – Bitmap Fonts
- Use Pre-Compressed DDS in OpenGL – glut
- NEHE的OpenGL-Lesson 01 Setting Up OpenGL in Windows
- NeHe OpenGL Lesson28 – Bezier Patches(贝叶茨曲面) / Fullscreen Fix
- NeHe OpenGL Lesson33 – Loading Compressed And Uncompressed TGA’s
- NeHe OpenGL Lesson27 – Volume Shadows(体积阴影)