I am attempting to render a texture to a simple shape using QBuilder and QGeometryData but I can not get the texture to display, what am I doing wrong?
I have created a QGLSceneNode which builds the texture and attempts to use generateTextureCoordinates to map the texture coordinates.
EDIT Mapping the texture coordinates by hand seems to work, but generateTextureCoordinates should work.
[My class is a child of QGLView]
vtkQtViewer::vtkQtViewer(QWidget *parent) :
QGLView(parent), scene(new QGLSceneNode(this))
{
// in the constructor construct a builder on the stack
QGLBuilder builder;
QGeometryData triangle;
QVector3D a(2, 2, 0);
QVector3D b(-2, 2, 0);
QVector3D c(2, -2, 0);
QVector3D d(-2, -2, 0);
triangle.appendVertex(a,b,c);
triangle.appendVertex(b,d,c);
triangle.generateTextureCoordinates();
// When adding geometry,
//QGLBuilder automatically creates lighting normals
builder << triangle;
// obtain the scene from the builder
QGLSceneNode* can = builder.finalizedSceneNode();
// apply effects at app initialization time
QGLMaterial *mat = new QGLMaterial;
mat->setDiffuseColor(Qt::red);
QUrl url;
url.setPath(QLatin1String("qtlogo.png"));
url.setScheme(QLatin1String("file"));
mat->setTextureUrl(url);
can->setMaterial(mat);
scene->addNode(can);
}
vtkQtViewer::~vtkQtViewer()
{
delete scene;
}
void vtkQtViewer::initializeGL(QGLPainter *painter)
{
painter->setStandardEffect(QGL::LitDecalTexture2D);
}
void vtkQtViewer::paintGL(QGLPainter *painter)
{
scene->draw(painter);
}}