Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Problem With Texture Wrapping [Equirectangular to Azimuthal Equidistant Projection]

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Location
    Australia
    Posts
    9

    Problem With Texture Wrapping [Equirectangular to Azimuthal Equidistant Projection]

    Hello all.

    I have been trying to write a program to perform the named projection but am having some problems where the texture is joined. I posted a thread on this cartography site http://www.cartotalk.com/index.php?showtopic=8330 as I was having problems with mapping initially but I think my mapping is now working I just have a problem with repeating texture coordinates.

    Here are some screenshots. There is just some detracting distortion where the image is joined along the date line (the edge of the image):


    I think the problem problem is due to the wrapping of texture coordinates. I have tried to illustrate the problem in the figure below. The program is currently mapping from A-->B so the distorted sectors are displaying a compressed version of nearly the entire map. What should happen instead is to map from A wrapping to B (to the right). In OpenGL I think this can be achieved by enabling GL_REPEAT and simple using that B'=B+1 to get the correct texture response.


    But when I added this check:
    Code :
    if (p_d[n].u < p_d[n-1].u)
    		p_d[n].u += 1;
    only the problem from one of the polar aspects was fixed (and not at all from oblique aspects).

    Any ideas? Here is a link to the program I have so far if it will help with diagnoses: http://dl.dropbox.com/u/49415695/Desktop5%...ery.close%5D.7z
    You will need the data folder with the image (and maybe some dll files I haven't included). The arrow keys control the centre of the projection, 't' toggles the texture, 'up-pg' 'dn-pg' zoom in and out.

    Thanks
    Felix

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2012
    Location
    Australia
    Posts
    9
    I have nearly fixed the problem by searching for jumps (above some threshold) in the texture coordinates. I have made this short video to illustrate the method I have used: http://dl.dropbox.com/u/49415695/Map...Wrap%20Fix.mp4

    The only problem is that the distortion still appears but after you move the centre point around (using the arrow keys) the problem appears to vanish. Here is the new version of my program: http://dl.dropbox.com/u/49415695/Des...enCloser%5D.7z

    I am lost as to why this happens. If I pause the program and manually edit the centre back to the original latitude and longitude the image displays correctly.

  3. #3
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,007
    I think your problem is that you have to duplicate the vertices along the seam so that you don't have texture coordinates that go from 0.9..0 (as you mention in the above thread link)

    So instead of having tex coords that go 0.0, 0.2, 0.4, 0.6, 0.8 (when wrapping that would go back to 0.0) you need to add another set of vertices that go
    0.0, 0.2, 0.4, 0.6, 0.8, 1.0 (duplicate vertex in same position as 0.0)


    This thread also might be of some help to you
    http://www.opengl.org/discussion_boa...onment-mapping

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2012
    Location
    Australia
    Posts
    9
    Quote Originally Posted by sqrt[-1] View Post
    This thread also might be of some help to you
    http://www.opengl.org/discussion_boa...onment-mapping
    That program looks pretty cool, fancier than anything i've written in OpenGL

    I think you haven't seen my second post as it took some time before it was approved. I'm pretty sure I implemented the method you outlined (I have tried to explain in more detail in the video I made).
    Hopfully someone has experiance with the problem I am now having, and/or a better way to solve the problem than the method I took.

    Thanks

  5. #5
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,007
    I would help more, but the video link is broken and the example app you posted contains no code (and the exe depends on debug dlls I don't have installed)

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2012
    Location
    Australia
    Posts
    9
    Quote Originally Posted by sqrt[-1] View Post
    the video link is broken
    Sorry about that I'm not sure about how to edit previous posts but here is the Fixed Video Link
    [I can edit here but not others... I think these are the posts that had to be approved before they were posted]

    Quote Originally Posted by sqrt[-1] View Post
    the example app you posted contains no code
    Yes, I will try and put code in the future. I did post code at the link in the first post link but it was limited since I was just trying to solve my initial problem with mapping.
    I will post some code at the end of this post if you wanted to suggest any improvments (i'm sure there would be a better way... as I got told 'I am using old-school OpenGL'.
    (I've just been doing the tuts from NeHe that look interesting)

    Quote Originally Posted by sqrt[-1] View Post
    and the exe depends on debug dlls I don't have installed
    I have compiled the fixed program in 'release' mode. I'm not sure if this solves the problem?


    Ok, fist this is the embarising bug that I found on the train this morning:
    Code :
    for (i=0; i<4; i++)   { [B]// FOR THE FOUR VERTICES OF QUAD.[/B]
     
              [B]// disk coordinates[/B]
              p_d[n].x = b2[i] * cos(a2[i]) + x0;
              p_d[n].y = b2[i] * sin(a2[i]) + y0;
     
              [B]// calcuate texture coordinates[/B]
              AziCalc (lat_p, long_p, b2[i], a2[i], p_d[n].x, R);
              p_d[n].u = 0.5 - longitude/PI2;
              p_d[n].v = latitude/PI;
     
              [B]// I HAD THE TEXTURE WRAPPING CODE HERE![/B]
     
              n++;
              }
     
              [B]// THE CODE WHOULD HAVE BEEN HERE![/B]
              // Wrap bad texture coordinates
              getmax2(n-4, n-1, &max, &index);       //get max value for last quad
              getmin2(n-4, n-1, &min, &index);       //get min value for last quad
              while (max - min > 0.5){             // if texture coordinates too far apart
                 p_d[index].u += 1;             //wrap coordinates
                 getmax2(n-4, n-1, &min, &index);    //get max value for last quad
                 getmin2(n-4, n-1, &min, &index);    //get min value for last quad
              }
        }

    The program now works well. Here is the fixed version: Fixed version
    (I compiled this version as 'Release' as this should hopfully get rid of some dll dependencies - not sure though)
    Controls:
    Arrow Keys: Adjust the centre of projection
    'T': toggles the texture
    'F': changes filters
    Here is the section of code that creates the disk: Source1.c

    Thanks for your help. You will probably think my code isn't very good but at least it is working now

    I was also wndering if there was a way to add '[SOLVED]' to thread title?
    Last edited by felixrulz; 07-31-2012 at 08:20 PM.

  7. #7
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,007
    I don't think I helped at all, but glad you sorted it out - It ran fine.
    You probably need a few more posts on these forums before you can do more things.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •