How to do Texture Mapping in OpenGL?? – A sample example.

Texture mapping is the process of applying colors from an image to an object created in OpenGL. A simple example would be, applying a brick image onto a square which makes the square look like an original wall.
OpenGL supports four basic texture map types. 1D, 2D, 3D and cube map textures. The following code is an example of a 2D texture mapping, which provides a basic usage of textures.
Note: To run this code on your machine, make a bitmap image (64 x 64) and name it floor.bmp . Keep this image in the same folder where your exe file is located. If you are Code::Blocks user, then compiling from IDE results in Error, it says that it couldn’t found the Image. So just compile it and run the exe  file which is inside debug or release folder. Visual Studio user can directly run this program without even including <windows.h> but Code::Blocks user must include <windows.h>.

Source Code:



SHARE How to do Texture Mapping in OpenGL?? – A sample example.

You may also like...

3 Responses

  1. It's a nice tutorial, thanks for it.
    MPI Machine

  2. Anonymous says:

    what if I only have access to gl.h and not glu.h and glut.h?

  3. Anonymous says:

    It is giving me this error:
    Planes from floor.bmp is not 1: 1028

Leave a Reply

Your email address will not be published. Required fields are marked *