TOpenGl


  The Component     The Scene Editor     The Source Code     Send an e-mail here
  if you want to be notified
  of new releases 
 

Ogl.zip   Borland C++ Builder Component
This archive contains the following files 
OpenGl.h include it in your app
Ogl.lib  link it
Ogl.bpl  copy it to your system32 or another dir in the PATH
Ogl.htm  the page you are reading
lgpl.html  The GNU Library General Public License


Installation

Extract the files and copy them to a directory of your choice.
Copy ogl.bpl to your system32 or another dir in the PATH.
Go to your BCB IDE. Choose Component/Install Packages. Select ogl.bpl.

 This will install a  tab on your palette, containing five components:
TOpenGl   The core component. Encapsulates OpenGl, keeps a list of objects composing a scene and a list of lights. Handles animation calling events in your app when the scene is going to be repainted so you can change anything you like in the scene on each frame.
TFloatEdit   This and the following are simple components that make your life easier if you need the user to enter/modify floating point values. This is the ancestor of the other three.
TPos3D   A TFloat Edit specialized for handling 3D positions (X,Y,Z,W values)
TColorEdit   A TFloat Edit specialized for handling colors (R,G,B,A values)
TAngleEdit   A TFloat Edit specialized for handling degrees values
The ogl.bpl package also contains a number of other non visual components (they do not appear on the palette). These components are used internally for building the 3D scene but you may directly manipulate them to achieve more control or use animation.

 They are:
TPart hierarchy  An object of class TPart or of a class derived from TPart represent a 3D object in the scene. 
TPart  This is the ancestor of this hierarchy. Implements the functionality's common to all the objects as setting the position, rotation, scaling. New objects can be derived from here. 
TPartCube  Represents a cube of side 1, centered on the origin. You cannot change the side but modifying its position, rotation and scaling you can achieve a great flexibility. 
TPartSphere  Represents a sphere of radius 1, centered on the origin. 
TPartCylinder  Represents a cylinder having base radius 1,height 1, centered on the origin. 
TPartDisk  Represents a disk having inner radius 1, outer radius 2, centered on the origin. 
TPartQuad  Represents nearly any shape you can create with glBegin, glEnd. You can set the shape, number of points, the vertices and the normals. 
TPartGroup  Contains a list of other objects. Position, rotation and scaling defined for this object ally to all the children. 
 
TLuce  Luce is the italian for Light. TOpenGl contains a list of 32 TLuce objects. For each of them you can define position, ambient color, diffuse color, specular color and state (enabled or not). 
TFloatVector hierarchy  TFloatVector just enables you to manipulate an array of up to four float numbers as a whole. It is the ancestor of a hierarchy containing 
T3DVector 
specialized for X,Y,Z,W values 
TColorVector 
specialized for R,G,B,A values 
TAngle 


TOpenGl 
PROPERTIES
Animation bool Animation 
Set to true if you want to enable animation. 
When true the component continuously invalidates its window, calling each time the OnFrame event so your application can update the scene. Defaults to false. 
Fps float Fps 
Read only. Tells you the number of frame per second. Meaningful only if animation is on. 
ProjectionOrtho bool ProjectionOrtho 
Set to true if you want an orthogonal projection. Defaults to false. 
ProjectionWidth float ProjectionWidth 
Only used when ProjectionOrtho is true. 
ProjectionHeight float ProjectionHeight 
Only used when ProjectionOrtho is true. 
ProjectionNear float ProjectionNear 
How far is the near plane from your eye. Objects nearer than this value are clipped. 
ProjectionFar float ProjectionFar 
How far is the far plane from your eye. Objects farthest than this value are clipped. 
ProjectionAngle float ProjectionAngle 
Set a value in degrees from 1 (sub millimeter telescope) to 180 (fish eye). Only used when ProjectionOrtho is false. 
EyePosition T3DVector * EyePosition 
Where is your eye. 
Defaults: 
EyePosition->X = 0; 
EyePosition->Y = 0; 
EyePosition->Z = -8;
EyeTarget T3DVector * EyeTarget 
Where are you looking to. 
Defaults to 0,0,0. 
EyeUp T3DVector * EyeUp 
If you are standing up and looking forward keep the default of 0,1,0.
Parts TList * Parts 
The list of TPart objects making up the scene. 
Lights TLuce * Lights[int n] 
The 32 TLuce elements. 
ResourceContext int ResourceContext 
Recast to HGLRC and play with the low level details of OpenGl. 
Textures TPicture * Textures[int n] 
Assign up to MAXBITMAPS TPicture * objects. 
Texture is currently disabled in this version. Conversion of TPictures to texture buffer is implemented but too slow. I will enable it as soon as I find some better solution to handle multiple textures. 
METHODS
SaveTo bool SaveTo(String fileName) 
Saves the current scene to a ".3DS" file. Returns true if OK. 
LoadFrom bool LoadFrom(String fileName) 
Loads a scene from a file ".3DS". Returns true if OK. 
Refresh void __fastcall Refresh(TObject *Sender) 
Redraws the scene. 
AddGroup TPart * __fastcall AddGroup(TPart * pParent, const char * name = 0) 
Creates and adds to the scene a new a group. Returns the handle of the new object. 
If pParent is 0 or is not a group it is ignored. If it is a group the new object is added to that group. The OnListChanged event is called. 
AddQuad TPart * __fastcall AddQuad(TPart * pParent, const char * name = 0) 
Creates and adds to the scene a quad that you can later modify into any other shape. Returns the handle of the new object. 
If pParent is 0 or is not a group it is ignored. If it is a group the new object is added to that group. The OnListChanged event is called. 
AddCube TPart * __fastcall AddCube(TPart * pParent, const char * name = 0) 
Creates and adds to the scene a cube. Returns the handle of the new object. 
If pParent is 0 or is not a group it is ignored. If it is a group the new object is added to that group. The OnListChanged event is called. 
AddSphere TPart * __fastcall AddSphere(TPart * pParent, const char * name = 0) 
Creates and adds to the scene a sphere. Returns the handle of the new object. 
If pParent is 0 or is not a group it is ignored. If it is a group the new object is added to that group. The OnListChanged event is called. 
AddCylinder TPart * __fastcall AddCylinder(TPart * pParent, const char * name = 0) 
Creates and adds to the scene a cylinder. Returns the handle of the new object. 
If pParent is 0 or is not a group it is ignored. If it is a group the new object is added to that group. The OnListChanged event is called. 
AddDisk TPart * __fastcall AddDisk(TPart * pParent, const char * name = 0) 
Creates and adds to the scene a disk. Returns the handle of the new object. 
If pParent is 0 or is not a group it is ignored. If it is a group the new object is added to that group. The OnListChanged event is called. 
DeleteObject void __fastcall DeleteObject(TPart *) 
Remove from the scene and deletes an Object. The OnListChanged event is called. 
Paste TPart * __fastcall Paste(TPart * pParent, TPart * pp) 
Adds to the scene an object you already have. The OnListChanged event is called. Be careful to Clone any object that is already in the list if you want to duplicate it using this function. 
EVENTS
OnInitRC Called after initialization is completed. Trap it if you want to add global settings like antialiasing, face culling or the like. 
OnListChanged Called when new objects are added or deleted from the Parts list. The scene editor uses this to synchronize its objects TreeView with the content of the TOpenGl component. 
OnPaint Called each time the windows is redrawn. 

 If you trap it you have to manually add objects to the scene (the objects in the Parts list are not drawn). 

OnFrame Called just before the scene is going to be redrawn as the effect of setting Animation to true. Trap if to modify the scene from one frame to the other. 
OnSetProjection Called every time the scene is redrawn. Trap if to modify any OpenGl state before the object list is drawn or OnPaint is called. 
 

TFloatEdit 
PROPERTIES
Value  TFloatVector * Value  
The edited values. 
Min  TFloatVector * Min  
The minimum values the user can select. 
Max  TFloatVector * Max  
The maximum values the user can select. 
NValues  int NValues  
The number of elements the user can modify. 
Labels  TStringList * Labels  
The labels the user sees associated to each element. 
DecDigits  int DecDigits  
The number of decimal digits displayed. 
EVENTS
OnChange  Called whenever a change occurs in Values. 
 

TPos3D 
Derived from TFloatEdit
PROPERTIES
Value  T3DVector * Value  
The edited values. 
Min  T3DVector * Min  
The minimum values the user can select. 
Max  T3DVector * Max  
The maximum values the user can select. 
 

TColorEdit 
Derived from TFloatEdit
PROPERTIES
Value  TColorVector * Value  
The edited values. 
Min  TColorVector * Min  
The minimum values the user can select. 
Max  TColorVector * Max  
The maximum values the user can select. 
 

TAngleEdit 
Derived from TFloatEdit
PROPERTIES
Value  TAngle * Value  
The edited values. 
Min  TAngle * Min  
The minimum values the user can select. 
Max  TAngle * Max  
The maximum values the user can select. 
 

TPart 
PROPERTIES
PX  float PX  
X Position. 
PY  float PY  
Y Position. 
PZ  float PZ  
Z Position. 
RX  float RX  
X of the rotation vector. 
RY  float RY  
Y of the rotation vector. 
RZ  float RZ  
Z of the rotation vector. 
SX  float SX  
Amount of scaling along the X axis. 
SY  float SY  
Amount of scaling along the Y axis. 
SZ  float SZ  
Amount of scaling along the Z axis. 
RotationAngle  float RotationAngle  
Amount of rotation clockwise around the rotation vector defined by the origin and RX,RY,RZ. 
Name  String Name  
Name of the object. There is no control that is unique and no search method in TOpenGl but I plan to add them. 
FullName  String FullName  
Read only. Gives you a string made up of the object type (Cube, Sphere, Disk, Group ...) plus the name or an ID if the name a name was not assigned (default). 
METHODS
Clone  virtual TPart * __fastcall Clone();  
Returns a copy of the object that you can use with the Past method of TOpenGl. If you don't give the cloned object to Paste, it's your responsibility to delete it. 
EVENTS
OnChange  Called when any property is modified. Defaults to the Refresh method of the TOpenGl instance containing the object. 
 

TPartCube 
Derived from TPart
 

TPartSphere 
Derived from TPart
PROPERTIES
Slices  int Slices  
Number of slices the sphere is build with. Defaults to 20. 
Stacks  int Stacks  
Number of stacks the sphere is build with. Defaults to 20. 
 

TPartCylinder 
Derived from TPart
PROPERTIES
Slices  int Slices  
Number of slices the cylinder is build with. Defaults to 20. 
Stacks  int Stacks  
Number of stacks the cylinder is build with. Defaults to 20. 
BaseRadius  float BaseRadius  
Defaults to 1. 
TopRadius  float TopRadius  
Defaults to 1. 
Height  float Height  
Defaults to 1. 
 

TPartDisk 
Derived from TPart
PROPERTIES
Slices  int Slices  
Number of slices the cylinder is build with. Defaults to 20. 
Loops  int Loops  
Number of stacks the cylinder is build with. Defaults to 20. 
InnerRadius  float InnerRadius  
Defaults to 1. 
OuterRadius  float OuterRadius  
Defaults to 2. 
 

TPartQuad 
Derived from TPart
PROPERTIES
NPoints  int NPoints  
Number of points. Each point has X,Y,Z vertices and X,Y,Z normals. 
Shape  int Shape  
Accepts the OpenGl constants GL_POINTS, GL_LINES... 
Defaults to GL_QUADS. 
float X[int n]  
X position of vertex n. 
Default values are: 
X[0]=-1; 
Y[0]=-1; 
Z[0]=0; 
X[1]=1; 
Y[1]=-1; 
Z[1]=0; 
X[2]=1; 
Y[2]=1; 
Z[2]=0; 
X[3]=-1; 
Y[3]=1; 
Z[3]=0;
float Y[int n]  
Y position of vertex n.
float Z[int n]  
Z position of vertex n.
NormX  float NormX[int n]  
X normal to vertex n.
NormY  float NormX[int n]  
Y normal to vertex n.
NormZ  float NormZ[int n]  
Z normal to vertex n.
 

TPartGroup 
Derived from TPart 
Can be used as parent of other objects.
 

TLuce 
PROPERTIES
Enabled  bool Enabled  
True if this light is to be used
EVENTS
OnChange  Called whenever the light parameters (position, ambient color, diffuse color, specular color) are changed. Defaults to the Refresh method of the TOpenGl instance containing it. The light parameters are public members of the class, they are not property; see the OpenGl.h header file if you want to modify them. 
 

TFloatVector 
PROPERTIES
Element  float Element[int]  
The elements of the vector 
METHODS
Assign  void __fastcall Assign(TPersistent * Value)  
If Value is another TFloatVector the elements of Value are copied to this object otherwise nothing happens. 
Vector  const GLfloat * Vector()  
Returns a GLfloat * vector which you can pass to OpenGl primitives ending with "fv". 
EVENTS
OnChange  Called whenever an element is changed 
 

T3DVector 
Derived from TFloatVector
PROPERTIES
float X  
X value. 
float Y  
Y value. 
float Z  
Z value. 
float W  
W value. 
 

TColorVector 
Derived from TFloatVector
PROPERTIES
float R  
Red value. 
float G  
Green value. 
float B  
Blue value. 
float A  
Alpha value. 
 

TAngle 
Derived from TFloatVector
PROPERTIES
Degrees  float Degrees  
Degrees value. 
 
 

Source code for the component and the scene editor.

Copyright (C) 1998 Enzo Piombo

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA  02111-1307, USA.

download

write me at