Results 1 to 20 of 25

Thread: porting my virtua girl player to qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default porting my virtua girl player to qt

    Hello,

    After my 2 initial projects with Qt have been succesfull it's time to wet my feet a little with graphics programming.

    In windows I succeeded in making my own virtuagirl player, it plays animations of stripping girls in the corner above the tray.

    I like to port this to linux, I miss it
    The data for the animations is in some kind of run length encoding. But in stead of a normal bitmap, each frame is build using the windows mechanismes CreateRectRgn(), CombineRgn() in order to have a transparant image on the desktop.

    I like to have some advice on how to go about this.

    Thank you. Jean.

  2. #2
    Join Date
    Jan 2006
    Posts
    371
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    14
    Thanked 18 Times in 17 Posts

    Default Re: porting my virtua girl player to qt

    Dud, when you finish it, please give me a download link

  3. #3
    Join Date
    Aug 2006
    Posts
    250
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    19
    Thanked 49 Times in 36 Posts

    Default Re: porting my virtua girl player to qt

    Hmm.. This might be quite difficult, if the file format is composed of basically commands to the Windows graphics system. I suppose it depends on the complexity of the commands. If there are only a few commands that are used, I would reimplement them using QPainter equivalents, but if they run the full gamut of GDI commands then I would look into using Wine to port your existing application to Linux, or even run it outright.

  4. #4
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: porting my virtua girl player to qt

    The Create/Add Rgn stuff in windows is basically a way to have a *window* which is not a pure rectangle, but an irregular shape, like a girl for instance. Because of it being a window in itself, it is automatically transparent from the underlying background, the desktop. If the girl moves her arm, the background under the previous armshape is restored because the window shape changes. That painting is done automatically by the os. This is about what I'm looking for. Can qpainter do (something like) this?

  5. #5
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: porting my virtua girl player to qt

    Not QPainter, but QWidget.
    QWidget::setMask ( const QBitmap & bitmap )

  6. #6
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: porting my virtua girl player to qt

    setMask() looks promising. I'm gonna invest, thanks.
    I'll let you guys know when there's a download link, may take a while though.

  7. #7
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: porting my virtua girl player to qt

    Well, the graphics system is something which is not learned in a day, overwhelming.

    My questions:

    In the shaped clock example the actual drawing is done in the paint event by using QPainter. But I would like to use a QImage and setPixel() because in that way I hope I can set a mask from the pixelmap I have build on that QImage

    How do I do that?

    Note, I don't use the paintevent like in that example, I use a frame() function triggered by a timer. The window has FramelessWindowHint attribute so a paintevent is not needed.

    Also, I don't think scanLine() will be faster because the pixel data comes in vertical rows, am I correct?

    Thanks.

  8. #8
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: porting my virtua girl player to qt

    I'm not completely sure I understood most of your post, so I'll just tell you how I would go about this problem. It really shouldn't be to complicated.

    First prepare the data:
    For each frame you should have a QPixmap of the girl and a QBitmap of the mask. I don't now in which format you have the images, but once you've loaded the data into a QImage or QPixmap QPixmap::createMaskFromColor() should help you create the mask.

    Make your QWidget subclass a frameless window and connect a timer to a slot(which you seem to have done)

    You do need paintEvent(), painting outside paintEvent is not allowed! All you need to do in frame() is to select which new QPixmap/QBitmap pair to use and call setMask().

    paintEvent will be called automatically when needed and all you have to do is paint the QPixmap at (0,0)

    Don't complicate things more than necessary! You won't need scanLine() unless you are reading binary data into a QImage.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: porting my virtua girl player to qt


  10. #10
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: porting my virtua girl player to qt

    Thank you both.

    I'm trying to go the way spud describes.

    in constructor (I need to construct it on the stack, else cannot set width / height):
    Qt Code:
    1. image = new QPixmap(400, 400);
    To copy to clipboard, switch view to plain text mode 

    in frame()
    Qt Code:
    1. void Girl::frame()
    2. {
    3. image->fill(Qt::red);
    4. setMask(image->createMaskFromColor(Qt::black, Qt::MaskOutColor));
    5. }
    To copy to clipboard, switch view to plain text mode 
    in paintEvent()
    Qt Code:
    1. void Girl::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. painter.drawPixmap(QPoint(0, 0), *image);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Program crashes with segmentation fault. Not a smooth ride yet.
    p.s. the pixeldata comes from a run length encoded file and is presented in vertical lines of 1 pixel width each which than can be put on the pixmap with drawLine().
    Last edited by JeanC; 1st February 2008 at 13:08.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: porting my virtua girl player to qt

    You meant something like this?
    Attached Images Attached Images

  12. #12
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 1 Post

    Default Re: porting my virtua girl player to qt

    Grin, what have you got there?
    Can it zoom?
    My eyes are bad, that's a reason I wanted to write a player myself in the first place so I could add 2 , 3 and 4 times zoom.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: porting my virtua girl player to qt

    Zooming is not a problem, but the resolution of the animations I have is hmm... bad It's 160x120, so zooming will make it look terrible. If you have larger anims, they shouldn't pose a problem.

    By the way - I implemented both approaches - using setMask and using ARGB display and the latter works much much better.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.