mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 03:53:10 +02:00
Fixed bug which would cause program to crash if there was no image associated with an overlay in windows build (see checkbox in sunLightExample)
This commit is contained in:
parent
25708678f6
commit
85f6fdb8cf
1 changed files with 35 additions and 32 deletions
|
@ -75,46 +75,49 @@ void ImageOverlay::render(RenderArgs* args) {
|
||||||
glm::vec2 topLeft(left, top);
|
glm::vec2 topLeft(left, top);
|
||||||
glm::vec2 bottomRight(right, bottom);
|
glm::vec2 bottomRight(right, bottom);
|
||||||
|
|
||||||
float imageWidth = _texture->getWidth();
|
|
||||||
float imageHeight = _texture->getHeight();
|
|
||||||
|
|
||||||
// if for some reason our image is not over 0 width or height, don't attempt to render the image
|
// if for some reason our image is not over 0 width or height, don't attempt to render the image
|
||||||
if (_renderImage && imageWidth > 0 && imageHeight > 0) {
|
if (_renderImage) {
|
||||||
|
float imageWidth = _texture->getWidth();
|
||||||
|
float imageHeight = _texture->getHeight();
|
||||||
|
if (imageWidth > 0 && imageHeight > 0) {
|
||||||
|
QRect fromImage;
|
||||||
|
if (_wantClipFromImage) {
|
||||||
|
float scaleX = imageWidth / _texture->getOriginalWidth();
|
||||||
|
float scaleY = imageHeight / _texture->getOriginalHeight();
|
||||||
|
|
||||||
QRect fromImage;
|
fromImage.setX(scaleX * _fromImage.x());
|
||||||
if (_wantClipFromImage) {
|
fromImage.setY(scaleY * _fromImage.y());
|
||||||
float scaleX = imageWidth / _texture->getOriginalWidth();
|
fromImage.setWidth(scaleX * _fromImage.width());
|
||||||
float scaleY = imageHeight / _texture->getOriginalHeight();
|
fromImage.setHeight(scaleY * _fromImage.height());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fromImage.setX(0);
|
||||||
|
fromImage.setY(0);
|
||||||
|
fromImage.setWidth(imageWidth);
|
||||||
|
fromImage.setHeight(imageHeight);
|
||||||
|
}
|
||||||
|
|
||||||
fromImage.setX(scaleX * _fromImage.x());
|
float x = fromImage.x() / imageWidth;
|
||||||
fromImage.setY(scaleY * _fromImage.y());
|
float y = fromImage.y() / imageHeight;
|
||||||
fromImage.setWidth(scaleX * _fromImage.width());
|
float w = fromImage.width() / imageWidth; // ?? is this what we want? not sure
|
||||||
fromImage.setHeight(scaleY * _fromImage.height());
|
float h = fromImage.height() / imageHeight;
|
||||||
} else {
|
|
||||||
fromImage.setX(0);
|
glm::vec2 texCoordTopLeft(x, y);
|
||||||
fromImage.setY(0);
|
glm::vec2 texCoordBottomRight(x + w, y + h);
|
||||||
fromImage.setWidth(imageWidth);
|
|
||||||
fromImage.setHeight(imageHeight);
|
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, quadColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
float x = fromImage.x() / imageWidth;
|
if (_renderImage) {
|
||||||
float y = fromImage.y() / imageHeight;
|
glDisable(GL_TEXTURE_2D);
|
||||||
float w = fromImage.width() / imageWidth; // ?? is this what we want? not sure
|
}
|
||||||
float h = fromImage.height() / imageHeight;
|
|
||||||
|
|
||||||
glm::vec2 texCoordTopLeft(x, y);
|
|
||||||
glm::vec2 texCoordBottomRight(x + w, y + h);
|
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor);
|
|
||||||
} else {
|
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, quadColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_renderImage) {
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageOverlay::setProperties(const QScriptValue& properties) {
|
void ImageOverlay::setProperties(const QScriptValue& properties) {
|
||||||
Overlay2D::setProperties(properties);
|
Overlay2D::setProperties(properties);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue