Cheb's Home Page
 
 
 
Orphus system

Cheb's Home Page

Home
Cheb's Game Engine Quake II facelift
Штошник на ушах
 

 

ChebLib window class for Free Pascal:

instead of GLUT...


Download sources and examples v0.9 (95K)

Download pre-compiled demos, for both Windows and Linux (442K)

Bugs:

Under Linux, setting the bit depth for video mode doesn't work: it always uses the desktop default. Also, video mode switching method is a bit perverted (it flips trough them one by one until finds desired one... but at least it works). I suspect, I used obsolete methods and libraries in my work, but this was just what I found using Google. (namely, XFree86VidMode extensions and freeglut and KambiLib sources as reference material)

Well, anyway in my distribution (Mandrake 9.0), to change desktop bit depth or default resolution one should know the root password.

Also note - under Linux, if you'll somehow manage to kill the window in the fullscreen mode by outside means, video mode will _not_ be restored. (It tries anyway, but gets only stream of "0"s from the X server)

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 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;