diff --git a/src/pulsaranimationwidget.cpp b/src/pulsaranimationwidget.cpp index f1f8f54f9fc014be2153b66287604738d5f50e34..653b82a2dea1874a4c82f5e4205b1cd15ad62e9c 100644 --- a/src/pulsaranimationwidget.cpp +++ b/src/pulsaranimationwidget.cpp @@ -105,6 +105,17 @@ void PulsarAnimationWidget::initializeGL() gluQuadricNormals(m_quadricPulsar, GLU_SMOOTH); gluQuadricNormals(m_quadricPulsarCone1, GLU_SMOOTH); gluQuadricNormals(m_quadricPulsarCone2, GLU_SMOOTH); + + // load pulsar texture + m_pulsarTexture = bindTexture(QImage(":/textures/resources/texture_pulsar.png"), GL_TEXTURE_2D, GL_RGBA); + + // use mipmap filter + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + + // enable 2D sphere mapping (s/t coordinates) + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); } void PulsarAnimationWidget::resizeGL(int w, int h) @@ -135,7 +146,7 @@ void PulsarAnimationWidget::paintGL() static GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 }; static GLfloat mat_diffuse[] = { 0.5, 0.5, 0.5, 1.0 }; static GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; - static GLfloat low_shininess[] = { 5.0 }; + static GLfloat low_shininess[] = { 2.5 }; glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); @@ -156,9 +167,21 @@ void PulsarAnimationWidget::paintGL() cos(m_orbitRotationAngle * deg2rad) * m_pulsarOrbitRadius); glPushMatrix(); + // enable texture coordinates and bind texture + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glBindTexture(GL_TEXTURE_2D, m_pulsarTexture); + + // FIXME: how to rotate texture? glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f); glRotatef(m_pulsarSpinAxisInclination, 1.0f, 0.0f, 0.0f); gluSphere(m_quadricPulsar, 1.0f, 32, 32); + + // disable texture coordinates + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_2D); glPopMatrix(); // TODO: should be located elsewhere diff --git a/src/pulsaranimationwidget.h b/src/pulsaranimationwidget.h index a113f39f705e787fdb2dbd3ec4879d0185ba3765..737af75d46ea17c5132b55e6749fb41abf52b0c2 100644 --- a/src/pulsaranimationwidget.h +++ b/src/pulsaranimationwidget.h @@ -71,6 +71,8 @@ protected: GLUquadricObj *m_quadricPulsarCone1; GLUquadricObj *m_quadricPulsarCone2; + GLuint m_pulsarTexture; + int m_framesPerSecond; float m_pulsarRotationAngle; diff --git a/src/pulsatingscience.qrc b/src/pulsatingscience.qrc index 0b97917bb7700a17c864797273537ce59fd61ccb..6911ea50ffadefc288ce0e32f094cd6e8fe93b9e 100644 --- a/src/pulsatingscience.qrc +++ b/src/pulsatingscience.qrc @@ -9,4 +9,7 @@ <file>resources/help-website.png</file> <file>resources/aei-icon48.png</file> </qresource> + <qresource prefix="textures" > + <file>resources/texture_pulsar.png</file> + </qresource> </RCC> diff --git a/src/resources/texture_pulsar.png b/src/resources/texture_pulsar.png new file mode 100644 index 0000000000000000000000000000000000000000..853e40a6e323e74d5c4fdb0a46a6bc737eadc2ec Binary files /dev/null and b/src/resources/texture_pulsar.png differ