Ho scaricato il file OpenGL.pas per usare OPENGL con Delphi. Seguendo una guida, ho scritto questo codice:

codice:
procedure TForm12.FormCreate(Sender: TObject);
var
  PFD: TPixelFormatDescriptor;
  FormatIndex: Integer;
begin
FillChar(PFD,sizeof(PFD),0);
with PFD do
begin
  nSize := sizeof(PFD);
  nVersion := 1;
  dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
  iPixelType := PFD_TYPE_RGBA;
  cColorBits := 24;
  cDepthBits := 32;
  iLayerType := PFD_MAIN_PLANE;
end;
FormatIndex := ChoosePixelFormat(Canvas.Handle,@PFD);    // <-------
(*showmessage(inttostr(formatindex));
SetPixelFormat(Canvas.Handle,FormatIndex,@PFD); *)
end;
Purtroppo non so come mai ma la riga indicata genera un errore mooolto generico:
Access violation at address 00000000. Read of address 00000000.

Come mai? Non mi pare di aver sbagliato qualcosa anche perchè sto copiando...

A meno che la versione di OpenGL che ho scaricato è sbagliata... Per altro ho pure dovuto manomettere il codice della Unit, perchè in alcuni punti assegnava valori a variabili dichiarate come costanti VVoVe: ....



EDIT: ho scaricato un'altra versione dell'OPENGL.PAS e almeno quel punto sembra funzionare... Ecco il codice completo:
codice:
var
  Form12: TForm12;
  GlContext: HGLRC;
  ErrorCode: cardinal;//GLenum;
  Init: Boolean = false;
  GlDC: HDC;

implementation

{$R *.dfm}

procedure TForm12.FormCreate(Sender: TObject);
var
  PFD: TPixelFormatDescriptor;
  FormatIndex: Integer;
begin
FillChar(PFD,sizeof(PFD),0);
with PFD do
begin
  nSize := sizeof(PFD);
  nVersion := 1;
  dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
  iPixelType := PFD_TYPE_RGBA;
  cColorBits := 24;
  cDepthBits := 32;
  iLayerType := PFD_MAIN_PLANE;
end;
glDC := getDC(handle);
FormatIndex := ChoosePixelFormat(glDC,@pfd);
if FormatIndex=0 then
  raise Exception.Create('ChoosePixelFormat failed '+IntToStr(GetLastError));
if not SetPixelFormat(glDC,FormatIndex,@pfd) then
  raise Exception.Create('SetPixelFormat failed '+IntToStr(GetLastError));
GLContext := wglCreateContext(glDC);
if GLContext=0 then
  raise Exception.Create('wglCreateContext failed '+IntToStr(GetLastError));
if not wglMakeCurrent(glDC,GLContext) then
  raise Exception.Create('wglMakeCurrent failed '+IntToStr(GetLastError));
Init:=true;
end;

procedure TForm12.FormDestroy(Sender: TObject);
begin
wglMakeCurrent(Canvas.Handle,0);
wglDeleteContext(GlContext);
end;

procedure TForm12.FormPaint(Sender: TObject);
var
  errorCode: Cardinal;
begin
if not Init then exit;
try
glClearColor(0.0,0.4,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);

errorCode := glGetError;
if errorCode <> GL_NO_ERROR then
  raise Exception.Create('Paint Error'+#13#10+gluErrorString(ErrorCode));

except on Ex:exception do
  showmessage(ex.Message);         Eccezione!!!!

end;
end;
Tuttavia nel punto segnalato viene generata nuovamente l'eccezione sopracitata. Non so che dire... Chi mi sa dire qualcosa di + ??