Author Topic: sphere mapping question (openGL)  (Read 2923 times)

0 Members and 2 Guests are viewing this topic.

Frankolinox

  • Guest
sphere mapping question (openGL)
« on: February 21, 2015, 04:05:58 AM »
topic: openGL

a) hi all.. how I can create a sphere mapping for an earth pic? :)

b) how I can create an uv sphere mapping with an earth texture?

thanks, regards, frank

.

Mike Lobanovsky

  • Guest
Re: sphere mapping question (openGL)
« Reply #1 on: February 21, 2015, 10:44:33 AM »
Hi,

If we assume the sphere precision nPrecision as half the number of sphere faces (32 will be enough for starters), M_PI_2 as Pi / 2, and M_TWOPI as Pi * 2, then:

Code: [Select]
For i = 0 To (nPrecision - 1) \ 2
theta1 = i * M_TWOPI / nPrecision - M_PI_2
theta2 = (i + 1) * M_TWOPI / nPrecision - M_PI_2

glBegin(GL_TRIANGLE_STRIP)
For j = 0 To nPrecision
theta3 = j * M_TWOPI / nPrecision

' Splices
ex = cos(theta2) * cos(theta3) ' calculate Euler angles on 3 axes
ey = sin(theta2)
ez = cos(theta2) * sin(theta3)

glNormal3f(ex, ey, ez) ' set up normals
glTexCoord2f(-j / nPrecision, 2 * (i + 1) / nPrecision) ' set up UVs
glVertex3f(1.5 * ex, 1.5 * ey, 1.5 * ez) ' render vertices

' Sides
ex = cos(theta1) * cos(theta3)
ey = sin(theta1)
ez = cos(theta1) * sin(theta3)

glNormal3f(ex, ey, ez)
glTexCoord2f(-j / g_nPrecision), 2 * i / nPrecision)
glVertex3f(1.5 * ex, 1.5 * ey, 1.5 * ez)
Next
glEnd()
Next

Declare all the variables in the above code As Single, except for i and j which should be defined As Long (or Sys).  Put this code into your render procedure. Then if God permits, you'll get the following picture: (incidentally, this FBSL example uses a similar texture)

.
« Last Edit: February 21, 2015, 11:10:08 AM by Mike Lobanovsky »

JRS

  • Guest
Re: sphere mapping question (openGL)
« Reply #2 on: February 21, 2015, 01:06:52 PM »
Here is the NASA Blue Marble equirectangular projection in a Java applet. It tends to give the feeling as if the earth is inside out and your viewing from the center. What is amazing about the image is it's acuracy when the long/lat is feed to Google maps. Drag the image with your mouse to pan (zooming optional) and press the map button to sync with Google maps.

FYI You need to have Java Applet plugin support for this example to work in your browser. Current Chrome no longer supports Java so Firefox is your best bet.

NASA Blue Marble - Viewer/Google Maps sync




 

.
« Last Edit: February 21, 2015, 11:35:30 PM by John »

Mike Lobanovsky

  • Guest
Re: sphere mapping question (openGL)
« Reply #3 on: February 21, 2015, 01:26:54 PM »
... so Firefox is your best bet.

Hi John,

... but not under XP. Modern Java updates are no more compatible with XP and require at least Vista. Anyway thanks for the lead. I'll study it when I'm under my Vista or 7.

Frankolinox' texture is specifically designed to be used with the GL_TRIANGLE_STRIP sphere rendering algo whereby polar UVs tend to be infinitely small, and it can't be effectively used in any other sphere rendering modes. There are some other algos that render the polar regions of a sphere practically without distortion but they can't be used with this particular texture layout. Hence my example code.

Charles Pegge

  • Guest
Re: sphere mapping question (openGL)
« Reply #4 on: February 22, 2015, 04:13:11 AM »

Thanks Mike,

I have included an example with your code. ProjectsA/OpenglCns/SphereMapPolar.o2bas

Earth.bmp is converted to Earth.jpg

The texture loader has also been tweaked to support rectangular images. (512*256.

Code: OxygenBasic
  1.   % Title "Sphere Mapping Demo"
  2.   % Animated
  3.   % ScaleUp
  4.  '% PlaceCentral
  5. '% AnchorCentral
  6.  include "$\inc\ConsoleG.inc"
  7.  
  8.   function SphereMap(sys nPrecision)
  9.   ==================================
  10.   'Mike / Sphere mapping
  11.  float ex,ey,ez,theta1,theta2
  12.   float M_TWOPI = pi()*2
  13.   float M_PI_2  = pi()/2
  14.   sys   i,j,ei
  15.   ei=(nprecision-1)\2
  16.   For i = 0 To ei
  17.     theta1 = i * M_TWOPI / nPrecision - M_PI_2
  18.     theta2 = (i + 1) * M_TWOPI / nPrecision - M_PI_2
  19.     glBegin(GL_TRIANGLE_STRIP)
  20.     For j = 0 To nPrecision
  21.       theta3 = j * M_TWOPI / nPrecision
  22.       ' Splices
  23.      ex = cos(theta2) * cos(theta3) ' calculate Euler angles on 3 axes
  24.      ey = sin(theta2)
  25.       ez = cos(theta2) * sin(theta3)
  26.       glNormal3f(ex, ey, ez) ' set up normals
  27.      glTexCoord2f(-j / nPrecision, 2 * (i + 1) / nPrecision) ' set up UVs
  28.      glVertex3f(1.5 * ex, 1.5 * ey, 1.5 * ez) ' render vertices
  29.      ' Sides
  30.      ex = cos(theta1) * cos(theta3)
  31.       ey = sin(theta1)
  32.       ez = cos(theta1) * sin(theta3)
  33.       glNormal3f(ex, ey, ez)
  34.       glTexCoord2f(-j / nPrecision, 2 * i / nPrecision)
  35.       glVertex3f(1.5 * ex, 1.5 * ey, 1.5 * ez)
  36.     Next
  37.     glEnd()
  38.   Next
  39.   end function
  40.  
  41.   sub main()
  42.   ==========
  43.   static sys   imgn,res,wi,ht,earth
  44.   static float ang
  45.   if not imgn
  46.     imgn=21
  47.     res=0 'use image wi and ht (512*256)
  48.    LoadTexture "..\..\examples\images\Earth.jpg",imgn,res,wi,ht
  49.     earth=CompileList : SphereMap 32 : glEndlist
  50.   end if
  51.   cls 0,0,0
  52.   'display image
  53.  '
  54.  pushstate
  55.   move 16,-16
  56.   shading
  57.   color 1,1,1,1
  58.   texture imgn
  59.   scale 6
  60.   rotateY ang
  61.   go earth
  62.   'quadnorm 10.0, 10.0 'apply image texture to quad
  63.  texture 0
  64.   popstate
  65.   flat
  66.   move 0,-.5
  67.   scale 2
  68.   printl "Sphere Mapping"
  69.   ang+=.5 : if ang>=360 then ang-=360
  70.   end sub 'main
  71.  
  72.   EndScript
  73.  


Mike Lobanovsky

  • Guest
Re: sphere mapping question (openGL)
« Reply #5 on: February 22, 2015, 09:24:05 AM »
Hi guys,


@John:

Nah, my Win 7 FF refuses to display the applet. It says AllBasic is untrusted as far as Java sources go. :)

But your Earth texture is ... gorgeous! Thanks!


@Charles:

Thanks for your confidence in my code. :)

But John's (NASA) texture looks absolutely awesome on this sphere in place of my poor 512x256 shred, and especially when it has more faces than 32 * 2, for instance, SphereMap 128.

JRS

  • Guest
Re: sphere mapping question (openGL)
« Reply #6 on: February 22, 2015, 12:08:31 PM »
Quote from: Mike
Nah, my Win 7 FF refuses to display the applet. It says AllBasic is untrusted as far as Java sources go

 :-\ I think you would really be impressed with our (early pano days) old 360 virtual tour viewer I used to display the Blue Marble. The Google interface is icing. I got it working on Firefox under Linux with the Ice Tea Java applet support plug-in. Promise, it will be worth the extra effort on your part.

Just accept the warning messages as the viewer is a 2003-2005 vintage Java JAR applet.



.

Charles Pegge

  • Guest
Re: sphere mapping question (openGL)
« Reply #7 on: February 22, 2015, 06:36:06 PM »

Mmmm yes, this one is rather nice too :)

http://www.johnstonsarchive.net/spaceart/earthmap.jpg



.

JRS

  • Guest
Re: sphere mapping question (openGL)
« Reply #8 on: February 23, 2015, 12:36:20 AM »


Blue Marble - Next Generation Very high resolution images.

Here is a newer version of the viewer for Windows, Linux and Mac.

http://www.fsoft.it/FSPViewer/

Using this viewer doesn't have my Google Maps interface but still fun to play with.
« Last Edit: February 23, 2015, 01:42:36 AM by John »

Frankolinox

  • Guest
Re: sphere mapping question (openGL)
« Reply #9 on: February 23, 2015, 06:01:23 AM »
thank you mike and charles for help :) nice week for you