PDA

View Full Version : rotate a pixmap before binding to texture



saman_artorious
3rd November 2013, 13:03
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.



void GlWidget::pixmapCatchFromForm(QPixmap pixmap)
{

deleteTexture(texture);

// image->loadFromData(bytes, "PNG");

pixmap.scaled(QSize(800,600));

texture = bindTexture(pixmap);

qDebug() << "texture:" << texture; // returns 1

updateGL();
}

wysota
4th November 2013, 12:11
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.

saman_artorious
9th November 2013, 12:13
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:


QMatrix rm;

rm.rotate(90);

pixmap = pixmap.transformed(rm);

pixmap.scaled(801, 701);

texture = bindTexture(pixmap);


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

wysota
10th November 2013, 09:44
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.

saman_artorious
10th November 2013, 11:33
wow, that was so tricky! i exactly needed the same thing to reduce machine CPU consumption.
Cheers,