Commit a66c5e69 authored by Oliver Bock's avatar Oliver Bock

Added texture checks

* Quadratic shape
* Dimensions a power of 2
* Maximum size (automatic scaling if exceeded)
* Also: removed simple background
parent f63f2520
......@@ -164,10 +164,49 @@ void PulsarAnimationWidget::initializeGL()
gluQuadricNormals(m_quadricPulsarSpinAxis, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarMagneticAxis, GLU_SMOOTH);
// load textures
m_pulsarTexture = bindTexture(QImage(":/textures/resources/texture_pulsar.png"), GL_TEXTURE_2D, GL_RGBA);
// m_backgroundTexture = bindTexture(QImage(":/textures/resources/texture_background_simple.png"), GL_TEXTURE_2D, GL_RGBA);
m_backgroundTexture = bindTexture(QImage(":/textures/resources/texture_background_carina.jpg"), GL_TEXTURE_2D, GL_RGB);
// query max texture size (estimate)
GLint maxTextureSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
// prepare and check pulsar texture
QImage pulsarTexture(":/textures/resources/texture_pulsar.png");
if(pulsarTexture.width() != pulsarTexture.height()) {
qWarning("Warning: pulsar texture shape not quadratic!");
}
else {
double integer = 0.0;
double fraction = 0.0;
fraction = modf(log(pulsarTexture.width()) / log(2.0), &integer);
if(fraction > 0.0) {
qWarning("Warning: pulsar texture dimensions not a power of 2!");
}
}
if(pulsarTexture.width() > maxTextureSize) {
qDebug("Warning: maximum texture size exceeded! Scaling down pulsar texture to %ix%i...", maxTextureSize, maxTextureSize);
pulsarTexture = pulsarTexture.scaled(maxTextureSize, maxTextureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
// prepare and check background texture
QImage backgroundTexture(":/textures/resources/texture_background_carina.jpg");
if(backgroundTexture.width() != backgroundTexture.height()) {
qWarning("Warning: invalid background texture shape!");
}
else {
double integer = 0.0;
double fraction = 0.0;
fraction = modf(log(backgroundTexture.width()) / log(2.0), &integer);
if(fraction > 0.0) {
qWarning("Warning: background texture dimensions not a power of 2!");
}
}
if(backgroundTexture.width() > maxTextureSize) {
qDebug("Warning: maximum texture size exceeded! Scaling down background texture to %ix%i...", maxTextureSize, maxTextureSize);
backgroundTexture = backgroundTexture.scaled(maxTextureSize, maxTextureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
// bind textures
m_pulsarTexture = bindTexture(pulsarTexture, GL_TEXTURE_2D, GL_RGBA);
m_backgroundTexture = bindTexture(backgroundTexture, GL_TEXTURE_2D, GL_RGB);
// use mipmapped textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment