PDA

View Full Version : QPainter problem (a HW issue perhaps?)



jonks
6th June 2009, 19:31
Hi,

I have something odd going on with QPainter/QPixmap that I don't understand.
Before I start - I'm not using OpenGL.

I have a image which is 1798x1709x24bit (it's a texture map which contains multiple textures).
I load it into a Pixmap and use QPainter::drawPixmap to draw a sub-sections of it.
This works as expected on my PC with a low end graphics card.

I've just discovered on a friend's PC that the pixmap is not rendered at all when QPainter::drawPixmap is called (exactly the same binaries were used in both cases, the image is embedded as a resource).

I also load other images from other resources (much small images) and sub-sections of these are using the same QPainter::drawPixmap calls.
These images are rendered correctly.

The end result is there is a large transparent empty space where the big image should be surrounded by smaller images.

We've verified that the QPixmap loaded with the image returns the correct dimensions, etc, so it appears that the QPainter::drawPixmap call is failing silently.

Are there any known issues with QPixmap/QPainter on different flavors of graphics HW?
(should images ideally be power-of-2 when they are used for textures?)
(He has a mid-range to higher end graphics card)

Are there any good debugging techniques that I could use to find out the root cause of this issue?

Also, assuming it is a HW issue, is there an API I can use to determine the limitations of the HW so that I can adjust things on the fly so my SW works for all HW?

Thanks
J

wysota
6th June 2009, 21:54
What are you drawing the pixmap to?

jonks
7th June 2009, 01:58
a QGraphicsScene

the scene params (if it's important):



scene.setItemIndexMethod(QGraphicsScene::NoIndex);
scene.setSceneRect(QRectF(-2500, -2500, 5000, 5000));


All of the view params:



view->setRenderHint(QPainter::Antialiasing);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setDragMode(QGraphicsView::RubberBandDrag);
view->setViewportUpdateMode(QGraphicsView::MinimalViewpo rtUpdate);


For the draw image function, src = (0,0,100,100), dest = (0,0,100,100).
The 100x100 block of pixels is rendered on my PC, but not on my friend's.

wysota
7th June 2009, 09:46
Can we see the exact sequence of calls you use to draw? Or better yet try to provide a minimal compilable example reproducing the problem.

jonks
7th June 2009, 16:34
I've just created a minimal implementation.
I'm waiting to hear for the result.
I'll post it as soon as I hear.

Thanks

jonks
9th June 2009, 08:01
Hi - back again
Here's a short prog that reproduces the problem.
In this case, the red square is missing from his, but not mine.

main.cpp



#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}



MainWindow.h



#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QGraphicsView>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QWidget>
#include <QGraphicsItem>
class QGraphicsScene;

namespace Ui
{
class MainWindow;
}


class MyGraphicsItem : public QGraphicsItem
{
QPixmap pixmap;
public:
MyGraphicsItem(const QString &source, QGraphicsScene *scene) : QGraphicsItem(0, scene)
{
pixmap.load(source);
}
QRectF boundingRect() const
{
return QRectF(0,0, 100, 100);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawPixmap(0,
0,
100,
100,
pixmap,
0,0,
100,
100);
}
};


class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;
QGraphicsScene scene;
QGraphicsView *view;
MyGraphicsItem* missing;
MyGraphicsItem* notMissing;
};
#endif // MAINWINDOW_H




MainWindow.cpp



#include <QGraphicsScene.h>
#include <QHBoxLayout>
#include <QPixmap>
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
scene.setSceneRect(QRectF(-2500, -2500, 5000, 5000));
view = new QGraphicsView(&scene);
view->setRenderHint(QPainter::Antialiasing);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setDragMode(QGraphicsView::RubberBandDrag);
view->setViewportUpdateMode(QGraphicsView::MinimalViewpo rtUpdate);

QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(view);
QWidget *widget = new QWidget;
widget->setLayout(layout);
setCentralWidget(widget);


MyGraphicsItem* missing1 = new MyGraphicsItem(":/missing1", &scene);
MyGraphicsItem* missing2 = new MyGraphicsItem(":/missing2", &scene);
MyGraphicsItem* notMissing = new MyGraphicsItem(":/notmissing", &scene);
MyGraphicsItem* notMissing2 = new MyGraphicsItem(":/notmissing", &scene);
missing1->setPos(0, 0);
missing2->setPos(0, 100);
notMissing->setPos(-100, 0);
notMissing2->setPos(100, 100);
}

MainWindow::~MainWindow()
{
delete ui;
}


resources.qrc


<RCC>
<qresource prefix="/" >
<file alias="notmissing" >notmissing.png</file>
<file alias="missing1" >missing.jpg</file>
<file alias="missing2" >missing2.png</file>
</qresource>
</RCC>


Minimal.pro


# -------------------------------------------------
# Project created by QtCreator 2009-06-07T06:49:19
# -------------------------------------------------
TARGET = Minimal
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
RESOURCES += resources.qrc


"notmissing.png"
http://img23.imageshack.us/img23/582/notmissing.png

"missing.jpg"
Only a link here because the image dimensions are so large (1798x1709x24 48Kb)
This is the missing "red square" texture source.
http://img13.imageshack.us/img13/5735/missingz.jpg

"missing2.png" (1798x1709x24 WARNING 2.2MB)
Only a link here because the image dimensions and file size are large (1798x1709x24 2.2MB)
http://img44.imageshack.us/img44/8383/missing2.png

My result:
http://img19.imageshack.us/img19/2117/workingb.png

His result:
http://img200.imageshack.us/img200/5908/bustedi.jpg

wysota
9th June 2009, 08:18
Are both systems Windows? What happens if you run the application with "-graphicssystem raster" and "-graphicssystem opengl"? Does it change anything?

jonks
9th June 2009, 09:05
Hi thanks for staying interested.

Both are running windows Vista. Mine is 32bit, I'm not sure if his is 64bit (I suspect it is).
For me "-graphicssystem raster" and "-graphicssystem opengl" produce the correct results.
For him....I'll have the results later

BRB

jonks
9th June 2009, 21:41
Are both systems Windows? What happens if you run the application with "-graphicssystem raster" and "-graphicssystem opengl"? Does it change anything?
He has 64bit Vista with a GTS8800 with latest drivers.

-graphicssystem raster" and "-graphicssystem opengl" had no effect.

We just discovered that by changing the red jpg to a 32bit png it works on his PC as well. :eek:

wysota
9th June 2009, 22:27
In that case maybe he simply doesn't have a JPEG image plugin installed?
http://www.qtcentre.org/forum/faq.php?faq=qt_images#faq_qt_missing_images

jonks
10th June 2009, 04:05
Thank you!

I assumed the FAQ link in the menu above for for forum FAQs, not for QT specifics! :D
I really should browse around this forum more. :o