Results 1 to 4 of 4

Thread: set QPixmap to texture

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default set QPixmap to texture

    I receive a byte array which contains PNG file from network. I need to set this to a pixmap and set it as a texture to my QGlWidget. As I run the program below, pixmap is in debug mode and does not contain anything. However, bytes contains the whole byte array received from network.

    Qt Code:
    1. void MainWindow::dataFromServer(QByteArray bytes)
    2. {
    3. // QByteArray bytes;
    4. QBuffer buffer(&bytes);
    5.  
    6. QPixmap pixmap;
    7. // pixmap = QPixmap::grabWidget(this);
    8.  
    9. buffer.open(QIODevice::WriteOnly);
    10.  
    11. pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
    12.  
    13. emit sendPixmapToWidget(pixmap);
    14. }
    To copy to clipboard, switch view to plain text mode 

    and here I set the pixmap to texture:

    Qt Code:
    1. void GlWidget::pixmapCatchFromForm(QPixmap pixmap) {
    2.  
    3. deleteTexture(texture);
    4. // image->loadFromData(bytes, "PNG");
    5.  
    6. texture = bindTexture(pixmap);
    7.  
    8. qDebug() << texture; // returns 1
    9.  
    10. updateGL();
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: set QPixmap to texture

    Qt Code:
    1. void MainWindow::dataFromServer(QByteArray bytes)
    2. {
    3. // QByteArray bytes;
    4. QBuffer buffer(&bytes);
    5.  
    6. QPixmap pixmap;
    7. // pixmap = QPixmap::grabWidget(this);
    8.  
    9. buffer.open(QIODevice::WriteOnly);
    10.  
    11. pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
    12.  
    13. emit sendPixmapToWidget(pixmap);
    14. }
    To copy to clipboard, switch view to plain text mode 
    "I just got a new image data, I will create a buffer from it. Now, I will take empty image and write it over that buffer. Finally, I will send that empty image."
    Do you know where is the problem ?

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: set QPixmap to texture

    how to do the vice versa? I mean how to write the buffer to empty image? I don't think I need to use a buffer instead simple doing:
    Qt Code:
    1. QPixmap pixmap(bytes.data());
    2.  
    3. qDebug() << pixmap.size();
    To copy to clipboard, switch view to plain text mode 
    may suffice. but again, the value of pixmap here is inaccessible and size prints (0, 0)!

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: set QPixmap to texture


Similar Threads

  1. Replies: 4
    Last Post: 28th August 2008, 13:13
  2. Replies: 1
    Last Post: 21st August 2008, 07:44
  3. Replies: 5
    Last Post: 9th April 2007, 14:26
  4. Texture in QGLWidget
    By showhand in forum Qt Programming
    Replies: 5
    Last Post: 28th October 2006, 08:47
  5. renderPixmap and texture
    By techno in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2006, 12:13

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.