diff --git a/src/pulsaranimationwidget.cpp b/src/pulsaranimationwidget.cpp index 630f2c8818c57f16a90b8f05e11a47dde6bd7d71..7a201285b1fd8cd0504fb085d4839a36f41a80fd 100644 --- a/src/pulsaranimationwidget.cpp +++ b/src/pulsaranimationwidget.cpp @@ -70,6 +70,7 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) : // initialize texture pointers m_backgroundTexture = 0; + m_beamTexture = 0; // initial render timing settings m_framesPerSecond = 25; @@ -118,6 +119,7 @@ PulsarAnimationWidget::~PulsarAnimationWidget() if(m_quadricLineOfSightCone) gluDeleteQuadric(m_quadricLineOfSightCone); if(m_quadricLineOfSightConeBase) gluDeleteQuadric(m_quadricLineOfSightConeBase); if(m_backgroundTexture) deleteTexture(m_backgroundTexture); + if(m_beamTexture) deleteTexture(m_beamTexture); } void PulsarAnimationWidget::initializeGL() @@ -202,16 +204,31 @@ void PulsarAnimationWidget::initializeGL() backgroundTexture = backgroundTexture.scaled(maxTextureSize, maxTextureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } + // prepare and check beam texture + QImage beamTexture(":/textures/resources/texture_beam.png"); + if(beamTexture.width() != beamTexture.height()) { + qWarning() << msgShape.arg(tr("Beam")); + } + else { + double integer = 0.0; + double fraction = 0.0; + fraction = modf(log(beamTexture.width()) / log(2.0), &integer); + if(fraction > 0.0) { + qWarning() << msgPower.arg(tr("Beam")); + } + } + if(beamTexture.width() > maxTextureSize) { + qWarning() << msgSize.arg(tr("beam").arg(maxTextureSize).arg(maxTextureSize)); + beamTexture = beamTexture.scaled(maxTextureSize, maxTextureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + } + // bind textures m_backgroundTexture = bindTexture(backgroundTexture, GL_TEXTURE_2D, GL_RGBA); + m_beamTexture = bindTexture(beamTexture, GL_TEXTURE_2D, GL_RGBA); // use mipmapped textures glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - - // enable 2D mapping (s/t coordinates, sphere map won't rotate texture!) - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); } void PulsarAnimationWidget::resizeGL(int w, int h) @@ -331,14 +348,7 @@ void PulsarAnimationWidget::paintGL() } glPopMatrix(); - // TODO: should be located elsewhere - static GLfloat coneAmbient[] = {1.0, 1.0, 0.0, 1.0}; - static GLfloat coneDiffuse[] = {1.0, 1.0, 0.0, 1.0}; - static GLfloat coneSpecular[] = {1.0, 1.0, 0.5, 1.0}; - - glMaterialfv(GL_FRONT, GL_SPECULAR, coneSpecular); - - // first cone + // first cone (pointing away from camera) glPushMatrix(); { glRotatef(-m_pulsarSpinAxisInclination, 1.0, 0.0, 0.0); @@ -373,15 +383,13 @@ void PulsarAnimationWidget::paintGL() glTranslatef(0.0, 0.0, -m_pulsarBeamLength); - glMaterialfv(GL_FRONT, GL_AMBIENT, coneAmbient); - glMaterialfv(GL_FRONT, GL_DIFFUSE, coneDiffuse); // draw first cone's outer layer glBegin(GL_TRIANGLE_FAN); { // Pinnacle of cone is shared vertex for fan, moved up z-axis // to produce a cone instead of a circle - glColor3f(1.0f, 1.0f, 0.0f); + glColor4f(1.0f, 1.0f, 0.0f, 0.33f); glVertex3f(0.0f, 0.0f, m_pulsarBeamLength); // Loop around in a circle and specify even points along the circle @@ -398,26 +406,25 @@ void PulsarAnimationWidget::paintGL() } glEnd(); - // draw first cone's inner layer (do we need/want this?) - glBegin(GL_TRIANGLE_FAN); - { - glColor3f(0.66f, 0.66f, 0.0f); - glVertex3f(0.0f, 0.0f, m_pulsarBeamLength); - for(angle = 0.0f; angle < (2.0f*PI); angle += (PI/32.0f)) { - x = m_pulsarBeamInnerRadius * sin(angle); - y = m_pulsarBeamInnerRadius * cos(angle); - glVertex2f(x, y); - } - } - glEnd(); + // draw first cone's "base" (textured bottom to visualize beam intensity) + glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + // create texture coordinates and enable texturing + gluQuadricTexture(m_quadricPulsarConeRim1, GL_TRUE); + glBindTexture(GL_TEXTURE_2D, m_beamTexture); + glEnable(GL_TEXTURE_2D); + + gluDisk(m_quadricPulsarConeRim1, 0, m_pulsarBeamOuterRadius, 32, 1); - // draw first cone's "rim" (disk topping gap between both cones) - glColor3f(1.0f, 1.0f, 0.5f); - gluDisk(m_quadricPulsarConeRim1, m_pulsarBeamInnerRadius, m_pulsarBeamOuterRadius, 32, 8); + // disable texturing + glDisable(GL_TEXTURE_2D); + + glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); } glPopMatrix(); - // second cone + // second cone (pointing towards from camera) glPushMatrix(); { glRotatef(180.0, 1.0, 0.0, 0.0); @@ -428,15 +435,12 @@ void PulsarAnimationWidget::paintGL() glTranslatef(0.0, 0.0, -m_pulsarBeamLength); - glMaterialfv(GL_FRONT, GL_AMBIENT, coneAmbient); - glMaterialfv(GL_FRONT, GL_DIFFUSE, coneDiffuse); - - // draw first cone's outer layer + // draw second cone's outer layer glBegin(GL_TRIANGLE_FAN); { // Pinnacle of cone is shared vertex for fan, moved up z-axis // to produce a cone instead of a circle - glColor3f(1.0f, 1.0f, 0.0f); + glColor4f(1.0f, 1.0f, 0.0f, 0.33f); glVertex3f(0.0f, 0.0f, m_pulsarBeamLength); // Loop around in a circle and specify even points along the circle @@ -453,22 +457,21 @@ void PulsarAnimationWidget::paintGL() } glEnd(); - // draw first cone's inner layer (do we need/want this?) - glBegin(GL_TRIANGLE_FAN); - { - glColor3f(0.66f, 0.66f, 0.0f); - glVertex3f(0.0f, 0.0f, m_pulsarBeamLength); - for(angle = 0.0f; angle < (2.0f*PI); angle += (PI/32.0f)) { - x = m_pulsarBeamInnerRadius * sin(angle); - y = m_pulsarBeamInnerRadius * cos(angle); - glVertex2f(x, y); - } - } - glEnd(); + // draw second cone's "base" (textured bottom to visualize beam intensity) + glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + // create texture coordinates and enable texturing + gluQuadricTexture(m_quadricPulsarConeRim2, GL_TRUE); + glBindTexture(GL_TEXTURE_2D, m_beamTexture); + glEnable(GL_TEXTURE_2D); + + gluDisk(m_quadricPulsarConeRim2, 0, m_pulsarBeamOuterRadius, 32, 1); - // draw first cone's "rim" (disk topping gap between both cones) - glColor3f(1.0f, 1.0f, 0.5f); - gluDisk(m_quadricPulsarConeRim2, m_pulsarBeamInnerRadius, m_pulsarBeamOuterRadius, 32, 8); + // disable texturing + glDisable(GL_TEXTURE_2D); + + glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); } glPopMatrix(); } @@ -499,7 +502,6 @@ void PulsarAnimationWidget::paintGL() // draw backdrop (independent parallel projection) glColor3f(1.0f, 1.0f, 1.0f); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_specular); glTranslatef(0.0, 0.0, -501.0); drawTexture(QPointF(0.0, 0.0), m_backgroundTexture); diff --git a/src/pulsaranimationwidget.h b/src/pulsaranimationwidget.h index b3e23d9e56f5678a6ac1c64205cd52d363c0a4c9..8149bd21d65ee7ceb6a05a08b846ab1770b3239a 100644 --- a/src/pulsaranimationwidget.h +++ b/src/pulsaranimationwidget.h @@ -88,6 +88,7 @@ private: GLUquadricObj *m_quadricLineOfSightConeBase; GLuint m_backgroundTexture; + GLuint m_beamTexture; int m_framesPerSecond; diff --git a/src/pulsatingscience.qrc b/src/pulsatingscience.qrc index 983fcf3e063a9b5dfd570098a9fbc9bf973e4df4..0eaace8cc94dfd75dd7008bcf5de10001df671f7 100644 --- a/src/pulsatingscience.qrc +++ b/src/pulsatingscience.qrc @@ -16,5 +16,6 @@ <qresource prefix="/textures"> <file>resources/texture_background_carina.png</file> <file>resources/texture_pulsar.png</file> + <file>resources/texture_beam.png</file> </qresource> </RCC> diff --git a/src/resources/texture_beam.png b/src/resources/texture_beam.png new file mode 100644 index 0000000000000000000000000000000000000000..5e163ae79f5a8edd62341ee82f87bfa94f16874e Binary files /dev/null and b/src/resources/texture_beam.png differ diff --git a/src/resources/texture_beam.svg b/src/resources/texture_beam.svg new file mode 100644 index 0000000000000000000000000000000000000000..331bea94f9741cfcf1c538a9fce2fab142d16bce --- /dev/null +++ b/src/resources/texture_beam.svg @@ -0,0 +1,133 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448819" + height="1052.3622047" + id="svg2" + version="1.1" + inkscape:version="0.47 r22583" + sodipodi:docname="texture_beam.svg"> + <defs + id="defs4"> + <linearGradient + id="linearGradient3685"> + <stop + style="stop-color:#ffff00;stop-opacity:1;" + offset="0" + id="stop3687" /> + <stop + style="stop-color:#ffff00;stop-opacity:0;" + offset="1" + id="stop3689" /> + </linearGradient> + <linearGradient + id="linearGradient3679"> + <stop + id="stop3681" + offset="0" + style="stop-color:#ffff00;stop-opacity:0;" /> + <stop + style="stop-color:#ffff00;stop-opacity:0.33613446;" + offset="0.68535012" + id="stop3705" /> + <stop + id="stop3703" + offset="0.85416669" + style="stop-color:#ffff00;stop-opacity:0.74901961;" /> + <stop + style="stop-color:#ffff00;stop-opacity:1;" + offset="0.85416669" + id="stop3691" /> + <stop + id="stop3683" + offset="1" + style="stop-color:#ffff00;stop-opacity:0;" /> + </linearGradient> + <linearGradient + id="linearGradient3671"> + <stop + style="stop-color:#ffff00;stop-opacity:1;" + offset="0" + id="stop3673" /> + <stop + style="stop-color:#ffff00;stop-opacity:0;" + offset="1" + id="stop3675" /> + </linearGradient> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3679" + id="radialGradient3677" + cx="438.57144" + cy="610.93359" + fx="438.57144" + fy="610.93359" + r="187.14285" + gradientUnits="userSpaceOnUse" + spreadMethod="repeat" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="0.71743361" + inkscape:cx="123.94066" + inkscape:cy="470.4268" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1680" + inkscape:window-height="1002" + inkscape:window-x="1440" + inkscape:window-y="22" + inkscape:window-maximized="0" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <path + sodipodi:type="arc" + style="fill:url(#radialGradient3677);fill-opacity:1.0" + id="path2816" + sodipodi:cx="438.57144" + sodipodi:cy="610.93359" + sodipodi:rx="187.14285" + sodipodi:ry="187.14285" + d="m 625.71429,610.93359 a 187.14285,187.14285 0 1 1 -374.2857,0 187.14285,187.14285 0 1 1 374.2857,0 z" + transform="matrix(1.367939,0,0,1.367939,-217.81337,-338.24157)" + inkscape:export-filename="/Users/oliver/Development/pulsatingscience/src/resources/texture_beam.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90" /> + </g> +</svg>