Warning: This site is under construction, most links will be broken.

LightX API -> lxgfx -> cb_beforeendframe

Last modified on Tue, 17th Apr 2007 at 22:23 UTC by zipplet

lxgfx.cb_beforeendframe


cb_beforeendframe: procedure(lxgfx: tlxgfx) of object;


This callback is invoked by lxgfx when lxgfx.endframe is called, just before lxgfx.endframe finalises the current frame. A reference to the LightX graphics object that called the callback is passed.

You can use this callback to draw overlays such as debug messages, status icons for online games, timers, etc. The mouse input class for lxinput hooks this callback to draw the mouse cursor, however it still calls your original hook after (setting up a chain).

The mouse input class will also preserve your function pointer if you set it before setting up the mouse input class. This is important to keep in mind - the following sequence of pseudocode will break your application:

{ hook beforeendframe }
lxgfx.cb_beforeendframe := myfunction;
{ initialise the mouse input }
lxinputmouse.initialise(lxgfx);
.....
{ unhook beforeendframe - we dont need "myfunction" to be called anymore }
lxgfx.cb_beforeendframe := nil;
{ oops! no more mouse cursor... }


The correct thing to do would be to destroy the mouse input class, unhook the function, and then recreate the mouse input class. Hooks must always be removed in the reverse order that they were added to preserve the chain.

Setting up a chain is easy, you should hook like this:

old_hook = lxgfx.cb_beforeendframe;
lxgfx.cb_beforeendframe := myfunction;


Then in your callback function:

procedure myfunction;
begin
  { draw our own stuff }
  lxgfx.draw .....
  { call old hook }
  if assigned(old_hook) then old_hook;
end;


Unhooking:

lxgfx.cb_beforeendframe := old_hook;


Class: lxgfx