mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 07:37:20 +02:00
Billboard overlays disply grey square while image is loading
This commit is contained in:
parent
a9ceec4627
commit
22bcb7d7e7
1 changed files with 47 additions and 38 deletions
|
@ -20,26 +20,25 @@ BillboardOverlay::BillboardOverlay()
|
||||||
}
|
}
|
||||||
|
|
||||||
void BillboardOverlay::render() {
|
void BillboardOverlay::render() {
|
||||||
if (_billboard.isEmpty()) {
|
if (!_billboard.isEmpty()) {
|
||||||
return;
|
if (!_billboardTexture) {
|
||||||
}
|
QImage image = QImage::fromData(_billboard);
|
||||||
if (!_billboardTexture) {
|
if (image.format() != QImage::Format_ARGB32) {
|
||||||
QImage image = QImage::fromData(_billboard);
|
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||||
if (image.format() != QImage::Format_ARGB32) {
|
}
|
||||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
_size = image.size();
|
||||||
|
if (_fromImage.x() == -1) {
|
||||||
|
_fromImage.setRect(0, 0, _size.width(), _size.height());
|
||||||
|
}
|
||||||
|
_billboardTexture.reset(new Texture());
|
||||||
|
glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID());
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _size.width(), _size.height(), 0,
|
||||||
|
GL_BGRA, GL_UNSIGNED_BYTE, image.constBits());
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID());
|
||||||
}
|
}
|
||||||
_size = image.size();
|
|
||||||
if (_fromImage.x() == -1) {
|
|
||||||
_fromImage.setRect(0, 0, _size.width(), _size.height());
|
|
||||||
}
|
|
||||||
_billboardTexture.reset(new Texture());
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID());
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _size.width(), _size.height(), 0,
|
|
||||||
GL_BGRA, GL_UNSIGNED_BYTE, image.constBits());
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_ALPHA_TEST);
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
@ -62,25 +61,35 @@ void BillboardOverlay::render() {
|
||||||
}
|
}
|
||||||
glScalef(_scale, _scale, _scale);
|
glScalef(_scale, _scale, _scale);
|
||||||
|
|
||||||
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
if (_billboardTexture) {
|
||||||
float x = _fromImage.width() / (2.0f * maxSize);
|
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
||||||
float y = -_fromImage.height() / (2.0f * maxSize);
|
float x = _fromImage.width() / (2.0f * maxSize);
|
||||||
|
float y = -_fromImage.height() / (2.0f * maxSize);
|
||||||
glColor3f(1.0f, 1.0f, 1.0f);
|
|
||||||
glBegin(GL_QUADS); {
|
glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
glBegin(GL_QUADS); {
|
||||||
(float)_fromImage.y() / (float)_size.height());
|
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
||||||
glVertex2f(-x, -y);
|
(float)_fromImage.y() / (float)_size.height());
|
||||||
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
glVertex2f(-x, -y);
|
||||||
(float)_fromImage.y() / (float)_size.height());
|
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
||||||
glVertex2f(x, -y);
|
(float)_fromImage.y() / (float)_size.height());
|
||||||
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
glVertex2f(x, -y);
|
||||||
((float)_fromImage.y() + (float)_fromImage.height()) / _size.height());
|
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
||||||
glVertex2f(x, y);
|
((float)_fromImage.y() + (float)_fromImage.height()) / _size.height());
|
||||||
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
glVertex2f(x, y);
|
||||||
((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height());
|
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
||||||
glVertex2f(-x, y);
|
((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height());
|
||||||
} glEnd();
|
glVertex2f(-x, y);
|
||||||
|
} glEnd();
|
||||||
|
} else {
|
||||||
|
glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
glBegin(GL_QUADS); {
|
||||||
|
glVertex2f(-1.0f, -1.0f);
|
||||||
|
glVertex2f(1.0f, -1.0f);
|
||||||
|
glVertex2f(1.0f, 1.0f);
|
||||||
|
glVertex2f(-1.0f, 1.0f);
|
||||||
|
} glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
} glPopMatrix();
|
} glPopMatrix();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue