An image file printed on a shape is called a
texture.
I used the 256 × 256
WorldTile.png
from Google Maps.
main.mm
texture.cpp
GLAppDelegate
GLViewController
EAGLView
GLTools.cpp
WorldTile.tga
WorldTile.png |
WorldTile.tga |
For the time being, our textures will have to be tga files. To convert other formats to tga, see the free, on-line converters at Go 2 Convert, Convert Hub, etc.
Tga files come in two flavors, with and without RLE compression.
The program
file
will tell you if your tga file has RLE.
The following file does not have RLE.
file WorldTile.tga WorldTile.tga: Targa image data - RGB 256 x 256For the time being, we will have to use the type without compression. This C program removes the compression from a tga file, creating a new file named
tgatest.tga
.
The function
SetupRC
in
texture.cpp
calls
LoadTGATexture
,
which calls
gltReadTGABits
in
GLTools.cpp
,
which opens the
tga file by calling the C function
fopen
.
To get
fopen
to work,
the
main
function had to call
gltSetWorkingDirectory
in
GLTools.cpp
.
Since
gltSetWorkingDirectory
is a C++ function,
I had to change the name of
main.m
to
main.mm
.
The width and height in pixels of the tga file can’t be bigger than
GL_MAX_TEXTURE_SIZE
in
gl.h
,
currently 3379.
This excludes the class photo.
Our shape is the simplest possible
GLTriangleBatch
,
consisting of one triangle.
The batch is declared at the top of
texture.cpp
and created in
Setup
.
The fussy trigonometry makes the triangle equilateral.
A vector is an arrow that indicates a direction. A normal vector is an arrow that is perpendicular to something. Normal means perpendicular. The triangle is flat because the normal vectors that extend from each vertex are parallel.
The triangle does not cover the whole earth. It covers only the triangular area determined by the three vertices in the texture coördinates. These coördinates believe that the origin of the texture is at the lower left corner. The x coördinates increase rightwards from 0 to 1. The x coördinates increase upwards from 0 to 1.
SetupRC
function in
texture.cpp
,
change the texture coördinates array to the folloowing.
M3DVector2f textureCoordinates[] = { {0.20f, 0.72f}, {0.15f, 0.52f}, {0.35f, 0.52f} };
texture.cpp
,
comment out the triangle and comment in the sphere (in three places).
Roll the world with your finger.
WorldTile.png
was never intended to be a texture printed on a sphere.
I picked it only because Google Maps is the iconic image of our era.
Find an image file of the whole earth that would print
without the horizontal distortion.
Can you find a “blue marble” with clouds?
NSDate
and displays the Earth with the correct hemisphere illiminated.
The default point of view should be over New York City
(41° N 74° W)
or over the
subsolar point.