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

Qt Discussion :

Intégration de SDL dans QT


Sujet :

Qt

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    554
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 554
    Points : 181
    Points
    181
    Par défaut Intégration de SDL dans QT
    Bonjour à tous,

    j'ai donc suivi le tutoriel à l'adresse suivante : http://irmatden.developpez.com/tutoriels/sdl/

    Pour cela, j'ai créé un projet QT sous Code Blocks, le projet de base marche très bien avec l'affichage du bouton quit.

    Puis j'ai rajouté le code du tutoriel. Voici donc mon main.cpp :

    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
     
    #include <QApplication>
    #include <QFont>
    #include <QPushButton>
    #include <QWidget>
    #include <QShowEvent>
     
    #ifdef Q_WS_WIN
    #include <SDL.h>
    #elif defined Q_WS_X11
    #include <SDL/SDL.h>
    #endif
     
    /* PIEGE: main est redéfini par SDL.h comme SDL_Main.
    		  On retire donc la définition puisque Qt le gère
    */
    #undef main
     
    #include <vector>
    #include <cstdlib>
    #include <ctime>
     
    class SDLWidget : public QWidget
    {
    	Q_OBJECT
     
    public:
    	SDLWidget()
    	: windowInitialized(false), screen(0), StarNumbers(100)
    	{
    		setAttribute(Qt::WA_PaintOnScreen);
    		setAttribute(Qt::WA_NoSystemBackground);
     
    		starfield.resize(100);
    		initStarfield();
     
    		// Le bon vieux mode 13h (simulé, c'est sûr :p )
    		resize(320, 200);
    	}
     
    	virtual ~SDLWidget()
    	{
    		SDL_Quit();
    	}
     
    protected:
    	virtual void showEvent(QShowEvent *e)
    	{
    		(void)e;
     
    		if(!windowInitialized)
    		{
    			// C'est ici qu'on dis à SDL d'utiliser notre widget
    			char windowid[64];
    #ifdef Q_WS_WIN
    			sprintf(windowid, "SDL_WINDOWID=0x%lx", reinterpret_cast<qlonglong>(winId()));
    #elif defined Q_WS_X11
    			sprintf(windowid, "SDL_WINDOWID=0x%lx", winId());
    #else
    			qFatal("Fatal: cast du winId() inconnu pour votre plate-forme; toute information est la bienvenue!");
    #endif
    			SDL_putenv(windowid);
     
    			// Initialisation du système vidéo de SDL
    			SDL_Init(SDL_INIT_VIDEO);
    			screen = SDL_SetVideoMode(width(), height(), 32, SDL_SWSURFACE);
    			windowInitialized = true;
    		}
    	}
     
    private:
    	struct Star
    	{
    		float x, y, z;
    	};
     
    private:
    	Star generateStar()
    	{
    		Star s = {(::rand() / (static_cast<double>(RAND_MAX) + 1.0)) * 20-10,
    				  (::rand() / (static_cast<double>(RAND_MAX) + 1.0)) * 20-10,
    				  (::rand() / (static_cast<double>(RAND_MAX) + 1.0)) * 100};
    		return s;
    	}
     
    	void initStarfield()
    	{
    		for(StarField::iterator it = starfield.begin();
    			it != starfield.end();
    			++it)
    		{
    			*it = generateStar();
    		}
    	}
     
    	void updateStarfield()
    	{
    		for(StarField::iterator it = starfield.begin();
    			it != starfield.end();
    			++it)
    		{
    			--it->z;
     
    			if(it->z <= 0)
    			{
    				*it = generateStar();
    			}
    		}
    	}
     
    	void drawStarfield()
    	{
    		int w = width();
    		int hw = w >> 1;
    		int h = height();
    		int hh = h >> 1;
     
    		for(StarField::iterator it = starfield.begin();
    			it != starfield.end();
    			++it)
    		{
    			int screenX = static_cast<int>((it->x / it->z) * w + hw);
    			int screenY = static_cast<int>((it->y / it->z) * h + hh);
     
    			// ignore out of view stars
    			if(screenX < 0 || screenX > 319 || screenY < 0 || screenY > 199)
    				continue;
     
    			putpixel(screen, screenX, screenY, SDL_MapRGBA(screen->format,
    				0xfe, 0xef, 0xcc, 0xff));
    		}
    	}
     
    	// ripped off SDL doc
    	void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
    	{
    		int bpp = surface->format->BytesPerPixel;
    		/* Here p is the address to the pixel we want to set */
    		Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
     
    		switch(bpp) {
    		case 1:
    			*p = pixel;
    			break;
     
    		case 2:
    			*(Uint16 *)p = pixel;
    			break;
     
    		case 3:
    			if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
    				p[0] = (pixel >> 16) & 0xff;
    				p[1] = (pixel >> 8) & 0xff;
    				p[2] = pixel & 0xff;
    			} else {
    				p[0] = pixel & 0xff;
    				p[1] = (pixel >> 8) & 0xff;
    				p[2] = (pixel >> 16) & 0xff;
    			}
    			break;
     
    		case 4:
    			*(Uint32 *)p = pixel;
    			break;
    		}
    	}
     
    private slots:
    	void onRefresh()
    	{
    		if(windowInitialized && screen)
    		{
    			SDL_LockSurface(screen);
    				// Nettoyage de l'écran
    				SDL_FillRect(screen, NULL, 0);
    				// Dessin du starfield
    				drawStarfield();
    			SDL_UnlockSurface(screen);
     
    			// Rafraîchissement...
    			SDL_UpdateRect(screen, 0, 0, 0, 0);
     
    			// Et enfin, mise à jour des positions des étoiles
    			updateStarfield();
    		}
    	}
     
    private:
    	bool windowInitialized;
    	SDL_Surface *screen;
     
    	typedef std::vector<Star> StarField;
    	StarField starfield;
    	const int StarNumbers;
    };
     
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
     
    	SDLWidget *sdlw = new SDLWidget;
    	sdlw->show();
     
    	return app.exec();
    }
    Le problème est donc à la compilation, l'erreur est la suivante :

    main.o||In function `_ZNSt24__copy_backward_dispatchIPN9SDLWidget4StarES2_12__false_typeE4copyES2_S2_S2_'
    undefined reference to `vtable for SDLWidget'|
    undefined reference to `vtable for SDLWidget'|

    Je ne vois vraiment pas d'où ça peut venir. Est-ce que quelqu'un aurait une idée ?

    Merci d'avance

  2. #2
    yan
    yan est déconnecté
    Rédacteur
    Avatar de yan
    Homme Profil pro
    Ingénieur expert
    Inscrit en
    Mars 2004
    Messages
    10 033
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur expert
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2004
    Messages : 10 033
    Points : 13 968
    Points
    13 968
    Par défaut
    Salut.
    Comment compile tu ton application?
    vue les erreur, est tu sur d'avoir appliqué moc sur ton fichier?

  3. #3
    Membre expert

    Avatar de IrmatDen
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 727
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 727
    Points : 3 266
    Points
    3 266
    Par défaut
    Salut,

    Tu n'as pas copié le code dans son intégralité, il manque juste la dernière ligne qui justement indique à qmake de demander un moc'ing de ce fichier

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    554
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 554
    Points : 181
    Points
    181
    Par défaut
    Oui en fait, j'avais retiré le .moc mais j'ai trouvé comment le crée ensuite, maintenant tout marche très bien avec ce fichier.

    Merci pour votre aide

    A bientôt

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Intégration de la SDL dans Qt
    Par dourouc05 dans le forum Téléchargez
    Réponses: 0
    Dernier message: 12/11/2010, 21h09
  2. Intégration SDL dans QT sur MacOSX
    Par kolian dans le forum Qt
    Réponses: 4
    Dernier message: 18/03/2009, 10h49
  3. Intégration éditeur html dans page asp
    Par Crazyblinkgirl dans le forum ASP
    Réponses: 2
    Dernier message: 06/05/2004, 09h04
  4. [NETBEANS] Intégration de Jboss dans NetBeans
    Par Kleb dans le forum NetBeans
    Réponses: 1
    Dernier message: 09/06/2003, 18h45

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