
I repacked FreePascal units gl, glu and glx
into the cl_gl_core.pp, cl_gl_header.inc and cl_gl_loadprocs.inc...

Because the standard units DID NOT WORK under my Linux version (Mandrake 9.0)
- they always failed to load libGL.so and didn't bother to give
  a warning - which led to unexplained AVs.

Anyway, If you'll get a new, working version of 'em, you can
  use them then, and throw cl_gl_xxxx stuff away. I's just 
  a temporary solution.
  
************************************************
_cl_winman_demo:

- when window loses focus, it becomes bright red
  (funny, it appears in Lunux when you drag the window...)    

- mouse wheel controls transparency of the triangle

- mouse buttons recolor the triangle.

- mouse movement causes the triangle to shrink (it then slowly grows back)

- Enter switches between windowed and 640x480 fullscreen

- Space changes bit depth (when 16 bits, window color becomes dirty-green instead of blue)

- Pressed keys just lit it with green light

- Esc exits

You may click the "close" button in Linux, and watch the panic yell
"X Server reported a fatal error! Performing emergency shutdown."
(if you strted it from any terminal).
It's when OnDestroy is called "not matter how the window died".
(unfortunately, in this demo OnDestroy does nothing, so don't wait any effects...)

************************************************
_cl_winman_morph3d

it's  from the Freepascal distribution, 
just converted from GLUT to ChebLib.

Following controls were added: 
- mouse wheel controls the speed of the scene.

- numeric key "0" switches between windowed and 1024x768 fullscreen
 
 
************************************************
Fields, properties and method of TCLWindow class

(you should create your own descendant class and implement all the Onxxx methods,
 which are Abstract here!) 

// set it to true when you want to close the app.
// DO NOT call Free from within of one of the "On<>" methods!!!
ExitRequested: boolean;

// check this in OnLoseFocus and OnDestroy,
// and NEVER call ANY OpenGL functions if true!
// signals that application goes down after some svere failure.
EmergencyShutdown: boolean;

// affects all subsequent video mode related function and procedure calls
// there are two separate video mode lists: for 16 and 24/32-bit video modes)
// ALWAYS check it after setting - under Unix it is _always_ false (because
// bit depth switching not supported at all)
// Does NOT immediately change the video mode - although affects
// the functions VidModesNum..VidModeMaxRefreshRate,
// and affects the next SwitchToFullScreenMode() call.
// Ignored in windowed mode. 
property VidModes16bit: boolean


property InFullScreenMode: boolean //read only 

// set it when if your class expects text input instead of scan-codes.
// look details in the description of the OnType method.
// NOT IMPLEMENTED YET FOR LINUX! 
property TextInput: boolean

// use this if you need to do anything with the rendering context.
// note: always use this property, don't store it anywhere else -
// for between the OnIdle calls in some cases OpenGL may be re-loaded
// and window be re-created, and thus context be changed.
property RenderingContext: {$ifdef unix} glXContext {$else} HGLRC {$endif} 
// read only. 

// return window client area dimensions
property DisplayWidth: integer //read only 
property DisplayHeight: integer //read only

// current screen refresh rate. if not fullscreen or not supported then zero.
property RefreshRate: integer //read only 

// tells if the key is held down at the moment.
// always false for mouse wheel "keys" -4 and -5.
property Pressed [index: integer]: boolean //read only

//Mouse cursor position, in window client area coordinates
property MouseX: integer //read only
property MouseY: integer //read only

// does the window exist now?..
// Check in OnDestroy to determine if it was destroyed prematurely.
property WindowExists: boolean //read only

// check it to not draw when window is not visible at all.
property WindowVisible: boolean //read only

// contains the main program cycle. Call it next after Create. 
Procedure MainLoop;

// if compiled without corresponding extensions of XFree86,
// it will report one video mode - the current desktop resolution
function VidModesNum: integer;
function VidModeWidth(i: integer): integer;
function VidModeHeight(i: integer): integer;
// in some cases may return 0 - means 'not supported by OS'!
// ChebLib window always uses maximum refresh rate, supported by system.
function VidModeMaxRefreshRate(i: integer): integer;

// tells only that video mode is in the "official" list.
// Under Windows 98 may return false for some modes (like 320x200)
// but despite this they can be succesfully set.
function VidModeSupported(width, height: integer): boolean;

// if called with invalid width&height, will switch to windowed mode
// and return false.
// Always uses maximum refresh rate for given mode.
// Under Windows tries given parameters anyway (because Windows 9x often
// has some "hidden" video modes which it supports, but doesn't report
// about when asked for supported modes list (for example, 320x200 and
// others below 640x480).
function SwitchToFullscreenMode(width, height: integer): boolean; 

// This version allows you to try to set Hertz value implicitly 
// under Windows tries the Hertz value anyway.
// under Unix refresh rate is ignored - always uses system default.
function SwitchToFullscreenMode(width, height, Hertz: integer): boolean; 

// under Unix doesn't restore window position
procedure SwitchToWindowedMode;

// in game mode, mouse cursor is hidden, and MouseX/MouseY return
// relative coordinates. (and outside of OnMouseMove they always
// return zero!)
// Ggame mode works regardless of fulscreen/windowed state
// NOT FULLY IMPLEMENTED YET! 
property GameMode: boolean

// hide cursor in non-game mode. Cursor will be hidden only if it points
// inside the window client area.
// NOT FULLY IMPLEMENTED YET FOR LINUX! 
property HideCursor: boolean

// performs SwapBuffers, nothing more.
Procedure Flip;

// put your code for setting OpenGL rendering mode defaults here,
// not in OnCreate - because, as I said above, OpenGL may be reloaded
// between the OnIdle calls. If such happens, OnGetFocus will be called.
// OnGetFocus is always called at least once, at startup
procedure OnGetFocus; VIRTUAL; ABSTRACT;

// always called before shutdown (use WindowExists to check if window
// still exists at that time)
procedure OnLoseFocus; VIRTUAL; ABSTRACT;

// it's called one per every system mouse movement message.
// use MouseX and MouseY to obtain coordinates.
procedure OnMouseMove; VIRTUAL; ABSTRACT;

// it's called once at startup, and everytime the window unwraps
// from the minimized state (even if fullscren mode is used)
// and each time when window's size was changed.
// Use DisplayWidth and DisplayHeight to obtain window size.
procedure OnResize; VIRTUAL; ABSTRACT;

// mouse buttons are considered as keys with negative scancodes:
// -1 - left button, -2 - right one, -3 - middle.
// mouse wheel is considered as two keys: up (-4) and down (-5).
// they do receive only OnPress, and Pressed for them is always false.
//
// this structure was choosen for sake of simplicity of key binding
// in the game engine. It also coresponds to the mouse button / wheel
// numbering in X. But scancodes are in MS-DOS format
// ("Esc" = 1, and so on). IMHO, should match the DirectX definitions too. 
procedure OnPress(scancode: integer); VIRTUAL; ABSTRACT;
procedure OnRelease(scancode: integer); VIRTUAL; ABSTRACT;

// if the TextInput property is set to True, and the pressed keys
// represent a valid character, then OnType will be called instead
// of OnPress.
// NOT IMPLEMENTED YET FOR LINUX!
// Character is in UNICODE (utf16) encoding.
procedure OnType(input: WideChar); VIRTUAL; ABSTRACT;

// called once at startup, after window created and OpenGL initialized.
procedure OnCreate; VIRTUAL; ABSTRACT;

// it's called once, at shutdown.
// GUARANTEED - regardles of way the window was closed.
// Check the WindowExists property to determine if window sill exists
// or it was already destroyed.
// note: don't forget to catch all your exceptions yourself, or above said is void! 
procedure OnDestroy; VIRTUAL; ABSTRACT;

// Main cyclic method. Called repeatedly, unless there is anything else to do
// Put your rendering here. 
procedure OnIdle; VIRTUAL; ABSTRACT;