IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Dev-C++ Discussion :

devcpp / allegro /winmain


Sujet :

Dev-C++

  1. #1
    Modérateur
    Avatar de ggnore
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 472
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 472
    Par défaut devcpp / allegro /winmain
    Bonjour.

    J'essaie de compiler un exemple d'allegro avec devcpp.

    Mais je récupère ça comme message.

    [Linker error] undefined reference to `WinMain@16'

    Dans Projet>option>Général, j'ai choisi win32 console.

    l'exemple :
    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
     
    #include <cstdlib>
    #include <iostream>
    #include "allegro.h"
     
    int main(int argc, char *argv[])
    {
      BITMAP *bmp;            /* we create a pointer to a virtual screen */
       int x=160, y=100;       /* these will be used to show the target sight */
       int analogmode;
       AL_CONST char *msg;
       int c;
     
       if (allegro_init() != 0)/* you NEED this man! ;-) */
          return 1;
     
       install_keyboard();     /* ahh... read the docs. I will explain only
    			    * joystick specific routines
    			    */
     
       if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
          if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
    	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
    	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
    	 return 1;
          }
       }
     
       set_palette(default_palette);
       clear_bitmap(screen);
       textout_centre_ex(screen, font, "Please center the joystick", SCREEN_W/2,
    		     SCREEN_H/2 - 36, palette_color[255], 0);
       textout_centre_ex(screen, font, "and press a key.", SCREEN_W/2,
    		     SCREEN_H/2 - 20, palette_color[255], 0);
     
       if ((readkey()&0xFF) == 27)
          return 0;
     
       /* the first thing is to initialise the joystick driver */
       if (install_joystick(JOY_TYPE_AUTODETECT) != 0) {
          set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
          allegro_message("Error initialising joystick\n%s\n", allegro_error);
          return 1;
       }
     
       /* make sure that we really do have a joystick */
       if (!num_joysticks) {
          set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
          allegro_message("Error: joystick not found\n");
          return 1;
       }
     
       /* before using the joystick, we have to calibrate it. This loop only
        * calibrates joystick number 0, but you could do the same thing for
        * other sticks if they are present (the num_joysticks variable will 
        * tell you how many there are).
        */
       while (joy[0].flags & JOYFLAG_CALIBRATE) {
          msg = calibrate_joystick_name(0);
     
          clear_bitmap(screen);
          textout_centre_ex(screen, font, msg, SCREEN_W/2, 64, palette_color[255], 0);
          textout_centre_ex(screen, font, "and press a key.", SCREEN_W/2, 80, palette_color[255], 0);
     
          if ((readkey()&0xFF) == 27)
    	 return 0;
     
          if (calibrate_joystick(0) != 0) {
    	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
    	 allegro_message("Error calibrating joystick!\n");
    	 return 1;
          }
       }
     
       /* if this joystick supports analogue input, ask the user whether to
        * use digital or analogue mode. If it is only a digital pad, we don't
        * bother with this question.
       */
       if (joy[0].stick[0].flags & JOYFLAG_ANALOGUE) {
          clear_bitmap(screen);
          textout_centre_ex(screen, font, "Now press 'D' to use a digital",
    			SCREEN_W/2, 64, palette_color[255], 0);
          textout_centre_ex(screen, font, "joystick or 'A' for analogue mode.",
    			SCREEN_W/2, 80, palette_color[255], 0);
     
          for (;;) {
    	 c = readkey()&0xFF;
     
    	 if ((c=='d') || (c=='D')) {
    	    analogmode = FALSE;
    	    break;
    	 }
    	 else if ((c=='a') || (c=='A')) {
    	    analogmode = TRUE;
    	    break;
    	 }
    	 else if (c == 27)
    	    return 0;
          }
       }
       else
          analogmode = FALSE;
     
       drawing_mode(DRAW_MODE_XOR, 0, 0, 0);
       clear_keybuf();
     
       bmp = create_bitmap(320, 200);
       clear_bitmap(bmp);
     
       do {
          poll_joystick();     /* we HAVE to do this to read the joystick */
     
          clear_bitmap(bmp);
     
          textout_centre_ex(bmp, font, joystick_driver->name, 160, 150, palette_color[255], 0);
     
          if (analogmode)
    	 textout_centre_ex(bmp, font, "Analog mode selected", 160, 160, palette_color[255], 0);
          else
    	 textout_centre_ex(bmp, font, "Digital mode selected", 160, 160, palette_color[255], 0);
     
          textout_centre_ex(bmp, font, "Move the joystick all around", 160, 170, palette_color[255], 0);
          textout_centre_ex(bmp, font, "Press any key to exit", 160, 180, palette_color[255], 0);
          textout_centre_ex(bmp, font, "Made by Grzegorz Adam Hankiewicz", 160, 190, palette_color[255], 0);
     
          /* if we detect any buttons, we print a message on the screen */
          for (c=0; c<joy[0].num_buttons; c++) {
    	 if (joy[0].button[c].b)
    	    textprintf_centre_ex(bmp, font, 160, c*10, palette_color[15], 0, "%s pressed", joy[0].button[c].name);
          }
     
          if (!analogmode) {
    	 /* now we have to check individually every possible movement
    	  * and actualize the coordinates of the target sight.
    	  */
    	 if (joy[0].stick[0].axis[0].d1) {
    	    if (x > 0)
    	       x--;
    	    textout_centre_ex(bmp, font, "Left", 120, 100, palette_color[255], 0);
    	 }
    	 if (joy[0].stick[0].axis[0].d2) {
    	    if (x < 319)
    	       x++;
    	    textout_centre_ex(bmp, font, "Right", 200, 100, palette_color[255], 0);
    	 }
    	 if (joy[0].stick[0].axis[1].d1) {
    	    if (y > 0)
    	       y--;
    	    textout_centre_ex(bmp, font, "Up", 160, 70, palette_color[255], 0);
    	 }
    	 if (joy[0].stick[0].axis[1].d2) {
    	    if (y < 199)
    	       y++;
    	    textout_centre_ex(bmp, font, "Down", 160, 130, palette_color[255], 0);
    	 }
          }
          else {
    	 /* yeah! Remember the 'ifs' of the digital part? This looks
    	  * much better, only 2 lines.
    	  */
    	 x += joy[0].stick[0].axis[0].pos/40;
    	 y += joy[0].stick[0].axis[1].pos/40;
     
    	 /* for informational purposes, show the input values on screen */
             textprintf_ex(bmp, font, 0,  0, palette_color[255], 0, "Axis 0: %d", joy[0].stick[0].axis[0].pos);
             textprintf_ex(bmp, font, 0, 10, palette_color[255], 0, "Axis 1: %d", joy[0].stick[0].axis[1].pos);
     
    	 /* by checking if the values were positive or negative, we
    	  * can know in which the direction the user pulled the joy.
    	  */
    	 if (joy[0].stick[0].axis[0].pos/40 < 0) 
    	    textout_centre_ex(bmp, font, "Left", 120, 100, palette_color[255], 0);
     
    	 if (joy[0].stick[0].axis[0].pos/40 > 0) 
    	    textout_centre_ex(bmp, font, "Right", 200, 100, palette_color[255], 0);
     
    	 if (joy[0].stick[0].axis[1].pos/40 < 0) 
    	    textout_centre_ex(bmp, font, "Up", 160, 70, palette_color[255], 0);
     
    	 if (joy[0].stick[0].axis[1].pos/40 > 0) 
    	    textout_centre_ex(bmp, font, "Down", 160, 130, palette_color[255], 0);
     
    	 /* WARNING! An analog joystick can move more than 1 pixel at
    	  * a time and the checks we did with the digital part don't
    	  * work any longer because the steps of the target sight could
    	  * 'jump' over the limits.
    	  * To avoid this, we just check if the target sight has gone
    	  * out of the screen. If yes, we put it back at the border.
    	  */
    	 if (x > 319)
    	    x = 319;
     
    	 if (x < 0) 
    	    x = 0;
     
    	 if (y < 0) 
    	    y = 0;
     
    	 if (y > 199) 
    	    y = 199;
          }
     
          /* this draws the target sight. */
          circle(bmp, x, y, 5, palette_color[255]);
          putpixel(bmp, x, y, palette_color[255]);
          putpixel(bmp, x+1, y, palette_color[255]);
          putpixel(bmp, x, y+1, palette_color[255]);
          putpixel(bmp, x-1, y, palette_color[255]);
          putpixel(bmp, x, y-1, palette_color[255]);
          putpixel(bmp, x+5, y, palette_color[255]);
          putpixel(bmp, x, y+5, palette_color[255]);
          putpixel(bmp, x-5, y, palette_color[255]);
          putpixel(bmp, x, y-5, palette_color[255]);
     
          blit(bmp, screen, 0, 0, SCREEN_W/2 - 160, SCREEN_H/2 - 100, 320, 200);
     
       } while (!keypressed());
     
       destroy_bitmap(bmp);
     
       return 0;
     
    }
    J'ai utilisé ce tutorial :
    http://kaiser-edouard.developpez.com...tie1/#LIII-A-2

    j'ai donc fait ça :
    La méthode est la même que pour le linkage statique sauf qu'au lieu de spécifier la longue liste des library d'Allegro il suffira juste de mettre dans la section Editeur de liens l'option : -lalleg.
    Toutes les vertus des hommes se perdent dans l’intérêt comme les fleuves se perdent dans la mer.
    N'oubliez pas de consulter les FAQ Linux et les cours et tutoriels Linux

  2. #2
    Rédacteur

    Avatar de gege2061
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juin 2004
    Messages
    5 840
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur de base de données

    Informations forums :
    Inscription : Juin 2004
    Messages : 5 840
    Par défaut
    Salut,
    à la fin du main, il faut un END_OF_MAIN() :

    Citation Envoyé par [url=http://kaiser-edouard.developpez.com/tutoriels/allegro/partie1/#LIII-D
    Premier programme[/url]]Etant donné qu'Allegro est multi plateforme, il fallait trouver un moyen de rendre la fonction main compatible. Car chaque plateforme possède sa propre implémentation de main (winmain sous windows etc...) Pour cela il existe la macro END_OF_MAIN() qui se chargera de remplacer le main codé par un main en adéquation avec la plateforme ciblé. De ce fait, la fonction main d'un programme se basant sur Allegro aura toujours cette syntaxe :
    ...

  3. #3
    Modérateur
    Avatar de ggnore
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 472
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 472
    Par défaut
    Citation Envoyé par gege2061
    Salut,
    à la fin du main, il faut un END_OF_MAIN() :

    Citation Envoyé par [url=http://kaiser-edouard.developpez.com/tutoriels/allegro/partie1/#LIII-D
    Premier programme[/url]]Etant donné qu'Allegro est multi plateforme, il fallait trouver un moyen de rendre la fonction main compatible. Car chaque plateforme possède sa propre implémentation de main (winmain sous windows etc...) Pour cela il existe la macro END_OF_MAIN() qui se chargera de remplacer le main codé par un main en adéquation avec la plateforme ciblé. De ce fait, la fonction main d'un programme se basant sur Allegro aura toujours cette syntaxe :
    ...
    Merci...

    J'espère revenir bientôt avec un vrai problème
    Toutes les vertus des hommes se perdent dans l’intérêt comme les fleuves se perdent dans la mer.
    N'oubliez pas de consulter les FAQ Linux et les cours et tutoriels Linux

  4. #4
    Modérateur
    Avatar de ggnore
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 472
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 472
    Par défaut
    Tant que je t'ai sous main , est ce que tu pourrais me dire comment créer une application utilisant le GUI windows ?

    J'ai changé dans projet>options>général

    Après, je me suis dit qu'il fallait mettre winmain à la place de main, mais ça met :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    223 C:\Dev-Cpp\main.cpp `_mangled_main' undeclared (first use this function) 
      (Each undeclared identifier is reported only once for each function it appears in.)
    Je vais aller trouver la doc de devcpp et d'allegro ... Sous peine de m'exposer à un RTFM
    Toutes les vertus des hommes se perdent dans l’intérêt comme les fleuves se perdent dans la mer.
    N'oubliez pas de consulter les FAQ Linux et les cours et tutoriels Linux

  5. #5
    Rédacteur

    Avatar de gege2061
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juin 2004
    Messages
    5 840
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur de base de données

    Informations forums :
    Inscription : Juin 2004
    Messages : 5 840
    Par défaut
    Citation Envoyé par ggnore
    Tant que je t'ai sous main , est ce que tu pourrais me dire comment créer une application utilisant le GUI windows ?

    J'ai changé dans projet>options>général

    Après, je me suis dit qu'il fallait mettre winmain à la place de main, mais ça met :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    223 C:\Dev-Cpp\main.cpp `_mangled_main' undeclared (first use this function) 
      (Each undeclared identifier is reported only once for each function it appears in.)
    Il faut créer un nouveau projet de type GUI Win32 ou quelque chose approchant.
    t'as inclu windows.h ?
    Tu es un peut en retard, dev-cpp c'est fini, faut passer à code::blocks !


    Citation Envoyé par ggnore
    Je vais aller trouver la doc de devcpp et d'allegro ... Sous peine de m'exposer à un RTFM
    Nan pour toi ça sera un peu plus piquant

Discussions similaires

  1. [devcpp] debugger
    Par Heimdall dans le forum Dev-C++
    Réponses: 2
    Dernier message: 28/06/2004, 23h54
  2. Problème dans la déclaration de Winmain
    Par lvdnono dans le forum DirectX
    Réponses: 3
    Dernier message: 29/05/2004, 13h38
  3. erreurs opengl avec devcpp
    Par Vermin dans le forum OpenGL
    Réponses: 2
    Dernier message: 13/04/2004, 14h50
  4. [allegro]passage de pointeur sur image
    Par Gonath dans le forum Autres éditeurs
    Réponses: 3
    Dernier message: 13/12/2003, 18h47
  5. [Directx avec devcpp...]
    Par Gonath dans le forum DirectX
    Réponses: 1
    Dernier message: 21/08/2003, 16h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo