Draw World Map [WGS84] with OpenGL in a wide Range

c++, dictionary, opengl

Solution

Actually, I have recently run into the exact same problem in my implementation of rendering entire planets from space to ground. In fact, what you have to do is create a new position structure that splits the accuracy between different floats. For example,

struct location
{
     vec3 metre;
     vec3 megametre;
     vec3 terametre;
     vec3 examtre;
     vec3 yottametre;
};

Then you code all of the operators and type cast functions for this structure (+, -, *, /, toVec3), you then use this location struct to encode the location of your camera and each grid tile. On rendering time, you dont translate the camera, but instead you translate the tiles by difference. For example:

void render()
{
     // ...
     location diff = this->position - camera.position;
     vec3 diffvec = diff.toVec3();
     glPushMatrix();
     glTranslatef(diffvec.x, diffvec.y, diffvec.z);

     // render the tile
     glPopMatrix();
}

What it does is removes the difference calculation from the OpenGL pipeline which only has up to double precision and puts the work on your program which can essentially have infinite precision. Now the precision and accuracy fall the further away you are from the camera instead of the further away you are from the orgin.

Happy Coding.

Problem

I want to draw a Map, consisting of 256x256 pixle Tiles (a lot of them). These cover a big area. The transformation to convert lat|lon(from the globe) to x|y (map) spawns quite big values. With these big values goes accurcy and so, if I go far away from the 0/0 Point, I get inaccuracies of multiple pixels between textures of two Tiles being next to each other (e.g. 2E8 | 0 and 2E8-1 | 0). How can I fix these messy unwanted grid appearences? The current failing implementaition is to use float to draw the primitives (this should not matter, as all Tiles are clipped to multiples of 256 in both coordinate directions). Note: I allready tried to use glTranslated for offset but either double's accurcy is not enough too, or this is not the reason for the glitches.

Original source