The Dot Docs

DotWindow

DotWindow.pas contains classes to encapsulate an OpenGL rendering context and to attach a rendering context to a Delphi form. Dot manages rendering contexts using the WGL_ARB_pixel_format extension. Some older video cards may not support this extension, in which case they won't be able to run applications based on Dot.

TDotContext

The TDotContext class manages a rendering context.

  TDotContext = class
  public
    constructor Create(DC: HDC; hasFuncPtrs: Boolean);
    procedure SetAttrib(name, value: GLint);
    procedure SetAttrib(name, value: GLfloat);
    procedure QuickPF(rgb, a, z, stencil: Integer);
    function InitGL: Boolean;
    procedure PageFlip;
    procedure MakeCurrent;
    property DC: HDC;
    property RC: HGLRC;
    property IntAttribs[i: Integer]: TDotPFAttribi;
    property FloatAttribs[i: Integer]: TDotPFAttribf;
  end;

When you create a new rendering context (RC), you supply the device context with which the RC is to be associated. You must also specify whether or not the WGL_ARB_pixel_format entry points have already been loaded or not. If not, TDotContext will open an invisible temporary window and create a temporary RC in order to retrieve the function pointers. Your application will be terminated if WGL_ARB_pixel_format is not supported!

Once your context has been created, you can set its pixel format. This is done exactly as if you were to use WGL_ARB_pixel_format directly, namely by specifying named attributes and their values. You can use the SetAttrib() method to set or modify a pixel format attribute. See the WGL_ARB_pixel_format specification for the list of available attributes.

For your convenience, the QuickPF() method provides a quick way to set a standard pixel format. The method takes the desired bit depths of the color, alpha, depth and stencil buffers as arguments and sets the appropriate pixel format attributes. The default pixel format is 24 bits of color and depth, and no destination alpha or stencil, and it is only necessary to call QuickPF() and/or SetAttrib() if you want a different pixel format.

Once all attributes have been set, you can apply your settings and finalize your rendering context. To do so, call the InitGL() method. An exception will be raised at this point if no pixel format can be found with the attributes you requested. If you like, you can handle this error by trying to fall back to a simpler pixel format and calling InitGL() again.

Your rendering context is now ready for use, so you may begin to issue OpenGL calls. If you need to manage more than one RC, you can use the MakeCurrent() method to switch between them. The PageFlip() method swaps the front and back buffers of your framebuffer.

TDotForm

The TDotForm class derives from Delphi's standard TForm, and adds an OpenGL rendering context to it.

  TDotForm = class(TForm)
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Context: TDotContext read FContext;
  end;

To use this class, simply create a form as you always do, and then go to its source code and change the first line of the class declaration to derive from TDotForm instead of TForm. You now have access to a TDotContext object which you can use in your form's OnCreate event handler to initialize OpenGL for your form.

Full screen mode

DotWindow.pas also contains functions to assist in running your application in full screen mode.

procedure dotEnumerateDisplayModes(cb: TDotDisplayModeEnumCB);
function dotSetDisplayMode(w, h, bpp, refresh: Cardinal): Boolean;

The first function, dotEnumerateDisplayModes() will produce a list of all display modes available on the user's system. For each mode, it invokes a callback function that you supply. The callback has the following prototype:

function(w, h, bpp, refresh: Cardinal): Boolean;

The arguments passed to the callback, obviously, are the horizontal and vertical screen resolution, the color depth in bits per pixel, and the vertical refresh rate.

When you have chosen a display mode you want to use, you can use dotSetDisplayMode() to set it. The arguments are identical to the ones described above for the enumeration callback. If you pass zero for all arguments, the function will restore the display settings stored in the user's registry. The function returns TRUE if it succeeded or FALSE otherwise.

After switching to a suitable display resolution, "going full screen" is simply a matter of opening a borderless and maximized form.

The Delphi OpenGL Toolkit was written by Tom Nuydens.
See main page for disclaimer. For updates, visit Delphi3D.