slowin.space
The first thing everyone does when they learn OpenGL is texture map a map image in rectangular coordinates to a 3d sphere. Have fun.
/* Apply a texture image, a planetary map in a simple cylindrical
projection in RGB format*/
static void
texture_map (const char *fname)
{
GLubyte *image;
GLint width, height;
GLenum format;
/* What are the valid sizes for the texture image? */
/* glGetIntegerv (GL_MAX_TEXTURE_SIZE) */
image = LoadRGBImage (fname, &width, &height, &format);
/* check image size to see if suitable as texmap */
info ("Texture image: width = %d, height = %d, format = %x\n",
width, height, format);
/* texture map is ok to apply */
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, width, height, 0,
format, GL_UNSIGNED_BYTE, image);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable (GL_TEXTURE_2D);
}
static void
solid_sphere (GLdouble radius, GLint slices, GLint stacks)
{
glEnable (GL_CULL_FACE);
glCullFace (GL_BACK);
GLUquadricObj *obj = gluNewQuadric();
gluQuadricDrawStyle (obj, GLU_FILL);
gluQuadricNormals (obj, GLU_SMOOTH);
gluQuadricTexture (obj, GL_TRUE);
glNewList (Sphere, GL_COMPILE);
gluSphere (obj, radius, slices, stacks);
glEndList ();
}
void
define_globe (const char *teximage, float radius)
{
texture_map (teximage);
solid_sphere (radius, 36, 18);
}
void
draw_globe ()
{
glEnable (GL_LIGHTING); /* in case they aren't already */
glEnable (GL_TEXTURE_2D);
glCallList (Sphere);
}