Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pulsatingscience
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
einsteinathome
pulsatingscience
Commits
2f3c6acb
Commit
2f3c6acb
authored
Oct 06, 2017
by
Oliver Bock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: QGLWidget -> QOpenGLWidget migration (resolve known renderText() issues)
parent
14611ac7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
42 deletions
+73
-42
src/pulsaranimationwidget.cpp
src/pulsaranimationwidget.cpp
+68
-39
src/pulsaranimationwidget.h
src/pulsaranimationwidget.h
+5
-3
No files found.
src/pulsaranimationwidget.cpp
View file @
2f3c6acb
...
...
@@ -21,32 +21,13 @@
#include "pulsaranimationwidget.h"
#include "lib/antenna_lib.h"
#include <QPainter>
const
double
PulsarAnimationWidget
::
deg2rad
=
PI
/
180.0
;
PulsarAnimationWidget
::
PulsarAnimationWidget
(
QWidget
*
parent
)
:
Q
GLWidget
(
QGLFormat
(
QGL
::
AlphaChannel
|
QGL
::
SampleBuffers
),
parent
)
Q
OpenGLWidget
(
parent
)
{
QString
msgThis
=
tr
(
"3D animation"
);
if
(
!
format
().
directRendering
())
{
QString
msg
=
tr
(
"Sorry, no direct rendering support for %1..."
);
qWarning
()
<<
msg
.
arg
(
msgThis
);
}
if
(
!
format
().
doubleBuffer
())
{
QString
msg
=
tr
(
"Sorry, no double buffering support for %1..."
);
qWarning
()
<<
msg
.
arg
(
msgThis
);
}
if
(
!
format
().
rgba
())
{
QString
msg
=
tr
(
"Sorry, no RGBA support for %1..."
);
qWarning
()
<<
msg
.
arg
(
msgThis
);
}
if
(
!
format
().
alpha
())
{
QString
msg
=
tr
(
"Sorry, no alpha channel support for %1..."
);
qWarning
()
<<
msg
.
arg
(
msgThis
);
}
if
(
!
format
().
sampleBuffers
())
{
QString
msg
=
tr
(
"Sorry, no multisampling support for %1..."
);
qWarning
()
<<
msg
.
arg
(
msgThis
);
}
// initialize quadric pointers
m_quadricVirgoh
=
NULL
;
...
...
@@ -162,11 +143,9 @@ void PulsarAnimationWidget::initializeGL()
GLint
maxTextureSize
;
glGetIntegerv
(
GL_MAX_TEXTURE_SIZE
,
&
maxTextureSize
);
// prepare and
check
beam texture
// prepare and
bind
beam texture
QImage
beamTexture
(
":/textures/resources/World-Map-7.jpg"
);
// bind textures
m_beamTexture
=
bindTexture
(
beamTexture
,
GL_TEXTURE_2D
,
GL_RGBA
);
m_beamTexture
=
new
QOpenGLTexture
(
beamTexture
.
mirrored
());
// use mipmapped textures
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
...
...
@@ -250,7 +229,7 @@ void PulsarAnimationWidget::paintGL()
// create texture coordinates and enable texturing
gluQuadricTexture
(
m_quadricEarth
,
GL_TRUE
);
glBindTexture
(
GL_TEXTURE_2D
,
m_beamTexture
);
m_beamTexture
->
bind
(
);
glEnable
(
GL_TEXTURE_2D
);
glCullFace
(
GL_FRONT
);
...
...
@@ -452,10 +431,10 @@ void PulsarAnimationWidget::paintGL()
font
.
setBold
(
true
);
font
.
setFamily
(
"Arial"
);
font
.
setStyleStrategy
((
QFont
::
StyleStrategy
)
(
QFont
::
OpenGLCompatible
|
QFont
::
PreferQuality
));
renderText
(
10
,
4
0
,
-
100
,
tr
(
"B. Allen and O. Bock"
),
font
);
renderText
(
10
,
25
,
-
100
,
tr
(
"MPI for Gravitational Physics"
));
renderText
(
10
,
10
,
-
100
,
QString
(
"Copyright %1 2017"
).
arg
(
QChar
(
0x00A9
)));
renderText
(
0
,
0
,
-
100
,
tr
(
"B. Allen and O. Bock"
),
font
);
//
renderText(10, 25, -100, tr("MPI for Gravitational Physics"));
//
renderText(10, 10, -100, QString("Copyright %1 2017").arg(QChar(0x00A9)));
// restore original state
glMatrixMode
(
GL_PROJECTION
);
}
...
...
@@ -470,7 +449,7 @@ void PulsarAnimationWidget::mousePressEvent(QMouseEvent *event)
Q_UNUSED
(
event
);
m_cameraInteraction
=
true
;
update
GL
();
update
();
}
void
PulsarAnimationWidget
::
mouseMoveEvent
(
QMouseEvent
*
event
)
...
...
@@ -512,7 +491,7 @@ void PulsarAnimationWidget::mouseReleaseEvent(QMouseEvent *event)
m_mouseLastY
=
0
;
m_cameraInteraction
=
false
;
update
GL
();
update
();
}
void
PulsarAnimationWidget
::
showEvent
(
QShowEvent
*
event
)
...
...
@@ -529,7 +508,7 @@ void PulsarAnimationWidget::updateCameraPosition(const double angleH, const doub
m_cameraPosY
=
sin
(
angleV
*
deg2rad
)
*
zoom
;
m_cameraPosZ
=
cos
(
angleH
*
deg2rad
)
*
cos
(
angleV
*
deg2rad
)
*
zoom
;
update
GL
();
update
();
}
void
PulsarAnimationWidget
::
setSourceInclination
(
const
double
degrees
)
...
...
@@ -545,7 +524,7 @@ void PulsarAnimationWidget::setSourceInclination(const double degrees)
m_sourceInclination
=
degrees
;
updatePulseProfile
();
update
GL
();
update
();
}
void
PulsarAnimationWidget
::
setLHOAngle
(
const
double
degrees
)
...
...
@@ -553,7 +532,7 @@ void PulsarAnimationWidget::setLHOAngle(const double degrees)
m_LHOAngle
=
degrees
;
updatePulseProfile
();
update
GL
();
update
();
}
void
PulsarAnimationWidget
::
setLLOAngle
(
const
double
degrees
)
...
...
@@ -561,7 +540,7 @@ void PulsarAnimationWidget::setLLOAngle(const double degrees)
m_LLOAngle
=
degrees
;
updatePulseProfile
();
update
GL
();
update
();
}
void
PulsarAnimationWidget
::
setVirgoAngle
(
const
int
degrees
)
...
...
@@ -569,7 +548,7 @@ void PulsarAnimationWidget::setVirgoAngle(const int degrees)
m_VirgoAngle
=
degrees
;
updatePulseProfile
();
update
GL
();
update
();
}
void
PulsarAnimationWidget
::
setSourceIota
(
const
int
degrees
)
...
...
@@ -577,7 +556,7 @@ void PulsarAnimationWidget::setSourceIota(const int degrees)
m_sourceIota
=
degrees
;
updatePulseProfile
();
update
GL
();
update
();
}
void
PulsarAnimationWidget
::
getCameraPosition
(
double
&
cameraAngleH
,
double
&
cameraAngleV
,
double
&
cameraZoom
)
...
...
@@ -596,6 +575,56 @@ void PulsarAnimationWidget::resetCameraPosition(const double angleH, const doubl
updateCameraPosition
(
m_mouseAngleH
,
m_mouseAngleV
,
m_cameraZoom
);
}
void
PulsarAnimationWidget
::
renderText
(
double
x
,
double
y
,
double
z
,
const
QString
&
text
,
const
QFont
&
font
)
{
// Identify x and y locations to render text within widget
int
height
=
this
->
height
();
GLdouble
textPosX
=
0
,
textPosY
=
0
,
textPosZ
=
0
;
// project(x, y, 0f, &textPosX, &textPosY, &textPosZ);
textPosY
=
height
-
textPosY
;
// y is inverted
// Retrieve last OpenGL color to use as a font color
GLdouble
glColor
[
4
];
glGetDoublev
(
GL_CURRENT_COLOR
,
glColor
);
QColor
fontColor
=
QColor
(
glColor
[
0
],
glColor
[
1
],
glColor
[
2
],
glColor
[
3
]);
// save OpenGL state
glPushAttrib
(
GL_ACCUM_BUFFER_BIT
);
glPushAttrib
(
GL_COLOR_BUFFER_BIT
);
glPushAttrib
(
GL_CURRENT_BIT
);
glPushAttrib
(
GL_DEPTH_BUFFER_BIT
);
glPushAttrib
(
GL_ENABLE_BIT
);
glPushAttrib
(
GL_EVAL_BIT
);
glPushAttrib
(
GL_FOG_BIT
);
glPushAttrib
(
GL_HINT_BIT
);
glPushAttrib
(
GL_FOG_BIT
);
glPushAttrib
(
GL_LIGHTING_BIT
);
glPushAttrib
(
GL_LINE_BIT
);
glPushAttrib
(
GL_LIST_BIT
);
glPushAttrib
(
GL_MULTISAMPLE_BIT
);
glPushAttrib
(
GL_PIXEL_MODE_BIT
);
glPushAttrib
(
GL_POINT_BIT
);
glPushAttrib
(
GL_POLYGON_BIT
);
glPushAttrib
(
GL_POLYGON_STIPPLE_BIT
);
glPushAttrib
(
GL_SCISSOR_BIT
);
glPushAttrib
(
GL_STENCIL_BUFFER_BIT
);
glPushAttrib
(
GL_TEXTURE_BIT
);
glPushAttrib
(
GL_TRANSFORM_BIT
);
glPushAttrib
(
GL_VIEWPORT_BIT
);
glPushClientAttrib
(
GL_CLIENT_ALL_ATTRIB_BITS
);
// Render text
QPainter
painter
(
this
);
painter
.
setPen
(
fontColor
);
painter
.
setFont
(
font
);
painter
.
setRenderHints
(
QPainter
::
Antialiasing
|
QPainter
::
TextAntialiasing
);
painter
.
drawText
(
textPosX
,
textPosY
,
text
);
painter
.
end
();
// save OpenGL state
glPopAttrib
();
glPopClientAttrib
();
}
void
PulsarAnimationWidget
::
updatePulseProfile
()
{
struct
InputStruct
in
;
...
...
src/pulsaranimationwidget.h
View file @
2f3c6acb
...
...
@@ -23,7 +23,8 @@
#include <cmath>
#include <QGLWidget>
#include <QOpenGLWidget>
#include <QOpenGLTexture>
#include <QTimer>
#include <QMouseEvent>
#include <QDebug>
...
...
@@ -39,7 +40,7 @@
#define PI 3.14159265
class
PulsarAnimationWidget
:
public
QGLWidget
class
PulsarAnimationWidget
:
public
Q
Open
GLWidget
{
Q_OBJECT
...
...
@@ -54,6 +55,7 @@ public:
void
setSourceInclination
(
const
double
length
);
void
getCameraPosition
(
double
&
cameraAngleH
,
double
&
cameraAngleV
,
double
&
cameraZoom
);
void
resetCameraPosition
(
const
double
angleH
,
const
double
angleV
,
const
double
zoom
);
void
renderText
(
double
x
,
double
y
,
double
z
,
const
QString
&
text
,
const
QFont
&
font
=
QFont
());
signals:
void
pulseProfileUpdated
(
const
PlotData
&
data
);
...
...
@@ -83,7 +85,7 @@ private:
GLUquadricObj
*
m_quadricLHOv
;
GLUquadricObj
*
m_quadricLHOh
;
GLuint
m_beamTexture
;
QOpenGLTexture
*
m_beamTexture
;
double
m_earthRadius
;
double
m_LHOAngle
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment