title: Sphere texture mapping (opengl and c++)
body: <p>I am trying to add a texture to a sphere, it works, but I keep getting an error. Below is a picture of what I get, </p>
  
  <p><img src="https://i.stack.imgur.com/39IeE.jpg" alt="enter image description here"></p>
  
  <p>I don't know what this <code>GL error: Invalid operation</code> error is referring to. I think it has to do with my code. I'm not sure if I'm reading from my file correctly.</p>
  
  <p>Here is the code I am using to draw this sphere.</p>
  
  <pre><code>glTranslate(0.0f, 0.0f, 0.0f);
  glRotate(sunRot,0.0,0.0,1.0);
  drawAroundPlanetGrid(100, 1, 50, 50, 1);
  glPopMatrix();`
  </code></pre>
  
  <p>Here is what the <code>drawAroundPlanetGrid()</code> looks like.</p>
  
  <pre><code>void drawAroundPlanetGrid(double radius, int overSample, int numStrips, int numQuads, float radiusRatio)
  {
  GLMaterial test;
  GLuint surf;
  GLuint* surface;
  Images::RGBImage surfaceImage;
  
  surfaceImage=Images::readImageFile("/home/rodrtu/Desktop/SolarSystem/EarthTopography.png",Vrui::openFile("/home/rodrtu/Desktop/SolarSystem/EarthTopography.png"));
  
  glEnable(GL_TEXTURE_2D);
  
  //glGenTextures(1, surface);
  
  glBindTexture(GL_TEXTURE_2D, surf);
  
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  
  surfaceImage.glTexImage2D(GL_TEXTURE_2D,0,GL_RGB);
  
  double b = radius * 0.9966463577;//Geoid's semi-minor axis
  double e2 = 0.0067; //Geoid's squared eccentricity, derived from flattening factor
  
  float texY1=float(0)/float(numStrips);
  double lat1=(Math::Constants&lt;double&gt;::pi*double(0))/double(numStrips)-0.5*Math::Constants&lt;double&gt;::pi;
  double s1=Math::sin(lat1);
  double c1=Math::cos(lat1);
  double chi1=Math::sqrt(1.0-e2*s1*s1);
  double xy1=radius*radiusRatio/chi1*c1;
  double z1=radius*(1.0-e2)/chi1*s1;
  
  //* Draw latitude quad strips: *
  for(int i=1;i&lt;numStrips+1;++i)
      {
      float texY0=texY1;
      double s0=s1;
      double c0=c1;
      double xy0=xy1;
      double z0=z1;
      texY1=float(i)/float(numStrips);
      lat1=(Math::Constants&lt;double&gt;::pi*double(i))/double(numStrips)-0.5*Math::Constants&lt;double&gt;::pi;
      s1=Math::sin(lat1);
      c1=Math::cos(lat1);
      chi1=Math::sqrt(1.0-e2*s1*s1);
      xy1=radius/chi1*c1;
      z1=radius*(1.0-e2)/chi1*s1;
  
      glBegin(GL_QUAD_STRIP);
      for(int j=0;j&lt;=numQuads;++j)
      {
      float texX=float(j)/float(numQuads)+0.5f;
      double lng=(2.0*Math::Constants&lt;double&gt;::pi*double(j))/double(numQuads);
      double cl=Math::cos(lng)*radiusRatio;
      double sl=Math::sin(lng)*radiusRatio;
  
      glTexCoord2f(texX,texY1);
      glNormal3d(c1*cl,c1*sl,s1);
      glVertex3d(xy1*cl,xy1*sl,z1);
  
      glTexCoord2f(texX,texY0);
      glNormal3d(c0*cl,c0*sl,s0);
      glVertex3d(xy0*cl,xy0*sl,z0);
      }
      glEnd();
      }
      glEndList();
  }
  </code></pre>
  
  <p>I apologize if my code is confusing to read. Let me know if you see what is wrong with my code. I tried getting read of this error but it still shows up. Any ideas why?</p>