Help with OpenGL needed

alfcen

Well-Known Member
Licensed User
Longtime User
Using the illfamed try-and-error technique I have finally managed to render
a planet with night shadow (screen snaps attached). Now, since a planet
rotates around its axis while seasons change the center of the shadow
needs to be positioned accordingly.

Googled for it but couldn't find anything that deals with the same problem.

I would truly appreciate help from anyone familiar with OpenGL

The core source:

B4X:
Sub Globals
   Dim lightDiffuse(0),lightPositionOn(0), lightPositionOff(0) As Float
   lightDiffuse = Array As Float(0.9,0.9,0.9,1)
   lightPositionOn = Array As Float(0,0,0,1)
   lightPositionOff = Array As Float(1,1,1,0)
   Dim globalAmbient(0) As Float
   globalAmbient = Array As Float(0.3,0.3,0.3,0.7)
End Sub

Sub glsv_Draw(gl As GL1)
   gl.glClearColor(0.0,0.0,0,1)
   gl.glClear(Bit.Or(gl.GL_COLOR_BUFFER_BIT, gl.GL_DEPTH_BUFFER_BIT))
   gl.glLoadIdentity
   gl.glScalef(0.5,0.5,0.5)
   gl.glTranslatef(0,0,-distZ)
   gl.glRotatef(rotX,1,0,0)
   gl.glRotatef(rotY,0,1,0)
   gl.glRotatef(rotZ,0,0,1)
   gl.glShadeModel(gl.GL_SMOOTH)
   gl.glLightfv(gl.GL_LIGHT0,gl.GL_AMBIENT,globalAmbient,0)
   gl.glLightfv(gl.GL_LIGHT0,gl.GL_DIFFUSE,lightDiffuse,0)
   If shadow Then   
      gl.glLightfv(gl.GL_LIGHT0,gl.GL_POSITION,lightPositionOn,0)
   Else
      gl.glLightfv(gl.GL_LIGHT0,gl.GL_POSITION,lightPositionOff,0)
   End If
   gl.glEnable(gl.GL_LIGHTING)
   gl.glEnable(gl.GL_LIGHT0)   
   GLObject_Draw(obj1,gl)
End Sub

Sub glsv_SurfaceCreated(gl As GL1)
   gl.glClearDepthf(1.0)
   gl.glEnable(gl.GL_DEPTH_TEST)
   gl.glDepthFunc(gl.GL_LEQUAL)
   gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT,gl.GL_NICEST)
   gl.glFrontFace(gl.GL_CCW) : gl.glEnable(gl.GL_CULL_FACE) : gl.glCullFace(gl.GL_BACK)
   glsv.RequestRender
End Sub

Sub glsv_SurfaceChanged(gl As GL1, width As Int, height As Int)
   gl.glViewport(0, 0, width, height)
   gl.glMatrixMode(gl.GL_PROJECTION)
   gl.glLoadIdentity
   gl.gluPerspective(fov,width/height,1,100)
   gl.glMatrixMode(gl.GL_MODELVIEW)
End Sub
 
Top