Bonsoir, je travail actuellement sur un projet de développement de jeu vidéo 2D sur Qt (avec Qt Creator), et je souhaite ajouter la SDL 2.0 en tant qu'héritier d'un QWidget à mon projet. J'ai cherché, mais je ne trouve que des tutoriel d'implémentation de la SDL 1.2, et non 2.0.

Donc d'abord, est-ce qu'il existe un moyen d'ajouter la SDL2 en tant que QWidget (Comme la 1.2), ou cette possibilité a disparue ? J'ai essayé d'implanter la SDL2 comme dit dans les tutoriels pour 1.2, mais cela donne une erreur :

.pro

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
QT += widgets
QT += multimedia
QT += multimediawidgets
QT += webkitwidgets
QT += core
 
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QtSDL
TEMPLATE = app
 
win32:{
# Resolve conflicts between Qt and SDL
CONFIG-= windows
QMAKE_LFLAGS += $$QMAKE_LFLAGS_WINDOWS
# SDL
INCLUDEPATH += C:/SDL2-2.0.3/include
LIBS += -LC:/SDL2-2.0.3/lib/x86 -lSDL2main
LIBS += -LC:/SDL2-2.0.3/lib/x86 -lSDL2
}
 
linux:{
# SDL
INCLUDEPATH+= /SDL2-2.0.3/include
LIBS +=-L/SDL2-2.0.3/lib/x86 -lSDL2main
LIBS +=-L/SDL2-2.0.3/lib/x86 -lSDL2
}
 
 
SOURCES += \
    main.cpp \
    mainwindow.cpp \
    app.cpp \
    mainmenu.cpp \
    optionspanel.cpp \
    gamemenu.cpp \
    friendgamepanel.cpp \
    traininggamemenu.cpp \
    patterncreationpanel.cpp
 
FORMS += \
    mainwindow.ui \
    mainmenu.ui \
    optionspanel.ui \
    gamemenu.ui \
    friendgamepanel.ui \
    traininggamemenu.ui \
    patterncreationpanel.ui
 
HEADERS += \
    mainwindow.h \
    app.h \
    mainmenu.h \
    optionspanel.h \
    gamemenu.h \
    friendgamepanel.h \
    traininggamemenu.h \
    patterncreationpanel.h
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
#include <QApplication>
#include <QPushButton>
#include <mainwindow.h>
#include <optionspanel.h>
#include <app.h>
 
#include <SDL.h>
#undef main
 
int main(int argc, char* argv[]) {
    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("ERREUR : Cast impossible");
    #endif
    SDL_putenv(windowid);
 
    QApplication app(argc, argv);
 
    MainWindow win;
 
    win.show();
 
    return app.exec();
}
'SDL_putenv' was not declared in this scope

Merci d'avance


EDIT :


Finalement, j'abandonne la fusion de la SDL2 et Qt. J'ai trouvé un code qui a l'air de fonctionner, mais qui n'affiche qu'un carré blanc (même en ajoutant des blits d'image)

http://quabr.com/25232756/sdl2-rendering-into-qwidget

Je vais donc me référencer aux QPainter, ça sera sans doute plus simple.