CylinderView::CylinderView(QWindow *parent) : QGLView(parent) { QGLBuilder builder; // Evil hack: it is not possible to just call glClearColor on any device // but it is possible to have a huge, dark SkyBox. Without this hack the // cylinder floats over a transparent background, displaying the contents // of the last app builder << QGL::Smooth << QGLCube(1000.0f); // Add the cylinder builder << QGL::Smooth << QGLCylinder(2.0, 1.5, 2.0, 36, 3, true, true); QGLMaterial *matLid = new QGLMaterial; matLid->setAmbientColor(Qt::gray); matLid->setDiffuseColor(Qt::gray); QUrl urlLid; urlLid.setPath(QLatin1String(":/latte.png")); urlLid.setScheme(QLatin1String("file")); matLid->setTextureUrl(urlLid); QGLMaterial *matSides = new QGLMaterial; matSides->setColor(QColor(170, 202, 0)); QUrl urlSides; urlSides.setPath(QLatin1String(":/cupTexture.png")); urlSides.setScheme(QLatin1String("file")); matSides->setTextureUrl(urlSides); QGLSceneNode *root = builder.sceneNode(); QGLSceneNode *lid = root->findChild<QGLSceneNode *>("Cylinder Top"); int lidMat = root->palette()->addMaterial(matLid); lid->setMaterialIndex(lidMat); lid->setEffect(QGL::LitDecalTexture2D); QGLSceneNode *sides = root->findChild<QGLSceneNode *>("Cylinder Sides"); int sideMat = root->palette()->addMaterial(matSides); sides->setMaterialIndex(sideMat); sides->setEffect(QGL::LitDecalTexture2D); cylinder = builder.finalizedSceneNode(); QGLMaterial *mat = new QGLMaterial; mat->setAmbientColor(Qt::gray); mat->setDiffuseColor(Qt::gray); cylinder->setMaterial(mat); cylinder->setEffect(QGL::LitMaterial); }
void tst_QGLRender::sequence() { QSKIP("QWidget: Cannot create a QWidget when no GUI is being used"); QSharedPointer<QGLMaterialCollection> palette(new QGLMaterialCollection()); // create a yellow lit material QGLMaterial *mat = new QGLMaterial; mat->setAmbientColor(Qt::yellow); int ix0 = palette->addMaterial(mat); // create a blue lit material mat = new QGLMaterial; mat->setAmbientColor(Qt::blue); int ix1 = palette->addMaterial(mat); // create a grey textured material int tx0; { QImage uv(1024, 1024, QImage::Format_ARGB32); uv.fill(qRgba(196, 196, 196, 196)); mat = new QGLMaterial; mat->setAmbientColor(Qt::gray); QGLTexture2D *tex = new QGLTexture2D; tex->setImage(uv); mat->setTexture(tex); tx0 = palette->addMaterial(mat); } QGLSceneNode *scene = new QGLSceneNode; scene->setPalette(palette); QGLSceneNode *node = 0; QGLSceneNode *prim; { QGLBuilder builder(palette); QVector3D a(-1.0f, -1.0f, 0.0f); QVector3D b(1.0f, -1.0f, 0.0f); QVector3D c(1.0f, 1.0f, 0.0f); QGeometryData p; p.appendVertex(a, b, c); p.generateTextureCoordinates(); builder.addTriangles(p); prim = builder.currentNode(); prim->setMaterialIndex(ix0); builder.newSection(); QVector3D d(-1.2f, -1.2f, 0.0f); QVector3D e(1.2f, -1.2f, 0.0f); QVector3D f(1.2f, 1.2f, 0.0f); QVector3D g(-1.2f, 1.2f, 0.0f); QGeometryData q; q.appendVertex(d, e, f, g); q.generateTextureCoordinates(); builder.addQuads(q); prim = builder.currentNode(); prim->setMaterialIndex(ix1); node = builder.finalizedSceneNode(); } scene->addNode(node); QGLSceneNode *cl = prim->clone(scene); cl->setMaterialIndex(tx0); cl->setEffect(QGL::LitDecalTexture2D); TestView widget(scene); if (!widget.context()->isValid()) QSKIP("GL Implementation not valid"); TestPainter *ptr = new TestPainter(&widget); widget.paintGL(ptr); QList<int> starts = ptr->starts(); QList<int> counts = ptr->counts(); QCOMPARE(starts.at(0), 0); QCOMPARE(counts.at(0), 3); QCOMPARE(starts.at(1), 3); QCOMPARE(counts.at(1), 6); }