使用QGLSceneNode将纹理渲染为简单形状

时间:2012-11-03 12:31:15

标签: opengl colors textures qt3d

我正在尝试使用QBuilder和QGeometryData将纹理渲染为简单的形状但是我无法显示纹理,我做错了什么?

我创建了一个QGLSceneNode来构建纹理并尝试使用generateTextureCoordinates来映射纹理坐标。

修改 手动映射纹理坐标似乎有效,但generateTextureCoordinates应该可以工作。

[我的班级是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);
}}

0 个答案:

没有答案