示例#1
0
void ImageViewer::setFile(const QString &fileName)
{
    QGLTexture2D *tex = body->material()->texture();
    if (tex) {
        tex->release();
        tex->deleteLater();
    }
    tex = new QGLTexture2D;
    tex->setImage(QImage(fileName.isEmpty() ? defaultImage : fileName));
    body->material()->setTexture(tex);
}
示例#2
0
void QGeoTileCache::GLContextAvailable()
{
    QMutexLocker ml(&cleanupMutex_);

    /* Throttle the cleanup to 10 items/frame to avoid blocking the render
     * for too long. Normally only 6-20 tiles are on screen at a time so
     * eviction rates shouldn't be much higher than this. */
    int todo = qMin(cleanupList_.size(), 10);
    for (int i = 0; i < todo; ++i) {
        QGLTexture2D *texture = cleanupList_.front();
        if (texture) {
            texture->release();
            texture->cleanupResources();
            delete texture;
        }
        cleanupList_.pop_front();
    }
}
示例#3
0
void Mg3dScene::drawText(QGLPainter * painter, const QStringList& str)
{
	QString longest;
	const int minWidth = 100;
	for (int i = 0; i < str.size(); ++i)
	{
		if(str[i].length()>longest.length())
			longest = str[i];
	}

	QFont f = font();
	f.setPointSize(11);

	QFontMetrics metrics(f);

	QRect rect = metrics.boundingRect(longest);

	if(rect.width()<minWidth)
		rect.setWidth(minWidth);

	QImage image(
			QSize(rect.width()+10,rect.height()*str.size()+10),
			QImage::Format_ARGB32
			);
	image.fill(0);
	QPainter p2(&image);
	p2.setFont(f);
	p2.setPen(Qt::yellow);
	p2.setRenderHint(QPainter::TextAntialiasing);
	for(int y= 0;y<str.size();++y)
		p2.drawText(
				0 ,
				((y+1) * rect.height()),
				" "+str[y]
		);


	p2.end();

	QGLTexture2D texture;
	texture.setImage(image);
	texture.bind();
	glDisable(GL_DEPTH_TEST);


	d_ptr->textureDisplayShader.setActive(painter,true);

	QVector2D size((float)image.width()/width(),
			(float)image.height()/height());
	QVector2D center(
			remapVal(size.x()/2,0,1,-1,1),
			remapVal(1-size.y()/2,0,1,-1,1));

	d_ptr->textureDisplayShader.setCenter(center);
	d_ptr->textureDisplayShader.setSize(size);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,texture.textureId());
	drawFboVertices(painter);
	d_ptr->textureDisplayShader.setActive(painter,false);
	texture.release();

	glEnable(GL_DEPTH_TEST);
}