PDA

View Full Version : Mousespeed in Delphi & OpenGL



Robert Petersson
12-26-2002, 08:04 AM
Hi OpenGL!

Why is the mousespeed/step slower/lower in my program (Delphi/Pascal the only true computer language)
-----------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, ComCtrls, OpenGL, StdCtrls;

type
TForm1 = class(TForm)
StatusBar1: TStatusBar;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean);
private
{ Private declarations }
fPFD:TPixelFormatDescriptor;
fRC:Integer;
fDC:Integer;
nPixelFormat:Integer;
procedure Render;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

//************************************************** ************

procedure TForm1.FormCreate(Sender: TObject);
begin
fDC:=GetDC(Self.Handle);
if fDC<>0 then
begin
FillChar(fPFD,SizeOf(fPFD),#00);
fPFD.nSize:=SizeOf(fPFD);
fPFD.nVersion:=1;
fPFD.dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER or PFD_SUPPORT_GDI;
fPFD.iPixelType:=PFD_TYPE_RGBA;
fPFD.cColorBits:=24;
fPFD.cDepthBits:=32;
fPFD.iLayerType:=PFD_MAIN_PLANE;

nPixelFormat:=ChoosePixelFormat(fDC, @fPFD);
if SetPixelFormat(fDC,nPixelFormat,@fPFD) then
begin
fRC:=wglCreateContext(fDC);
if not wglMakeCurrent(fDC,fRC) then showmessage('fail:wglMakeCurrent');
end
else showmessage('fail:SetPixelFormat');
end
else showmessage('fail:GetDC');
end;

//************************************************** ************

procedure TForm1.FormDestroy(Sender: TObject);
begin
wglMakeCurrent(fDC,0) ;
wglDeleteContext(fRC);
end;

//************************************************** ************

procedure TForm1.Render;
begin
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glVertex2f(-50,-50);
glVertex2f(50,50);
glEnd;
glFlush;
end;

//************************************************** ************

procedure TForm1.FormPaint(Sender: TObject);
begin
Render;
if not SwapBuffers(fDC) then showmessage('fail:SwapBuffers');
end;

//************************************************** ************

procedure TForm1.FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean);
var
E:integer;
begin
glViewPort(0,0,NewWidth,NewHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluOrtho2D(-100,100,-100,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
E:=glGetError;
if E<>GL_NO_ERROR then Resize:=false else Resize:=True;
end;

end.
--------------------------
Best regards

LarsMiddendorf
12-29-2002, 02:24 AM
I've got the strange error that the mousespeed changes with the refresh rate of the monitor. I noticed that the mouse movement in my program was slower when the refresh rate was below 140Hz. Pershaps this is similar to your error.