Results 1 to 5 of 5

Thread: rotate a pixmap before binding 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 rotate a pixmap before binding to texture

    before I bind the pixmap to texture, I scale it to 800 and 600 pixels. Now, I also want to rotate the image by 90 degrees. I do not know how to do that. another way is to bind the texture simply and for the rotation part I rotate it inside the paintGL. As I remember this is done via transformation matrix, but I don't know how to modify it so that the pixmap is 90 rotated.

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

  2. #2
    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: rotate a pixmap before binding to texture

    You can rotate the pixmap with QPixmap::transformed() but this is a costly operation. If you want to use the pixmap as a texture, it is much faster to adjust texture coordinates in your GL code. Same goes for scaling, by the way.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  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: rotate a pixmap before binding to texture

    it is much faster to adjust texture coordinates in your GL code.
    I didn't catch what you meant here.
    by the way, I used this method as you mentioned:
    Qt Code:
    1.  
    2. rm.rotate(90);
    3.  
    4. pixmap = pixmap.transformed(rm);
    5.  
    6. pixmap.scaled(801, 701);
    7.  
    8. texture = bindTexture(pixmap);
    To copy to clipboard, switch view to plain text mode 

    The problem here is I set the dimensions of my glwidget to 800 by 700, also in the resize method. However, when it shows the texture in the widget, the texture is of smaller size and just is rendered in the middle of the widget! I though scaling the pixmap would solve the problem, but it had no effect.
    Do you have any idea why this happens? Cheers

  4. #4
    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: rotate a pixmap before binding to texture

    Quote Originally Posted by saman_artorious View Post
    I didn't catch what you meant here.
    I mean to apply the texture rotated on the object. This is trivial to calculate in shader code.

    The problem here is I set the dimensions of my glwidget to 800 by 700, also in the resize method. However, when it shows the texture in the widget, the texture is of smaller size and just is rendered in the middle of the widget! I though scaling the pixmap would solve the problem, but it had no effect.
    Do you have any idea why this happens? Cheers
    GL widgets show objects consisting of vertices. The size of the texture doesn't matter, the size (aka coordinates) of the object does.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    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: rotate a pixmap before binding to texture

    wow, that was so tricky! i exactly needed the same thing to reduce machine CPU consumption.
    Cheers,

Similar Threads

  1. set QPixmap to texture
    By saman_artorious in forum Qt Programming
    Replies: 3
    Last Post: 28th October 2013, 10:58
  2. Replies: 1
    Last Post: 19th April 2011, 11:17
  3. Rotate Graphicsview and Pixmap in synchro
    By Qt Coder in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2009, 12:37
  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.