[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
|
IntroductionWhile searching for some sample 3D graphics code, I ran across this great site (www.delphi3D.net) 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 cghelp.zip, cglib,zip, and glunits.zip 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 glunits.zip. The Planets ViewerI 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:
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
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |