TextureBmpModern is sample C++ code illustrating the use of Modern OpenGL. It is part of a set of programs introducing the use of Modern OpenGL, which are intended to accompany a possible second edition of the book 3D Computer Graphics: A mathematical approach with OpenGL, Cambridge University Press, 2003.

TextureBmpModern shows how to load a texture from a bitmap (.bmp) file, and apply it to a quadrilateral. Its primary source file is TextureBmpModern.cpp. In addition, it uses RgbImage to load a texture map from a file and GlShaderMgr to read shader programs from a file. Follow these links to download the source files and executable:

Things to try out:

  1. Extract, compile and run the program. You must place the .glsl file and bitmap (.bmp) file in the same directory as the executable. You should see a rectangle, with a texture mapped image applied.
  2. Examine the source to see how it:
    • Reads the texture map from the file, and uses glTexParameteri to set its parameters.
    • Specifies texture coordinates in the array of vertex data loaded into the VBO.
    • Binds the texture map to shader program, and accesses the texture in the fragment shader.
  3. Try changing the texture coordinates to (0,0), (2,0), (2,1), (0,1) to see how "wrapping" work. Also, try (0,0), (1,0), (1,2), (0,2). The texture is "tileable" so you will not see any seam when wrapping.
  4. See the more detailed description of the software and its functionality.

Version 1.0 of TextureBmpModern, February 24, 2018. Revised September 14, 2020. All rights reserved.