Difference between revisions of "ZenGL Tutorial 2/fr"
m (Fixed syntax highlighting) |
|||
(4 intermediate revisions by one other user not shown) | |||
Line 19: | Line 19: | ||
Une fois que vous avez créé une fonte, vous avez besoin de suivre ces étapes pour dessiner dans la fenêtre ZenGL. | Une fois que vous avez créé une fonte, vous avez besoin de suivre ces étapes pour dessiner dans la fenêtre ZenGL. | ||
− | == | + | == Créer un programme == |
− | * | + | *Créez un nouveau programme Pascal et ajouter une référence à ZenGL comme expliqué dans le premier tutoriel. |
− | * | + | *Créez ces dossiers : |
<code>projectname\bin | <code>projectname\bin | ||
Line 31: | Line 31: | ||
projectname\project</code> | projectname\project</code> | ||
− | * | + | *Enregistrez votre projet dans "''projectname\project''". |
− | * | + | *Mettez la font que vous avez créée dans "''projectname\data''" |
− | * | + | *Allez à ''Project > Options > Paths'' dans ''Target file name'' écrivez "''..\bin\project1''". |
− | == | + | == Ajouter du code == |
Variables: | Variables: | ||
− | <syntaxhighlight>var | + | <syntaxhighlight lang=pascal>var |
dirRes : String {$IFNDEF DARWIN} = '../data/' {$ENDIF}; // this is the directory where resources are placed | dirRes : String {$IFNDEF DARWIN} = '../data/' {$ENDIF}; // this is the directory where resources are placed | ||
fnt : zglPFont; // this is the font we will use </syntaxhighlight> | fnt : zglPFont; // this is the font we will use </syntaxhighlight> | ||
− | + | Chargement de la fonte dans dans un variable : | |
− | <syntaxhighlight>procedure Init; | + | <syntaxhighlight lang=pascal>procedure Init; |
begin | begin | ||
fnt := font_LoadFromFile( dirRes + 'Agency FB-Regular-18pt.zfi' ); | fnt := font_LoadFromFile( dirRes + 'Agency FB-Regular-18pt.zfi' ); | ||
end; </syntaxhighlight> | end; </syntaxhighlight> | ||
− | + | Procédure de dessin (là nous allons dessinez notre texte avec la fonte chargée) : | |
− | <syntaxhighlight>procedure Draw; | + | <syntaxhighlight lang=pascal>procedure Draw; |
var | var | ||
rect: zglTRect; | rect: zglTRect; | ||
Line 72: | Line 72: | ||
end; </syntaxhighlight> | end; </syntaxhighlight> | ||
− | + | C'est un peu de code pour sortir de notre application en pressant ESC : | |
− | <syntaxhighlight>procedure Timer; | + | <syntaxhighlight lang=pascal>procedure Timer; |
begin | begin | ||
if key_Press( K_ESCAPE ) Then zgl_Exit(); | if key_Press( K_ESCAPE ) Then zgl_Exit(); | ||
Line 79: | Line 79: | ||
end; </syntaxhighlight> | end; </syntaxhighlight> | ||
− | == | + | == Résultat == |
− | + | Vous pouvez voir le texte avec la fonte que nous avons créé et un autre texte mis à l'échelle et avec de l'alpha. | |
[[Image:zengltext.png]] | [[Image:zengltext.png]] | ||
− | + | Le code résultant est quelque chose comme ceci : | |
− | <syntaxhighlight>program project1; | + | <syntaxhighlight lang=pascal>program project1; |
{$IFDEF WINDOWS} | {$IFDEF WINDOWS} |
Latest revision as of 12:34, 3 March 2020
│
English (en) │
español (es) │
français (fr) │
русский (ru) │
ZenGL |
Tutoriel 1 |
Tutoriel 2 |
Tutoriel 3 |
Edit
Ce tutoriel vous montre comment créer une fonte ZenGL (.zfi) et comment dessiner du texte.
Créer une fonte ZenGL
Pour créer une fonte ZenGL, vous avez besoin télécharger ZenFont qui est un générateur de fonte.
Après l'avoir obtenu, ouvrez-le et vous verrez quelque chose comme ceci :
Agency FB-Regular-18pt.zfi
Utilisez les options pour personnaliser votre fonte puis pressez sur "Save font" et choisissez le nom de fichier que vous voulez (certain nom de fichier sont générés automatiquement avec le nom de la fonte et sa taille. Les fichiers générés sont le fichier .zfi et quelques images .tga.
Une fois que vous avez créé une fonte, vous avez besoin de suivre ces étapes pour dessiner dans la fenêtre ZenGL.
Créer un programme
- Créez un nouveau programme Pascal et ajouter une référence à ZenGL comme expliqué dans le premier tutoriel.
- Créez ces dossiers :
projectname\bin
projectname\data
projectname\project
- Enregistrez votre projet dans "projectname\project".
- Mettez la font que vous avez créée dans "projectname\data"
- Allez à Project > Options > Paths dans Target file name écrivez "..\bin\project1".
Ajouter du code
Variables:
var
dirRes : String {$IFNDEF DARWIN} = '../data/' {$ENDIF}; // this is the directory where resources are placed
fnt : zglPFont; // this is the font we will use
Chargement de la fonte dans dans un variable :
procedure Init;
begin
fnt := font_LoadFromFile( dirRes + 'Agency FB-Regular-18pt.zfi' );
end;
Procédure de dessin (là nous allons dessinez notre texte avec la fonte chargée) :
procedure Draw;
var
rect: zglTRect;
begin
text_Draw( fnt, 0, 0, 'Sample Text. Press ESC to EXIT.' );
text_DrawEx( fnt, 32, 32, 1.5, 0, 'Sample Text with DrawEx - Scale 1.5 - Alpha 150', 150 );
rect.H:=128;
rect.W:=400;
rect.X:=0;
rect.Y:=96;
pr2d_rect(rect.X,rect.Y,rect.W,rect.H,$FFFFFF,100);
text_DrawInRect(fnt,rect,
'Sample multiline text in rect.' + #10 +
'Sample multiline text in rect.'+ #10 +
'Sample multiline text in rect.');
end;
C'est un peu de code pour sortir de notre application en pressant ESC :
procedure Timer;
begin
if key_Press( K_ESCAPE ) Then zgl_Exit();
key_ClearState();
end;
Résultat
Vous pouvez voir le texte avec la fonte que nous avons créé et un autre texte mis à l'échelle et avec de l'alpha.
Le code résultant est quelque chose comme ceci :
program project1;
{$IFDEF WINDOWS}
{$R *.res}
{$ENDIF}
{$DEFINE STATIC}
uses
{$IFNDEF STATIC}
zglHeader
{$ELSE}
zgl_main,
zgl_screen,
zgl_window,
zgl_timers,
zgl_keyboard,
zgl_font,
zgl_text,
zgl_textures,
zgl_textures_tga,
zgl_primitives_2d,
zgl_utils,
zgl_math_2d
{$ENDIF}
;
var
dirRes : String {$IFNDEF DARWIN} = '../data/' {$ENDIF};
fnt : zglPFont;
procedure Init;
begin
fnt := font_LoadFromFile( dirRes + 'Agency FB-Regular-18pt.zfi' );
end;
procedure Draw;
var
rect: zglTRect;
begin
text_Draw( fnt, 0, 0, 'Sample Text. Press ESC to EXIT.' );
text_DrawEx( fnt, 32, 32, 1.5, 0, 'Sample Text with DrawEx - Scale 1.5 - Alpha 150', 150 );
rect.H:=128;
rect.W:=400;
rect.X:=0;
rect.Y:=96;
pr2d_rect(rect.X,rect.Y,rect.W,rect.H,$FFFFFF,100);
text_DrawInRect(fnt,rect,
'Sample multiline text in rect.' + #10 +
'Sample multiline text in rect.'+ #10 +
'Sample multiline text in rect.');
end;
procedure Timer;
begin
if key_Press( K_ESCAPE ) Then zgl_Exit();
key_ClearState();
end;
Begin
{$IFNDEF STATIC}
zglLoad( libZenGL );
{$ENDIF}
timer_Add( @Timer, 16 );
zgl_Reg( SYS_LOAD, @Init );
zgl_Reg( SYS_DRAW, @Draw );
zgl_Enable( APP_USE_UTF8 );
wnd_SetCaption( 'Sample Text' );
wnd_ShowCursor( TRUE );
scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
zgl_Init();
End.