   OpenGL mapping Earth
  I am trying to map a 512 by 256 image of the earth onto a gluSphere object. I have no trouble getting the texture onto the object, but my problem is that once it is on the object it is repeated twice, split at the center of the sphere. Does anyone know a way to avoid this? I would think that this would be an almost standard texture mapping exercise. Does anyone know a way to get around this?I have placed both the code and the image online http://www.cs.rit.edu/~drc7257/earth/If you could offer any assistance I would appreciate it!Thanks,Dan   #include <GL/glut.h>#include <stdio.h>#include <stdlib.h>#include <string.h>char *texname = "earth.ppm";int angle = 0;unsigned char* ppmRead(char* filename, int* width, int* height){  FILE* fp;  int i, w, h, d;  unsigned char* image;  char head[70];/* max line <= 70 in PPM (per spec). */    fp = fopen(filename, "rb");  if (!fp) {    perror(filename);    return NULL;  }    /* grab first two chars of the file and make sure that it has thecorrect magic cookie for a raw PPM file. */  fgets(head, 70, fp);  if (strncmp(head, "P6", 2)) {    fprintf(stderr, "%s: Not a raw PPM file\n", filename);    return NULL;  }    /* grab the three elements in the header (width, height, maxval). */  i = 0;  while(i < 3) {    fgets(head, 70, fp);    if (head[0] == ''#'')/* skip comments. */ continue;    if (i == 0) i += sscanf(head, "%d %d %d", &w, &h, &d);    else if (i == 1) i += sscanf(head, "%d %d", &h, &d);    else if (i == 2) i += sscanf(head, "%d", &d);  }    /* grab all the image data in one fell swoop. */  image = (unsigned char*)malloc(sizeof(unsigned char)*w*h*3);  fread(image, sizeof(unsigned char), w*h*3, fp);  fclose(fp);    *width = w;  *height = h;  return image;}void sphere(GLuint texture){  glBindTexture(GL_TEXTURE_2D, texture);  GLUquadricObj *qobj;  qobj = gluNewQuadric();  gluQuadricDrawStyle(qobj,GLU_FILL);  gluSphere(qobj,1.0,100,100);}void textures(void){  GLint w, h, i;  GLubyte* texture;    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);    /* XXX - RE bug - must enable texture before bind. */  glEnable(GL_TEXTURE_2D);    glBindTexture(GL_TEXTURE_2D, 1);  texture = (GLubyte*)ppmRead(texname, &w, &h);  glTexImage2D(GL_TEXTURE_2D,0, 3, w, h, 0,    GL_RGB, GL_UNSIGNED_BYTE, texture);  free(texture);    /* XXX - RE bug - must enable texture before bind. */  glDisable(GL_TEXTURE_2D);}void display(void){  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  int width = glutGet(GLUT_WINDOW_WIDTH);  int height = glutGet(GLUT_WINDOW_HEIGHT);  glViewport(0,0,width,height);  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  gluPerspective(120,(GLfloat)width/height, 0.1, 1000.0);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  gluLookAt(0,0,3,0,0,0,0,1,0);    glPushMatrix();    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);  glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);  glEnable(GL_TEXTURE_GEN_S);  glEnable(GL_TEXTURE_GEN_T);  glEnable(GL_TEXTURE_2D);   glRotatef(angle,0.0,1.0,0.0);  sphere(1);   glPopMatrix();  glutSwapBuffers();}void init(void){  GLfloat Ka[] = { 0.2,0.2,0.2,1};  GLfloat Ks[] = { 1,1,1,1};  glEnable(GL_DEPTH_TEST);  glEnable(GL_CULL_FACE);  glEnable(GL_LIGHTING);  glEnable(GL_LIGHT0);  glEnable(GL_COLOR_MATERIAL);  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);  glColorMaterial(GL_FRONT, GL_DIFFUSE);  glMaterialf(GL_FRONT, GL_SHININESS, 64);  glMaterialfv(GL_FRONT, GL_SPECULAR, Ks);  glMaterialfv(GL_FRONT, GL_AMBIENT, Ka);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); }void timer(int val){  angle = (angle+5)%360;  glutPostRedisplay();  glutTimerFunc(100,timer,0);}  int main(int argc, char **argv){  glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA);  glutInitWindowPosition(50,50);  glutInitWindowSize(800,600);  glutInit(&argc, argv);  glutCreateWindow("Earth");  glutDisplayFunc(display);  glutTimerFunc(100,timer,0);    textures();  init();    glutMainLoop();  return 0;}
  Without looking at your code, it sounds as if your texture co-ords are whacked. ;  Try calling gluQuadricTexture after you create the quadric object.// Tell GLU to create texture coordinates for the quadricgluQuadricTexture(qobj, GL_TRUE);  [edit]typo[/edit]   [edited by - Rule on February 11, 2004 3:07:56 PM];  I added the gluQuadricTexture(qobj, GL_TRUE); to my code, which didn''t change how the object displayed.I am a little confused as to the statement that the texture coords are whacked. How would I modify this? are you talking about my calls to glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);glEnable(GL_TEXTURE_GEN_S);glEnable(GL_TEXTURE_GEN_T);  Or some other portion of code. I took the TexGeni code from a different source that instead of a GL_OBJECT_LINEAR it used GL_SPHERE_MAP. I read over the documentation on the glTexGen* call and I was unsure of what GL_S, GL_T, GL_R, GL_Q all stood for, so I kept with what I had at hand.Any clarification or other ideas? ;You might want to add these to your texture set up routine.If you want a single occurence of the image on the object use this :glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP);glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP);and if you want to repeat use this:glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);I can''t remember right now but perhaps by default it is set to repeat.Hope this helps. ;  I have found a solution!I removed the texGeni calls and addedglTexParameterf (GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);glTexParameterf (GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);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);This led to an accurately textured sphere!Thanks for all your help!-Dan- 