SDL2 Les pointeurs
Résolu/Fermé
poparnassus
Messages postés
426
Date d'inscription
vendredi 28 mars 2014
Statut
Membre
Dernière intervention
25 décembre 2019
-
12 avril 2016 à 01:58
poparnassus Messages postés 426 Date d'inscription vendredi 28 mars 2014 Statut Membre Dernière intervention 25 décembre 2019 - 15 avril 2016 à 23:56
poparnassus Messages postés 426 Date d'inscription vendredi 28 mars 2014 Statut Membre Dernière intervention 25 décembre 2019 - 15 avril 2016 à 23:56
2 réponses
jisisv
Messages postés
3645
Date d'inscription
dimanche 18 mars 2001
Statut
Modérateur
Dernière intervention
15 janvier 2017
934
12 avril 2016 à 03:17
12 avril 2016 à 03:17
Je n'ai évidemment pas testé tout ton code, mais si tu ouvre l'oeil, le bon, et que tu lis:
warning: unused variable 'rectangleB' [-Wunused-variable]
C'est une notification du compilateur indiquant que ta variable rectangleB est définie mais non utilisée. Si tu ne l'utilises nulle part, supprime la.
warning: unused variable 'rectangleB' [-Wunused-variable]
C'est une notification du compilateur indiquant que ta variable rectangleB est définie mais non utilisée. Si tu ne l'utilises nulle part, supprime la.
Pierre1310
Messages postés
8564
Date d'inscription
lundi 21 décembre 2015
Statut
Membre
Dernière intervention
21 juillet 2020
650
12 avril 2016 à 09:08
12 avril 2016 à 09:08
Salut,
Si tu veux faire des pointeurs propre, utilise l'allocation dynamique quand tu les déclarent (malloc).
Si tu veux faire des pointeurs propre, utilise l'allocation dynamique quand tu les déclarent (malloc).
poparnassus
Messages postés
426
Date d'inscription
vendredi 28 mars 2014
Statut
Membre
Dernière intervention
25 décembre 2019
30
12 avril 2016 à 11:30
12 avril 2016 à 11:30
ca se fait dans la structure ou dans la fonction ?
Pierre1310
Messages postés
8564
Date d'inscription
lundi 21 décembre 2015
Statut
Membre
Dernière intervention
21 juillet 2020
650
12 avril 2016 à 11:32
12 avril 2016 à 11:32
Dans la structure mais renseignes toi, ça fait un moment que je n'ai pas fait de C, tu m'as mis le doute ^^
poparnassus
Messages postés
426
Date d'inscription
vendredi 28 mars 2014
Statut
Membre
Dernière intervention
25 décembre 2019
30
12 avril 2016 à 13:44
12 avril 2016 à 13:44
honnetement j'essaye plein de truc mes ca marche pas
ma structure:
Ma fonctio affichage:
j'initialise ma structure
||=== Build: Debug in 6wd_SDL2_test (compiler: GNU GCC Compiler) ===|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c||In function 'intialisationAffichage':|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c|66|warning: unused variable 'ArrierePlan' [-Wunused-variable]|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c||In function 'ArrierePlan':|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c|460|error: expected expression before '/' token|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c|454|warning: unused variable 'rectangle1' [-Wunused-variable]|
||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
ma structure:
typedef struct Affichage Affichage; struct Affichage { //Fenetre //int WIDTH, HEIGHT; int rax ; int ray ; int raw; int rah ; SDL_Texture *ArrierePlan; SDL_Rect *rectangle1; SDL_Rect *rectangleA; SDL_Rect *rectangleB; SDL_Rect *rectangleX; SDL_Rect *rectangleY; };
Ma fonctio affichage:
void ArrierePlan(char *titre,Affichage *affichage) { affichage->ArrierePlan = NULL; //affichage->Texture = NULL; //Creation de la fenetre screen = SDL_CreateWindow(titre,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,WINDOW_W,WINDOW_H,SDL_WINDOW_SHOWN); //Creation du renderer renderer = SDL_CreateRenderer(screen,-1,SDL_RENDERER_ACCELERATED); if (screen == NULL || renderer == NULL) { printf("Impossible d'initialiser le mode ecran %s ,\n", SDL_GetError()); } SDL_SetRenderDrawColor(renderer, 255, 0, 0, 0); SDL_RenderClear(renderer); //chargement de l'image de fond // affichage->ArrierePlan = SDL_LoadBMP("6wd.bmp"); //SDL_CreateTextureFromSurface(renderer, affichage->ArrierePlan); int r1w =WINDOW_W , r1h = WINDOW_H/4; SDL_Rect *rectangle1 ; affichage->rectangle1->x = 20; affichage->rectangle1->y = 20; affichage->rectangle1->w = r1w - (affichage->rectangle1->x*2); affichage->rectangle1->h = r1h - (affichage->rectangle1->y*2); SDL_SetRenderDrawColor(renderer,255,255,255,255); // blanc SDL_RenderFillRect(renderer,affichage->rectangle1);
j'initialise ma structure
void intialisationAffichage(Affichage *affichage) { SDL_Texture *ArrierePlan = NULL; affichage->rectangle1->x = 0; affichage->rectangle1->y = 0; affichage->rectangle1->w = 0; affichage->rectangle1->h = 0; affichage->rax = 0; affichage->ray = 0; affichage->raw = 0; affichage->rah = 0; affichage->rectangleA->x = 0; affichage->rectangleA->y = 0; affichage->rectangleA->w = 0; affichage->rectangleA->h = 0; affichage->rectangleB->x = 0; affichage->rectangleB->y = 0; affichage->rectangleB->w = 0; affichage->rectangleB->h = 0; affichage->rectangleY->x = 0; affichage->rectangleY->y = 0; affichage->rectangleY->w = 0; affichage->rectangleY->h = 0; affichage->rectangleX->x = 0; affichage->rectangleX->y = 0; affichage->rectangleX->w = 0; affichage->rectangleX->h = 0; }
||=== Build: Debug in 6wd_SDL2_test (compiler: GNU GCC Compiler) ===|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c||In function 'intialisationAffichage':|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c|66|warning: unused variable 'ArrierePlan' [-Wunused-variable]|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c||In function 'ArrierePlan':|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c|460|error: expected expression before '/' token|
C:\Users\Nico\Desktop\Projet C\6wd_SDL2_test\fonction.c|454|warning: unused variable 'rectangle1' [-Wunused-variable]|
||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
Pierre1310
Messages postés
8564
Date d'inscription
lundi 21 décembre 2015
Statut
Membre
Dernière intervention
21 juillet 2020
650
12 avril 2016 à 13:53
12 avril 2016 à 13:53
Il y a quelque chose qui n'est pas clair dans ton code.
D'ou sort le x? Tu tu dis qu'il fait partis de rectangle1 qui est un pointeur de l'enssemble SDL_Rect donc x fait parti de SDL_Rect?
SDL_Rect *rectangle1; affichage->rectangle1->x = 0;
D'ou sort le x? Tu tu dis qu'il fait partis de rectangle1 qui est un pointeur de l'enssemble SDL_Rect donc x fait parti de SDL_Rect?
poparnassus
Messages postés
426
Date d'inscription
vendredi 28 mars 2014
Statut
Membre
Dernière intervention
25 décembre 2019
30
Modifié par poparnassus le 12/04/2016 à 14:24
Modifié par poparnassus le 12/04/2016 à 14:24
SDL_Rect rectangle1 ; rectangle1.x = 20; rectangle1.y = 20; rectangle1.w = r1w - (rectangle1.x*2); rectangle1.h = r1h - (rectangle1.y*2); SDL_SetRenderDrawColor(renderer,255,255,255,255); // blanc SDL_RenderFillRect(renderer, &rectangle1);
C'est le code sans utiliser de pointeur, ca fonctionne.
SDL_Rect Fait partie de la librairie SDL2
En faite SDL_Rect prend 4 variable x,y,w,h
(x,y) position du rectangle
w Longueur
h Hauteur
12 avril 2016 à 13:49
pour le rectangleA par ex je l'utilise mais ca marche pas!
j'ai mal fait un truc à mon avis