Apply texture to only part of a sphere

Hi,

I’m having a really hard time trying to put a texture in only one part of a sphere.
I have a sphere representing the earth and a texture for a part of the globe, say for clouds over USA.
I want to show those clouds over the part of the sphere where USA are.

I’m quite new with OpenGL so maybe the solution to my problem is quite simple, but I really could not find anything browsing the web.
I’m creating my sphere drawing a set of triangle strips.
As far as I understand, if I want to use a texture I need to specify a texture coord for each vertex (glTexCoord2*). But I do not have a valid texture for all of them.
So how do I tell OpenGL to skip texture for those vertexes?

Thanks in advance for your help

One way you could do it is render a sphere with just the Earth texture, then render an overlying group of triangles with a cloud texture wherever you want clouds. As long as the cloud texture has an alpha channel (some level of transparency), which I think doesn’t require any extra OpenGL code, you should be fine.

Thanks fiodis for your reply.

my case is a bit more general. My sphere (the earth) comes with a topography. My texture, can be also a terrain texture (of a part of the globe).
If I create a new object from the new texture, I would not have the topography information for that object, or I would need to get it from the part of the earth the texture should go on top to. It seems to me extra work, it would be much simpler if there would be a way to apply the texture to only a part of the sphere.

In that case you could look into OpenGL blending functions (mentioned here and here, among other places) if you’re using pre-OpenGL 3.0 code, or alternatively you could try to write your own shaders using GLSL that blend textures.

ok,

thank you very much for the references

I’ve been working on this problem too recently. I’ve come up with a couple of approaches.
The one below is fairly straightforward. It uses fixed pipeline GL.
The figures demonstrate it. The texture wrapped around the entire earth is 2048 x 1024 pixels.
I need much more detail than this is certain regions of the globe.
The second figure shows a 1024x1024 pixel image mapped onto a 5 deg x 5 deg lat-lon region.
All I did was generate the coordinates for the smaller region in a loop.
The same loop assigns texture coordinates.
The routine latlon_xyz converts lat and lon into vectors on the sphere.
You can use the vertex vectors as vertex normals.
My routine is included …

http://www.mfwerner.addr.com/OpenGL/Earth_PR.jpg
http://www.mfwerner.addr.com/OpenGL/Pacific_Range.jpg


void ECI_Window::Pacific_Range (void)
{

    int h, w, v = -1;
    float lat, lon;

    static int   first_PR = TRUE;
    static float vrt[51][51][3], tex[51][51][2];

    if (first_PR)  {
       for (h = 0; h < 51; h++)  {
          lat = float(h) / 10.0 + 31.0;
          for (w = 0; w < 51; w++)  {
             lon = float(w) / 10.0 + -123.0;
             latlon_xyz (1.0, lat, lon, vrt[h][w]);
             tex[h][w][0] = float(w) / 50.0;
             tex[h][w][1] = float(h) / 50.0;
           }
       }
       first_PR = FALSE;
    }

    glDisable (GL_BLEND);
    glEnable  (GL_LIGHTING);

    glBindTexture (GL_TEXTURE_2D, textures[6].texID);

    glBegin (GL_QUADS);
       for (h = 0; h < 50; h++)  {
          for (w = 0; w < 50; w++)  {
             glTexCoord2fv (tex[h  ][w  ]); glNormal3fv (vrt[h  ][w  ]); glVertex3fv (vrt[h  ][w  ]); 
	     glTexCoord2fv (tex[h  ][w+1]); glNormal3fv (vrt[h  ][w+1]); glVertex3fv (vrt[h  ][w+1]); 
	     glTexCoord2fv (tex[h+1][w+1]); glNormal3fv (vrt[h+1][w+1]); glVertex3fv (vrt[h+1][w+1]);
	     glTexCoord2fv (tex[h+1][w  ]); glNormal3fv (vrt[h+1][w  ]); glVertex3fv (vrt[h+1][w  ]);
          }
       }
    glEnd ();
}

Let’s say that the image for your Earth texture looks something like this: http://www.planetaryvisions.com/images_new/4123.jpg

Now, if you only want to show clouds over North America, you can create a cloud texture that looks like this:

[ATTACH=CONFIG]866[/ATTACH]

Then when drawing you can reuse the same sets of texcoords for both textures, and use standard multi-texturing to blend them together (e.g. an additive blend).

If you’re not already doing so (and you don’t seem to be from your mention of glTexCoord2*), it’s strongly recommended that you move to using at least vertex arrays for this. As well as being more efficient, they would allow you to reuse the same set of data for both sets of texcoords.

I should also add here that this kind of thing can occasionally seem “wasteful” to people new to OpenGL, or more used to programming standard CPU-side stuff. After all, if there is a huge chunk of your sphere that doesn’t have clouds, why would you “waste” resources by adding in a mostly black image?

It’s actually much better to do things this way. You’re re-using texture coords, you don’t have to deal with problems of co-planar polygons, and if - in the future - you want to do something like rotate or distort your cloud layer, you’re already mostly set up to do so.