Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
projetZ1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Corentin CHIEN KAN FOON
projetZ1
Commits
ce323bb6
Commit
ce323bb6
authored
3 years ago
by
mathieu
Browse files
Options
Downloads
Patches
Plain Diff
affichage hello world compris et fait
parent
7b80c7cd
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
affichage_txt/mathieu/main.c
+37
-2
37 additions, 2 deletions
affichage_txt/mathieu/main.c
with
37 additions
and
2 deletions
affichage_txt/mathieu/main.c
+
37
−
2
View file @
ce323bb6
#include
"util_sdl.h"
#define PATH_FONT "/home/local.isima.fr/mavilledie4/shared/projetZ1/exemples_executables/fonts/Pacifico.ttf"
#define TAILLE_FONT 65
int
main
()
{
...
...
@@ -37,13 +38,47 @@ int main()
if
(
renderer
==
NULL
)
if
(
end_sdl
(
0
,
"ERROR RENDERER CREATION"
,
window
,
renderer
)
==
-
1
)
return
EXIT_FAILURE
;
/******* fin initialisation de la sdl *************/
if
(
TTF_Init
()
<
0
)
if
(
end_sdl
(
0
,
"Couldn't initialize SDL TTF"
,
window
,
renderer
)
==
-
1
)
return
EXIT_FAILURE
;
/******* fin initialisation de la sdl *************/
TTF_Font
*
font
=
NULL
;
// la variable 'police de caractère'
font
=
TTF_OpenFont
(
PATH_FONT
,
TAILLE_FONT
);
// La police à charger, la taille désirée
if
(
font
==
NULL
)
if
(
end_sdl
(
0
,
"Can't load font"
,
window
,
renderer
)
==
-
1
)
return
EXIT_FAILURE
;
TTF_SetFontStyle
(
font
,
TTF_STYLE_ITALIC
);
// en italique, gras
SDL_Color
color
=
{
250
,
250
,
250
,
255
};
// la couleur du texte
SDL_Surface
*
text_surface
=
NULL
;
// la surface (uniquement transitoire)
text_surface
=
TTF_RenderText_Blended
(
font
,
"Hello World !"
,
color
);
// création du texte dans la surface
if
(
text_surface
==
NULL
)
if
(
end_sdl
(
0
,
"Can't create text surface"
,
window
,
renderer
)
==
-
1
)
return
EXIT_FAILURE
;
SDL_Texture
*
text_texture
=
NULL
;
// la texture qui contient le texte
text_texture
=
SDL_CreateTextureFromSurface
(
renderer
,
text_surface
);
// transfert de la surface à la texture
if
(
text_texture
==
NULL
)
end_sdl
(
0
,
"Can't create texture from surface"
,
window
,
renderer
);
SDL_FreeSurface
(
text_surface
);
// la texture ne sert plus à rien
SDL_Rect
pos
=
{
0
,
0
,
0
,
0
};
// rectangle où le texte va être positionné
SDL_QueryTexture
(
text_texture
,
NULL
,
NULL
,
&
pos
.
w
,
&
pos
.
h
);
// récupération de la taille (w, h) du texte
SDL_GetWindowSize
(
window
,
&
pos
.
x
,
&
pos
.
y
);
pos
.
x
=
(
pos
.
x
-
pos
.
w
)
/
2
;
pos
.
y
=
(
pos
.
y
-
pos
.
h
)
/
2
;
SDL_RenderCopy
(
renderer
,
text_texture
,
NULL
,
&
pos
);
// Ecriture du texte dans le renderer
SDL_DestroyTexture
(
text_texture
);
// On n'a plus besoin de la texture avec le texte
SDL_RenderPresent
(
renderer
);
SDL_Delay
(
2000
);
SDL_DestroyTexture
(
text_texture
);
TTF_Quit
();
end_sdl
(
1
,
"fermeture ok"
,
window
,
renderer
);
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment