crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )

 
Ответить в данную темуНачать новую тему
> Как сделать связку QT3 с SDL?, Программа должна быть написана QT->SDL
dell
  опции профиля:
сообщение 24.2.2008, 3:11
Сообщение #1


Новичок


Группа: Новичок
Сообщений: 1
Регистрация: 24.2.2008
Пользователь №: 103

Спасибо сказали: 0 раз(а)




Репутация:   0  


Программа должна быть написана на QT и местами должна использовать<SDL.h>

Как подключить библиотеки SDL к про файлу QT с последующей компиляцией в Linux (использую FC, ASPLinux)?
Как на виджете выводить графику (поверхности SDL)?

ЗЫ
Братцы помогите, кто чем может гуглю нечего не могу найти :(
Нужен пример ткните носом плиз.
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение
Litkevich Yuriy
  опции профиля:
сообщение 24.2.2008, 11:38
Сообщение #2


разработчик РЭА
*******

Группа: Сомодератор
Сообщений: 9669
Регистрация: 9.1.2008
Из: Тюмень
Пользователь №: 64

Спасибо сказали: 807 раз(а)




Репутация:   94  


извини, возможно это покажется не умный совет, но посмтори статью про qmake и ее подраздел про файлы проекта, там упоминается подключение сторонних библиотек
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение
ViGOur
  опции профиля:
сообщение 24.2.2008, 23:04
Сообщение #3


Мастер
******

Группа: Модератор
Сообщений: 3296
Регистрация: 9.10.2007
Из: Москва
Пользователь №: 4

Спасибо сказали: 231 раз(а)




Репутация:   40  


Пример связки Qt 4.0.1 и SDL 1.2.8-08:
main.pro
TEMPLATE = app
LANGUAGE = C++
TARGET = qtSDL
PROJECTNAME = SPARTA Video Tracking Demo
CONFIG += qt thread warn_on debug

INCLUDEPATH += /usr/include/SDL

LIBS += -lSDL

SOURCES    = SDLWidget.cpp main.cpp

HEADERS = SDLWidget.h

main.cpp
/*
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
*/

#include <qapplication.h>
#include <QMainWindow>
#include <QDesktopWidget>

#include "SDLWidget.h"

int main(int argc, char **argv)
{
    QApplication
        app(argc,argv);
    QMainWindow
        mw;
    QSDLScreenWidget
        *sdlWidget = new QSDLScreenWidget(&mw);
    mw.setCentralWidget(sdlWidget);

    // Query the desktop to determine the size of the desktop and
    // to center the application when it opens.
    //
    int
        width = QApplication::desktop()->width(),
        height = QApplication::desktop()->height();

    mw.setGeometry((width - 800)/2, (height - 600)/2, 800, 600);
    mw.show();

    return app.exec();
}

SDLWidget.h
/*
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
*/

#ifndef SDLWIDGET_H
#define SDLWIDGET_H

#include <Qt>
#include <QWidget>

struct SDL_Surface;

class QSDLScreenWidget : public QWidget
{
    Q_OBJECT
public:
    QSDLScreenWidget(QWidget *parent=0, Qt::WFlags flags=0);

protected:
    void resizeEvent(QResizeEvent *);
    void paintEvent(QPaintEvent *);

private:
    SDL_Surface
        *screen;
};
#endif

SDLWidget.cpp
/*
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
*/

#include <iostream>

#include <QX11Info>

#include <SDL.h>
#include "SDLWidget.h"

#ifdef Q_WS_X11
#include <X11/Xlib.h>
#endif

QSDLScreenWidget::QSDLScreenWidget(QWidget *parent, Qt::WFlags flags) :
    QWidget(parent, flags),
    screen(0)
{
    // Turn off double buffering for this widget. Double buffering
    // interferes with the ability for SDL to be properly displayed
    // on the QWidget.
    //
    setAttribute(Qt::WA_PaintOnScreen);
}

void QSDLScreenWidget::resizeEvent(QResizeEvent *)
{
    // We could get a resize event at any time, so clean previous mode.
    // You do this because if you don't you wind up with two windows
    // on the desktop: the Qt application and the SDL window. This keeps
    // the SDL region synchronized inside the Qt widget and the subsequent
    // application.
    //
    screen = 0;
    SDL_QuitSubSystem(SDL_INIT_VIDEO);

    // Set the new video mode with the new window size
    //
    char
        variable[64];
    sprintf(variable, "SDL_WINDOWID=0x%lx", winId());
    putenv(variable);

    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
    {
        std::cerr << "Unable to init SDL: " << SDL_GetError() << std::endl;
        return;
    }

    screen = SDL_SetVideoMode(width(), height(), 0, 0);

    if (!screen)
    {
        std::cerr << "Unable to set video mode: " << SDL_GetError() <<
            std::endl;
        return;
    }
}

void QSDLScreenWidget::paintEvent(QPaintEvent *)
{
#ifdef Q_WS_X11
    // Make sure we're not conflicting with drawing from the Qt library
    //
    XSync(QX11Info::display(), FALSE);
#endif

    if (screen)
    {
        SDL_FillRect(screen, NULL, 0);
        SDL_Surface
            *image = SDL_LoadBMP("sample.bmp");

        if (image)
        {
            SDL_Rect
                dst;
            dst.x = (screen->w - image->w)/2;
            dst.y = (screen->h - image->h)/2;
            dst.w = image->w;
            dst.h = image->h;
            SDL_BlitSurface(image, NULL, screen, &dst);
        }

        SDL_Flip(screen);
    }
}
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

Быстрый ответОтветить в данную темуНачать новую тему
Теги
Нет тегов для показа


1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0




RSS Текстовая версия Сейчас: 19.4.2024, 22:16