Texture mapping applies an image to a set of coordinates instead of a color. The program is setup to use 24-bit bitmaps, though other formats can be used. The bitmaps must be sized to a power of 2 in order to work properly with OpenGL, 2x2, 4x4, 8x8, 16x16, etc.... In my own experience 256x256 gives pretty good results.
In this first sample, the call to ‘CreateBMPTexture’ loads the bitmap and gives it the name “1”. ‘glEnable GL.TEXTURE.2D’ tells OpenGL that we will be working with textures. And ‘glBindTexture GL.TEXTURE.2D , Texture’ sets texture 1 as the one we will be applying to the triangle.
In the TextureVertex calls, the first two values specify the x,y position of the bitmap to use. The remaining three are the X,Y,Z coordinates of the triangle. For the bitmap coordinates, (0,0) is the bottom left, (0,1) is the top left, (1,1) is the top right and (1,0)is the bottom right. The photo below shows the x,y bitmap coordinates used for the triangle.
These next two examples build a textured cube and a textured cylinder with the normals applied. The cylinder example shows how to apply a texture to a Quad-strip.
OpenGL 3D Graphics in Liberty BASIC
Lesson Seven: Texture Mapping
by Robert McAllisterTexture mapping applies an image to a set of coordinates instead of a color. The program is setup to use 24-bit bitmaps, though other formats can be used. The bitmaps must be sized to a power of 2 in order to work properly with OpenGL, 2x2, 4x4, 8x8, 16x16, etc.... In my own experience 256x256 gives pretty good results.
In this first sample, the call to ‘CreateBMPTexture’ loads the bitmap and gives it the name “1”. ‘glEnable GL.TEXTURE.2D’ tells OpenGL that we will be working with textures. And ‘glBindTexture GL.TEXTURE.2D , Texture’ sets texture 1 as the one we will be applying to the triangle.
In the TextureVertex calls, the first two values specify the x,y position of the bitmap to use. The remaining three are the X,Y,Z coordinates of the triangle. For the bitmap coordinates, (0,0) is the bottom left, (0,1) is the top left, (1,1) is the top right and (1,0)is the bottom right. The photo below shows the x,y bitmap coordinates used for the triangle.
These next two examples build a textured cube and a textured cylinder with the normals applied. The cylinder example shows how to apply a texture to a Quad-strip.
Next we will be creating "Transparent surfaces and fog"