mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +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() {
|
||||
if (_billboard.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!_billboardTexture) {
|
||||
QImage image = QImage::fromData(_billboard);
|
||||
if (image.format() != QImage::Format_ARGB32) {
|
||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||
if (!_billboard.isEmpty()) {
|
||||
if (!_billboardTexture) {
|
||||
QImage image = QImage::fromData(_billboard);
|
||||
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);
|
||||
|
@ -62,25 +61,35 @@ void BillboardOverlay::render() {
|
|||
}
|
||||
glScalef(_scale, _scale, _scale);
|
||||
|
||||
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
||||
float x = _fromImage.width() / (2.0f * maxSize);
|
||||
float y = -_fromImage.height() / (2.0f * maxSize);
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
glBegin(GL_QUADS); {
|
||||
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
||||
(float)_fromImage.y() / (float)_size.height());
|
||||
glVertex2f(-x, -y);
|
||||
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
||||
(float)_fromImage.y() / (float)_size.height());
|
||||
glVertex2f(x, -y);
|
||||
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
||||
((float)_fromImage.y() + (float)_fromImage.height()) / _size.height());
|
||||
glVertex2f(x, y);
|
||||
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
||||
((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height());
|
||||
glVertex2f(-x, y);
|
||||
} glEnd();
|
||||
if (_billboardTexture) {
|
||||
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
||||
float x = _fromImage.width() / (2.0f * maxSize);
|
||||
float y = -_fromImage.height() / (2.0f * maxSize);
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
glBegin(GL_QUADS); {
|
||||
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
||||
(float)_fromImage.y() / (float)_size.height());
|
||||
glVertex2f(-x, -y);
|
||||
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
||||
(float)_fromImage.y() / (float)_size.height());
|
||||
glVertex2f(x, -y);
|
||||
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
||||
((float)_fromImage.y() + (float)_fromImage.height()) / _size.height());
|
||||
glVertex2f(x, y);
|
||||
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
||||
((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height());
|
||||
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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue