1

I'm trying to draw the celestial sphere in OpenGL, from the inside (from the perspective of the solar system). I want to be able to turn the camera around and see the stars in the milky way.

I'm using OpenGL 3 (and Glut) because that's well supported in Haskell. I'm using textures, because that seems simple enough for my purposes. I'm not trying to make it incredibly accurate, or spend too much time on it. I'm using this image as texture: https://www.eso.org/public/images/eso0932a/

My gist of my code is as follows:

render tex i = do
  -- Clear background
  ...            

  -- paint sphere
  GL.matrixMode $= GL.Modelview 0                                               
  GL.loadIdentity                                                               
  GL.texture GL.Texture2D $= GL.Enabled                                         
  GL.textureBinding Texture2D $= Just tex                                       
  GL.rotate (90+i) (Vector3 0.0 1.0 (0.0 :: GLfloat)) -- turn image around
                                                      -- just because
  GL.rotate 90 (Vector3 1.0 0.0 (0.0 :: GLfloat))     -- turn image sideways
                                                      -- to align with ecliptic                          
  GL.preservingMatrix $                                                     
    Quad.renderQuadric myStyle sphere                                           

  GLUT.swapBuffers                                                              
  GL.texture GL.Texture2D $= GL.Disabled                                        
  render tex (i+0.04)

Something is drawn if the sphere is small (e.g., 1 unit, whatever that means): it looks like it's just another celestial body. But if I start making it bigger, so that the viewer is inside it, then a hole opens in the middle and it eventually disappears. All I see is the background.

I'd like to see the inside of the sphere.

What am I doing wrong?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Ivan Perez
  • 582
  • 2
  • 17
  • 1
    Anything change if you flip the sphere inside-out using `glScalef(-1, -1, -1)`? Probably have to do `glFrontFace(GL_CW)` too since the negative scale will flip all the triangle/quad windings. – genpfault Jul 30 '19 at 02:33
  • 2
    This might be due to the far-plane of your camera clipping the geometry, too. – Mokosha Jul 30 '19 at 05:44
  • 1
    if you mean by inside your sphere underground than turn off `GL_CULL_FACE` otherwise its znear plane clipping. Also take a look at this: [Is it possible to make realistic n-body solar system simulation in matter of size and mass?](https://stackoverflow.com/a/28020934/2521214) and sublinks in there they cover all of the sub-tasks you will encounter ... This [Applying map of the earth texture a Sphere](https://stackoverflow.com/a/31804515/2521214) might help a bit too – Spektre Jul 30 '19 at 05:48
  • 1
    @Mokosha sounds more like znear clipping (problem starts when getting close) – Spektre Jul 30 '19 at 05:54
  • 1
    btw I am using these [Deep Star Maps](https://svs.gsfc.nasa.gov/cgi-bin/details.cgi?aid=3895) + Hipparcos/BSC – Spektre Jul 30 '19 at 05:59
  • Use a vertex shader to set the `gl_FragDepth` to something like 0.99 so it is always rendered, but behind everything else viewable within the frustrum – Nadir Jul 30 '19 at 08:05
  • 2
    How about posting a [MCVE]? – leftaroundabout Jul 30 '19 at 12:41

0 Answers0