Bonjour,
Je m'initie à OpenGL en utilisant le projet de test suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
unit Unit1;
 
//Programme par Yoann
//http://delphipage.free.fr/
 
interface
 
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, OpenGl12;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
   RC :HGLRC; //Adresse du contexte graphique où OpenGL dessinera
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.DFM}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
//Creation du contexte graphique pour notre fenêtre
RC:=CreateRenderingContext(Form1.Canvas.Handle,[opGDI],32,0,0,0,0); //Travail en GDI et en 32 bits
wglMakeCurrent(Form1.Canvas.Handle,RC); //Création du contexte graphique pour la fenêtre
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
wglDeleteContext(RC); //Supprime le contexte graphique
end;
 
procedure TForm1.FormResize(Sender: TObject);
begin
glMatrixMode(GL_PROJECTION); //Spécifie la matrice de projection
glLoadIdentity; //Initialise la matrice de projection
gluPerspective(45,Width/Height,1,10); //Définit le champ de vision
glViewport(0,0,Form1.Width, Form1.Height); //Specifie l'espace disponible à l'ecran
glMatrixMode(GL_MODELVIEW);
Form1.Paint; //Redessine la form
end;
 
procedure TForm1.FormPaint(Sender: TObject);
begin
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); //Vide le tampon
glLoadIdentity; //Initialise la matrice de projection
glTranslatef(0,0,-10); //Translation vers les axes X,Y,Z
glBegin(GL_QUADS);//Commence à dessiner le carré
glVertex2f(2,-2); // Position d'un point du carré 1
glVertex2f(-2,-2); // Position d'un point du carré 2
glVertex2f(-2,2); // Position d'un point du carré 3
glVertex2f(2,2 ); // Position d'un point du carré 4
glEnd(); //Finis de dessiner le carré
end;
 
end.
Je n'obtiens qu'une fenêtre vide.
Quelle peut être mon erreur?

Merci de votre aide.
Cordialement
Pierre