Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: porting my virtua girl player to qt

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

    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
    369
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    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
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    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
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    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
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    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
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    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
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    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
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: porting my virtua girl player to qt


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

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.

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

    Default Re: porting my virtua girl player to qt

    Well I have a bunch of files with a resolution of about 240 x 200 and zooming 3 times is acceptible for me, this in my windows player.

    So you wrote it yourself?

    Can you help me with mine, or do you want to share?

    P.s. that project you gave me a link to is a bit over my head at the moment.
    Last edited by JeanC; 1st February 2008 at 18:33.

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

    Default Re: porting my virtua girl player to qt

    Quote Originally Posted by JeanC View Post
    So you wrote it yourself?
    Yep. Took about 5 minutes.

    Can you help me with mine, or do you want to share?
    There is not much to share, I'm just displaying a bunch of images at 16fps I downloaded an app to convert BK3 files into a series of still images, so the "player" only has code to display those images in a proper way. Total amount of code including some commented lines and opening the ARGB visual (that takes about 50 lines of code) is 150 lines of code.

    I could share some stuff too if there's a demand.
    If you could PM me a link to some higher resolution stuff, I'd check how it goes with my "player".

    P.s. that project you gave me a link to did not do very much here, only showed that bitmap.
    The point is it allows you to have transparent windows without using setMask() that slows down the whole app. Using ARGB display two instances of the player running together use about 4% of my Athlon CPU power. The version using setMask() uses more power and introduces some flicker from time to time.

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

    Default Re: porting my virtua girl player to qt

    Well, I could share my code for decoding the stream so conversion to images is not needed. The stream starts with a header containing info like size, number of frames and such.
    Then comes a table with frame info.

    But I cannot yet show Qt code for the second part.
    Maybe we could share the project?

    Maybe if I make a minimal app to play the frames on a QImage without any transparancy, just a clear inbetween and you could build the transparancy from there. Just hinking aloud. I don't know if you have time or are willing to do this at all.
    Last edited by JeanC; 1st February 2008 at 19:09.

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

    Default Re: porting my virtua girl player to qt

    Quote Originally Posted by JeanC View Post
    Well, I could share my code for decoding the stream so conversion to images is not needed. The stream starts with a header containing info like size, number of frames and such.
    Then comes a table with frame info.
    Probably so, I didn't want to waste time for that. I wrote the program only to check how it would work

    But I cannot yet show Qt code for the second part.
    Maybe we could share the project?
    No problem, I can give you my code.
    Attached Files Attached Files

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

    Default Re: porting my virtua girl player to qt

    Ok, if I'm playing around, maybe I could implement an image format for BK3 if you sent me your decoding code

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

    Default Re: porting my virtua girl player to qt

    Nice!
    Will do so, give me a day or 2 and I''ll get back.

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

    Default Re: porting my virtua girl player to qt

    Sigh, I don't get it, only a black square shows up. Could somebody please help me on my way. Gee this ought to be simple. What's wrong with me.

    Qt Code:
    1. image = new QImage(400, 400, QImage::Format_RGB32);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Girl::frame()
    2. {
    3. image->fill(Qt::white);
    4. QPainter painter(image);
    5. painter.drawLine(QPoint(0, 0), QPoint(400, 4400));
    6. update();
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void Girl::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. painter.drawImage(QPoint(0, 0), *image);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by JeanC; 2nd February 2008 at 09:17.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.