SDL如何嵌入到QT中?!

如下 人家的代码,可是我编译之后却不行

/****************************************************************************
** $Id:  qt/SDLWidget.cpp   3.0.5   edited Oct 12 2001 $
**
** 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 <stdlib.h>
#include <stdio.h>
#include "SDL.h"
#include "SDLWidget.h"
#if defined(Q_WS_X11)
#include <X11/Xlib.h>
#endif

QSDLScreenWidget::QSDLScreenWidget( QWidget *parent, const char *name ) :
    QWidget(parent, name), screen(NULL)
{
    atexit(SDL_Quit);
}

void QSDLScreenWidget::resizeEvent( QResizeEvent * )
{
    char variable[64];

    // We could get a resize event at any time, so clean previous mode
    screen = NULL;
    SDL_QuitSubSystem(SDL_INIT_VIDEO);

    // Set the new video mode with the new window size
    sprintf(variable, "SDL_WINDOWID=0x%lx", winId());
    putenv(variable);
    if ( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        return;
    }
    screen = SDL_SetVideoMode(width(), height(), 0, 0);
    if ( ! screen ) {
        fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
        return;
    }
}

void QSDLScreenWidget::paintEvent( QPaintEvent * )
{
#if defined(Q_WS_X11)
    // Make sure we're not conflicting with drawing from the Qt library
    XSync(QPaintDevice::x11Display(), 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);
    }
}


/****************************************************************************
** $Id:  qt/SDLWidget.h   3.0.5   edited Oct 12 2001 $
**
** 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 <qwidget.h>

struct SDL_Surface;

class QSDLScreenWidget : public QWidget
{
    Q_OBJECT
public:
    QSDLScreenWidget( QWidget *parent=0, const char *name=0 );

protected:
    void resizeEvent( QResizeEvent * );
    void paintEvent( QPaintEvent * );
private:
    SDL_Surface *screen;
};

#endif


/****************************************************************************
** $Id:  qt/main.cpp   3.0.5   edited Oct 12 2001 $
**
** 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 "SDLWidget.h"

/*
  The program starts here.
*/

int main( int argc, char **argv )
{
    QApplication a(argc,argv);
    QSDLScreenWidget w;
    a.setMainWidget( &w );
    w.show();
    return a.exec();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值