I try to develop a paint algorithm via SDL_GFX unit. Some codes where I started to do this below. But I've got some problem with this code. When I started to move mouse faster , my algorithm is become slow and don't paint some pixels. I think this effect is for not detecting to faster mouse movements. At the end, I used a good timer from DelphiX and set its interval to 1 for increasing drawing speed and detecting fast mouse movements but nothing has changed. Her is my code:
Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, SDL, sdl_gfx, DXClass, SDLUtils, StdCtrls, gl;
type
TForm1 = class(TForm)
Panel1: TPanel;
DXTimer1: TDXTimer;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Screen : PSDL_Surface;
Pushed: boolean;
time1: cardinal;
Frames, TO2: GLInt;
seconds, fps : GLFloat;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SDL_putenv('SDL_VIDEODRIVER=windib');
SDL_putenv(PChar('SDL_WINDOWID=' + inttostr(Integer(Panel1.Handle))));
SDL_Init(SDL_INIT_VIDEO);
Screen := SDL_SetVideoMode(Panel1.ClientWidth, Panel1.ClientHeight, 32,
SDL_SWSURFACE or SDL_DOUBLEBUF);
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
var
event: TSDL_Event;
RECT: TSDL_Rect;
begin
//Let's Paint
if (SDL_PollEvent(@event) > 0 ) then
begin
case event.type_ of
SDL_MOUSEBUTTONDOWN: pushed := true;
SDL_MOUSEBUTTONUP: pushed := false;
SDL_MOUSEMOTION:
if pushed then
begin
RECT := SDLRect(event.Motion.x - 5, event.Motion.y - 5, event.motion.x + 5, event.motion.y + 5);
SDL_Gfx.filledCircleRGBA(Screen, event.Motion.x, event.Motion.y, 5, 255,0,0,255);
SDL.SDL_UpdateRects(Screen, 1, @RECT);
end;
end;
//Lets calc to FPS
Inc( Frames );
time1 := SDL_GetTicks;
if ( time1 - TO2 >= 1000 ) then
begin
seconds := ( time1 - TO2 ) / 1000.0;
fps := Frames / seconds;
Self.Caption := IntToStr(frames) + ' frames in ' + FloatToStr(seconds) + ' seconds = ' + FloatToStr(FPS) + ' FPS';
TO2 := time1;
Frames := 0;
end;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SDL.SDL_FreeSurface(Screen);
SDL_Quit;
end;
end.
Any idea about it? Why is some pixels don't paint when I move mouse fastly and what's the solution?
Note: I try other SDL painting algorithms except "SDL_Gfx.filledCircleRGBA" but the problem is continue.
Bookmarks