OpenGL implementation Cube Body texture; the so-called cube texture is to use six textures to form a cube. Of course, this is not for direct display. Then, based on the position and viewpoint of the object, through reflection, the color value at the intersection of the cube is the texture of the point, which is a simulation of the reflection of smooth objects in the real world in the surrounding environment.
Environment ing in OpenGL is more than this. This is also mentioned in nehe. However, instead of using cube mapping, sphere mapping is known from the above. cube ing is related to viewpoint, if the coordinates of any point on the surface of a cube are (x, y, z), the vector from the Cube origin to this point is V = (x, y, z), after this vector is normalized, set the normalized vector to V' = (x', y', Z'), where-1 <= x', y ', z' <= 1. In the process of representing the unit vector with color information, special processing is required ', z' size is converted to the range [0,255]. The specific conversion formula is: v'' = (V' + (2.0, 1)/255; then, assign each point on the cube surface to a pixel value in the same way. In fact, a unit vector query table is created for any vector. vectors of any direction and length can correspond to a pixel value on the surface of the cube, the color information of this pixel value is the unit vector corresponding to this vector. If you are not clear about it, see the following article. Article There should be no problem: http://developer.nvidia.com/object/cube_map_ogl_tutorial.html (a treasure chest of NV was discovered recently .. Crime of death ...) Below is Program Set the core of Environment ing in Code : Code
Void Cubemapping: docubemapping ()
{
Char * Imgfile [ 6 ] = { " Image/cm_left.tga " , " Image/cm_right.tga " , " Image/cm_top.tga " , " Image/cm_bottom.tga " , " Image/cm_back.tga " , " Image/cm_front.tga " };
Int I = 0 ;
For (I = 0 ; I < 6 ; I ++ )
{
Loadtga (cubetextures [I], imgfile [I]);
Glubuild2dmipmaps (cubefaces [I], gl_rgb, cubetextures [I]->Width, cubetextures [I]->Height, gl_rgb, gl_unsigned_byte, cubetextures [I]->Imagedata );
}
Gltexparameteri (gl_texture_cube_map_ext, gl_texture_min_filter, gl_linear );
Gltexparameteri (gl_texture_cube_map_ext, gl_texture_mag_filter, gl_linear );
Glable (gl_texture_gen_s );
Glable (gl_texture_gen_t );
Glable (gl_texture_gen_r );
Gltexgeni (gl_s, gl_texture_gen_mode, gl_reflection_map_ext );
Gltexgeni (gl_t, gl_texture_gen_mode, gl_reflection_map_ext );
Gltexgeni (gl_r, gl_texture_gen_mode, gl_reflection_map_ext );
Glenable (gl_texture_cube_map_ext );
Glenable (gl_texture_cube_map_ext );
Glable (gl_normalize );
}
In OpenGL, cube mapping exists in the form of ext_texture_cube_map extension. Check whether the program can run as follows: source program download:/files/gin_dl/source code .rar
You can use upper, lower, left, W, S, 1, 2 (non-keypad) control programs in the program.