OpenGL CgLib Planet Viewer Demo

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only





While searching for some sample 3D graphics code, I ran across this great site ( that offers  a Delphi  interface to OpenGL.  OpenGL is a widely supported graphics library that does most of the "grunt work" necessary to present 3D objects on a 2D screen.   From what I've read, it's popular because it is simpler than the  DirectX alternative, and it is supported on more platforms.  

Here's a prototype "Planets in Motion" program using the Computer Geometry OpenGL Delphi components from Delphi3D.   

Computer Geometry Library  (CGLib)

First, about the CGLib components.  Installation is straightforward.  Visit the Delphi3D site and get, cglib,zip, and  from the Downloads/Libraries & Tools  area    You'll probably want more demo programs, utilities, etc. later, but cglib and glunits are mandatory.   Extract these into your Delphi\Lib folder, or some other library that's in your units search path.  That's it.    There are 3 dlls required in your Windows/System directory:  opengl32.dll, glu32.dll and glut32.dll.   Of these, glut32.dll is probably the one that is not already installed - at least was the case on my  systems.   I'm definitely a novice here, but I think that glu and glut are wrappers for OpenGL functions and provide an interface to the API (Application Program Interface) and some additional functionality.    Glut32.dll is not available on Delphi3D, but there is a link from  the glunits download paragraph there to the glut32 author's site.  All you need from this download is glut32.dll, ignore the .h and .lib stuff which is for C compilers and provided for Delphi users by

The Planets Viewer

I modified a Planets project that is also available on the Delphi3D site as my first OpenGL program  .  It represents a stationary sun with the earth and moon rotating around it.   My modifications were:

bulletMade the orbits more real.  (Moon's orbit around the earth is 5 degrees from the ecliptic (plane of the earth around the sun).  Rotation is now counterclockwise for both orbits when viewed from the North star.  Moon now rotates 12 times per years around the earth.  Earth axis is tilted 23 degrees.  
bulletI started fooling around with moving the viewpoint (the camera in OpenGL terms).  So I added TSpinEdit components to control the azimuth (horizontal) angle, altitude (vertical) angle, and distance from he sun.    I also added a speed control (elapsed hours per step).   
bulletMoved the display from the form to a TPanel.   I just copied some code from another Panels demo program from Delphi3D to accomplish this.

Program logic is simple enough, FormCreate initializes some OpenGL stuff, a timer pops every few milliseconds to update the time measure, and a form paint  exit redraws everything to reflect the new positions.  That's it.     

The demo is cool!  Not only does earth rotate around the sun and the moon around the earth, but they each also rotate on their own axes!   Perspective drawing makes thing smaller as they recde from the viewer and larger as they approach.  Lighting from the sun always lights the facing  side.  It's kind of hard to see the axial rotation right now, but think a feature called "texturing" will allow bitmaps to be mapped to the surface of the spheres somehow.  

Now if I can just figure out how to do that and to "fly" the camera to  locations on the surface of one of the bodies, we'll really have something.   Like watching sun and moon rising and setting,  phases of the moon, eclipse activity, etc.   Fun, fun, fun!

Browse/Download Source 

bulletBrowse source code
bulletDownload source
bulletDownload executable 


  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.