PDA

View Full Version : GLScene Crosshair



Incubii
01-02-2005, 10:51 AM
Hi there this seemed like an appropriate place to put this code snippet. All it does is draw a crosshair that follows the mouse :). Your project must use TGLCanvas module to use this. Make sure you declare the function too so it can be used:D.

I placed my VCL components in a DataModule. This should also work in a normal application


procedure TDataModule1.DrawCrosshair(glc : TGLCanvas);
var
x, y,line_length,ellipse_radius : Integer;
begin
line_length:=16;
ellipse_radius:=8;
with glc do begin
x:=Mouse.CursorPos.X;
y:=Mouse.CursorPos.Y;
PenColor:=clRed; // You can change this to any color: clRed,clBlue,clYellow etc...

// Alpha-transparency antialiasing:
// we render the ellipse twice, the first pass with a very transparent
// wide pen, and a second time with a thinner pen.
PenAlpha:=0.4;
PenWidth:=3;
Ellipse(x-ellipse_radius, y-ellipse_radius, x+ellipse_radius, y+ellipse_radius);
PenAlpha:=0.75;
PenWidth:=2;
Ellipse(x-ellipse_radius, y-ellipse_radius, x+ellipse_radius, y+ellipse_radius);
// Complete the reticle
PenAlpha:=0.3;
PenWidth:=2;
Line(x-line_length, y, x+line_length, y);
Line(x, y-line_length, x, y+line_length);
end;
glc.Free;
end;


Now i use a fullscreen viewer and this is the code


procedure TDataModule1.GLFullScreenViewer1PostRender(Sender: TObject);
var
glc : TGLCanvas;
begin
glc:=TGLCanvas.Create(GLFullScreenViewer1.Width, GLFullScreenViewer1.Height);
DrawCrosshair(glc);
end;


This code was based on the fullscreen demo from GLScene. All i did was rip the crosshair code out into a function on its own. Figured it would be easier to manage if you make it more complex :). Hope this helps people