Stellarium  23.4
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Friends
StelPainter Class Reference

Provides functions for performing openGL drawing operations. More...

#include <StelPainter.hpp>

Public Types

enum  SphericalPolygonDrawMode { SphericalPolygonDrawModeFill =0 , SphericalPolygonDrawModeBoundary =1 , SphericalPolygonDrawModeTextureFill =2 , SphericalPolygonDrawModeTextureFillColormodulated =3 }
 Define the drawing mode when drawing polygons. More...
 
enum  DrawingMode {
  Points = 0x0000 , Lines = 0x0001 , LineLoop = 0x0002 , LineStrip = 0x0003 ,
  Triangles = 0x0004 , TriangleStrip = 0x0005 , TriangleFan = 0x0006
}
 Define the drawing mode when drawing vertex. More...
 

Public Member Functions

 StelPainter (const StelProjectorP &prj)
 
QOpenGLFunctions * glFuncs ()
 Returns a QOpenGLFunctions object suitable for drawing directly with OpenGL while this StelPainter is active. More...
 
const StelProjectorP & getProjector () const
 Return the instance of projector associated to this painter.
 
void setProjector (const StelProjectorP &p)
 
void drawViewportShape (void)
 Fill with black around the viewport.
 
void drawText (float x, float y, const QString &str, float angleDeg=0.f, float xshift=0.f, float yshift=0.f, bool noGravity=true)
 Draw the string at the given position and angle with the given font. More...
 
void drawText (const Vec3d &v, const QString &str, float angleDeg=0.f, float xshift=0.f, float yshift=0.f, bool noGravity=true)
 
void drawSphericalRegion (SphericalRegion *region, SphericalPolygonDrawMode drawMode=SphericalPolygonDrawModeFill, const SphericalCap *clippingCap=Q_NULLPTR, bool doSubDivise=true, double maxSqDistortion=5., const Vec3d &observerVelocity=Vec3d(0.))
 Draw the given SphericalRegion. More...
 
void drawGreatCircleArcs (const StelVertexArray &va, const SphericalCap *clippingCap=Q_NULLPTR)
 
void drawSphericalTriangles (const StelVertexArray &va, bool textured, bool colored, const SphericalCap *clippingCap=Q_NULLPTR, bool doSubDivide=true, double maxSqDistortion=5.)
 
void drawSmallCircleArc (const Vec3d &start, const Vec3d &stop, const Vec3d &rotCenter, void(*viewportEdgeIntersectCallback)(const Vec3d &screenPos, const Vec3d &direction, void *userData)=Q_NULLPTR, void *userData=Q_NULLPTR)
 Draw a small circle arc between points start and stop with rotation point in rotCenter. More...
 
void drawGreatCircleArc (const Vec3d &start, const Vec3d &stop, const SphericalCap *clippingCap=Q_NULLPTR, void(*viewportEdgeIntersectCallback)(const Vec3d &screenPos, const Vec3d &direction, void *userData)=Q_NULLPTR, void *userData=Q_NULLPTR)
 Draw a great circle arc between points start and stop. More...
 
void drawPath (const QVector< Vec3d > &points, const QVector< Vec4f > &colors)
 Draw a curve defined by a list of points. More...
 
void drawCircle (float x, float y, float r)
 Draw a simple circle, 2d viewport coordinates in pixel.
 
void drawEllipse (double x, double y, double rx, double ry, double angle)
 Draw a simple ellipse, 2d viewport coordinates in pixel. More...
 
void drawSprite2dMode (float x, float y, float radius)
 Draw a square using the current texture at the given projected 2d position. More...
 
void drawSprite2dMode (const Vec3d &v, float radius)
 
void drawSprite2dModeNoDeviceScale (float x, float y, float radius)
 Same as drawSprite2dMode but don't scale according to display device scaling.
 
void drawSprite2dMode (float x, float y, float radius, float rotation)
 Draw a rotated square using the current texture at the given projected 2d position. More...
 
void drawPoint2d (float x, float y)
 Draw a GL_POINT at the given position. More...
 
void drawLine2d (float x1, float y1, float x2, float y2)
 Draw a line between the 2 points. More...
 
void drawRect2d (float x, float y, float width, float height, bool textured=true)
 Draw a rectangle using the current texture at the given projected 2d position. More...
 
void sSphere (const double radius, const double oneMinusOblateness, const unsigned int slices, const unsigned int stacks, const bool orientInside=false, const bool flipTexture=false, const float topAngle=0.0f, const float bottomAngle=static_cast< float >(M_PI))
 
void sCylinder (double radius, double height, int slices, int orientInside=0)
 Re-implementation of gluCylinder : glu is overridden for non-standard projection.
 
void sSphereMap (double radius, unsigned int slices, unsigned int stacks, float textureFov=2.f *static_cast< float >(M_PI), int orientInside=0)
 Draw a fisheye texture in a sphere.
 
void setFont (const QFont &font)
 Set the font to use for subsequent text drawing.
 
void setColor (float r, float g, float b, float a=1.f)
 Set the color to use for subsequent drawing.
 
void setColor (Vec3f rgb, float a=1.f)
 Set the color to use for subsequent drawing.
 
void setColor (Vec4f rgba)
 Set the color to use for subsequent drawing.
 
Vec4f getColor () const
 Get the color currently used for drawing.
 
QFontMetrics getFontMetrics () const
 Get the font metrics for the current font.
 
void setBlending (bool enableBlending, GLenum blendSrc=GL_SRC_ALPHA, GLenum blendDst=GL_ONE_MINUS_SRC_ALPHA)
 Enable OpenGL blending. More...
 
bool getBlending (GLenum *src=Q_NULLPTR, GLenum *dst=Q_NULLPTR) const
 Retrieve current blending configuration It is useful to preserve and restore these settings with setBlending() later.
 
void setDepthTest (bool enable)
 
void setDepthMask (bool enable)
 
void setCullFace (bool enable)
 Set the OpenGL GL_CULL_FACE state, by default face culling is disabled.
 
void setLineSmooth (bool enable)
 Enables/disables line smoothing. By default, smoothing is disabled.
 
void setLineWidth (float width)
 Sets the line width. Default is 1.0f.
 
float getLineWidth () const
 Gets the line width.
 
void setSaturation (float v)
 Sets the color saturation effect value, from 0 (grayscale) to 1 (no effect).
 
void setVertexPointer (int size, GLenum type, const void *pointer)
 use instead of glVertexPointer
 
void setTexCoordPointer (int size, GLenum type, const void *pointer)
 use instead of glTexCoordPointer
 
void setColorPointer (int size, GLenum type, const void *pointer)
 use instead of glColorPointer
 
void setNormalPointer (GLenum type, const void *pointer)
 use instead of glNormalPointer
 
void enableClientStates (bool vertex, bool texture=false, bool color=false, bool normal=false)
 Simulates glEnableClientState, basically you describe what data the ::drawFromArray call has available.
 
void setArrays (const Vec3d *vertices, const Vec2f *texCoords=Q_NULLPTR, const Vec3f *colorArray=Q_NULLPTR, const Vec3f *normalArray=Q_NULLPTR)
 convenience method that enable and set all the given arrays. More...
 
void setArrays (const Vec3f *vertices, const Vec2f *texCoords=Q_NULLPTR, const Vec3f *colorArray=Q_NULLPTR, const Vec3f *normalArray=Q_NULLPTR)
 
void drawFromArray (DrawingMode mode, int count, int offset=0, bool doProj=true, const unsigned short *indices=Q_NULLPTR)
 Draws primitives using vertices from the arrays specified by setArrays() or enabled via enableClientStates(). More...
 
void drawStelVertexArray (const StelVertexArray &arr, bool checkDiscontinuity=true, Vec3d aberration=Vec3d(0.))
 Draws the primitives defined in the StelVertexArray. More...
 

Static Public Member Functions

static StelVertexArray computeSphereNoLight (double radius, double oneMinusOblateness, unsigned int slices, unsigned int stacks, int orientInside=0, bool flipTexture=false, float topAngle=0.0f, float bottomAngle=static_cast< float >(M_PI))
 Generate a StelVertexArray for a sphere. More...
 
static void computeFanDisk (float radius, uint innerFanSlices, uint level, QVector< Vec3d > &vertexArr, QVector< Vec2f > &texCoordArr)
 Draw a disk with a special texturing mode having texture center at center of disk. More...
 
static void initGLShaders ()
 Create the OpenGL shaders programs used by the StelPainter. More...
 
static void deinitGLShaders ()
 Delete the OpenGL shaders objects. More...
 
static bool linkProg (class QOpenGLShaderProgram *prog, const QString &name)
 Link an opengl program and show a message in case of error or warnings. More...
 

Friends

class VertexArrayProjector
 
class StelTextureMgr
 
class StelTexture
 

Detailed Description

Provides functions for performing openGL drawing operations.

All coordinates are converted using the StelProjector instance passed at construction. Because openGL is not thread safe, only one instance of StelPainter can exist at a time, enforcing thread safety. As a coding rule, no openGL calls should be performed when no instance of StelPainter exist. Typical usage is to create a local instance of StelPainter where drawing operations are needed.

Member Enumeration Documentation

◆ DrawingMode

Define the drawing mode when drawing vertex.

Enumerator
Points 

GL_POINTS.

Lines 

GL_LINES.

LineLoop 

GL_LINE_LOOP.

LineStrip 

GL_LINE_STRIP.

Triangles 

GL_TRIANGLES.

TriangleStrip 

GL_TRIANGLE_STRIP.

TriangleFan 

GL_TRIANGLE_FAN.

◆ SphericalPolygonDrawMode

Define the drawing mode when drawing polygons.

Enumerator
SphericalPolygonDrawModeFill 

Draw the interior of the polygon.

SphericalPolygonDrawModeBoundary 

Draw the boundary of the polygon.

SphericalPolygonDrawModeTextureFill 

Draw the interior of the polygon filled with the current texture.

SphericalPolygonDrawModeTextureFillColormodulated 

Draw the interior of the polygon filled with the current texture multiplied by vertex colors.

Member Function Documentation

◆ computeFanDisk()

static void StelPainter::computeFanDisk ( float  radius,
uint  innerFanSlices,
uint  level,
QVector< Vec3d > &  vertexArr,
QVector< Vec2f > &  texCoordArr 
)
static

Draw a disk with a special texturing mode having texture center at center of disk.

The disk is made up of concentric circles with increasing refinement. The number of slices of the outmost circle is (innerFanSlices<<level).

Parameters
radiusthe radius of the disk.
innerFanSlicesthe number of slices.
levelthe number of concentric circles.
vertexArrthe vertex array in which the resulting vertices are returned.
texCoordArrthe vertex array in which the resulting texture coordinates are returned.

◆ computeSphereNoLight()

static StelVertexArray StelPainter::computeSphereNoLight ( double  radius,
double  oneMinusOblateness,
unsigned int  slices,
unsigned int  stacks,
int  orientInside = 0,
bool  flipTexture = false,
float  topAngle = 0.0f,
float  bottomAngle = static_cast< float >(M_PI) 
)
static

Generate a StelVertexArray for a sphere.

Parameters
radius
oneMinusOblateness
slicesnumber of vertical segments ("meridian zones")
stacksnumber of horizontal segments ("latitude zones")
orientInside1 to have normals point inside, e.g. for Milky Way, Zodiacal Light, etc.
flipTextureif texture should be mapped to inside of sphere, e.g. Milky Way.
topAngleAn opening angle [radians] at top of the sphere. Useful if there is an empty region around the top pole, like North Galactic Pole.
bottomAngleAn opening angle [radians] at bottom of the sphere. Useful if there is an empty region around the bottom pole, like South Galactic Pole.

◆ deinitGLShaders()

static void StelPainter::deinitGLShaders ( )
static

Delete the OpenGL shaders objects.

This method needs to be called once before exit.

◆ drawEllipse()

void StelPainter::drawEllipse ( double  x,
double  y,
double  rx,
double  ry,
double  angle 
)

Draw a simple ellipse, 2d viewport coordinates in pixel.

Parameters
rxradius in x axis
ryradius in y axis
anglerotation (counterclockwise), radians [0..2pi]

◆ drawFromArray()

void StelPainter::drawFromArray ( DrawingMode  mode,
int  count,
int  offset = 0,
bool  doProj = true,
const unsigned short *  indices = Q_NULLPTR 
)

Draws primitives using vertices from the arrays specified by setArrays() or enabled via enableClientStates().

Parameters
modeThe type of primitive to draw. If
indicesis Q_NULLPTR, this operation will consume
countvalues from the enabled arrays, starting at
offset.Else it will consume
countelements of
indices,startingat
offset,whichare used to index into the enabled arrays. NOTE: Prefer to use drawStelVertexArray, else there are wrap-around rendering artifacts in a few projections.

◆ drawGreatCircleArc()

void StelPainter::drawGreatCircleArc ( const Vec3d start,
const Vec3d stop,
const SphericalCap clippingCap = Q_NULLPTR,
void(*)(const Vec3d &screenPos, const Vec3d &direction, void *userData)  viewportEdgeIntersectCallback = Q_NULLPTR,
void *  userData = Q_NULLPTR 
)

Draw a great circle arc between points start and stop.

The angle between start and stop must be < 180 deg. The algorithm ensures that the line will look smooth, even for non linear distortion. Each time the great circle crosses the edge of the viewport, the viewportEdgeIntersectCallback is called with the screen 2d position, direction of the currently drawn arc toward the inside of the viewport.

Parameters
clippingCapif not set to Q_NULLPTR, tells the painter to try to clip part of the region outside the cap.

◆ drawLine2d()

void StelPainter::drawLine2d ( float  x1,
float  y1,
float  x2,
float  y2 
)

Draw a line between the 2 points.

Parameters
x1x position of point 1 in the viewport in pixels. 0 is at left.
y1y position of point 1 in the viewport in pixels. 0 is at bottom.
x2x position of point 2 in the viewport in pixels. 0 is at left.
y2y position of point 2 in the viewport in pixels. 0 is at bottom.

◆ drawPath()

void StelPainter::drawPath ( const QVector< Vec3d > &  points,
const QVector< Vec4f > &  colors 
)

Draw a curve defined by a list of points.

The points should be already tesselated to ensure that the path will look smooth. The algorithm takes care of cutting the path if it crosses a viewport discontinuity.

◆ drawPoint2d()

void StelPainter::drawPoint2d ( float  x,
float  y 
)

Draw a GL_POINT at the given position.

Parameters
xx position in the viewport in pixels.
yy position in the viewport in pixels.

◆ drawRect2d()

void StelPainter::drawRect2d ( float  x,
float  y,
float  width,
float  height,
bool  textured = true 
)

Draw a rectangle using the current texture at the given projected 2d position.

This method is not thread safe.

Parameters
xx position of the top left corner in the viewport in pixel.
yy position of the tope left corner in the viewport in pixel.
widthwidth in pixel.
heightheight in pixel.
texturedwhether the current texture should be used for painting.

◆ drawSmallCircleArc()

void StelPainter::drawSmallCircleArc ( const Vec3d start,
const Vec3d stop,
const Vec3d rotCenter,
void(*)(const Vec3d &screenPos, const Vec3d &direction, void *userData)  viewportEdgeIntersectCallback = Q_NULLPTR,
void *  userData = Q_NULLPTR 
)

Draw a small circle arc between points start and stop with rotation point in rotCenter.

The angle between start and stop must be < 180 deg. The algorithm ensures that the line will look smooth, even for non linear distortion. Each time the small circle crosses the edge of the viewport, the viewportEdgeIntersectCallback is called with the screen 2d position, direction of the currently drawn arc toward the inside of the viewport. Example: A latitude circle has 0/0/sin(latitude) as rotCenter. If rotCenter is equal to 0,0,0, the method draws a great circle.

◆ drawSphericalRegion()

void StelPainter::drawSphericalRegion ( SphericalRegion region,
SphericalPolygonDrawMode  drawMode = SphericalPolygonDrawModeFill,
const SphericalCap clippingCap = Q_NULLPTR,
bool  doSubDivise = true,
double  maxSqDistortion = 5.,
const Vec3d observerVelocity = Vec3d(0.) 
)

Draw the given SphericalRegion.

Parameters
regionThe SphericalRegion to draw. If observerVelocity is given, it will be modified.
drawModedefine whether to draw the outline or the fill or both.
clippingCapif not set to Q_NULLPTR, tells the painter to try to clip part of the region outside the cap.
doSubDiviseif true tesselates the object to follow projection distortions. Typically set that to false if you think that the region is fully contained in the viewport.
observerVelocityprecomputed vector shift for aberration correction

◆ drawSprite2dMode() [1/2]

void StelPainter::drawSprite2dMode ( float  x,
float  y,
float  radius 
)

Draw a square using the current texture at the given projected 2d position.

This method is not thread safe.

Parameters
xx position in the viewport in pixel.
yy position in the viewport in pixel.
radiusthe half size of a square side in pixel.
vdirection vector of object to draw. Will draw only if this is in the visible hemisphere.

◆ drawSprite2dMode() [2/2]

void StelPainter::drawSprite2dMode ( float  x,
float  y,
float  radius,
float  rotation 
)

Draw a rotated square using the current texture at the given projected 2d position.

This method is not thread safe.

Parameters
xx position in the viewport in pixel.
yy position in the viewport in pixel.
radiusthe half size of a square side in pixel.
rotationrotation angle in degree.

◆ drawStelVertexArray()

void StelPainter::drawStelVertexArray ( const StelVertexArray arr,
bool  checkDiscontinuity = true,
Vec3d  aberration = Vec3d(0.) 
)

Draws the primitives defined in the StelVertexArray.

Parameters
checkDiscontinuitywill check and suppress discontinuities if necessary.
aberrationa vector which moves all vertices according to aberration effects. The vector must be transformed to the frame used in the array.

◆ drawText()

void StelPainter::drawText ( float  x,
float  y,
const QString &  str,
float  angleDeg = 0.f,
float  xshift = 0.f,
float  yshift = 0.f,
bool  noGravity = true 
)

Draw the string at the given position and angle with the given font.

If the gravity label flag is set, uses drawTextGravity180.

Parameters
xhorizontal position of the lower left corner of the first character of the text in pixel.
yvertical position of the lower left corner of the first character of the text in pixel.
strthe text to print.
angleDegrotation angle in degree. Rotation is around x,y.
xshiftshift in pixel in the rotated x direction.
yshiftshift in pixel in the rotated y direction.
noGravitydon't take into account the fact that the text should be written with gravity.
vdirection vector of object to draw. GZ20120826: Will draw only if this is in the visible hemisphere.

◆ glFuncs()

QOpenGLFunctions* StelPainter::glFuncs ( )
inline

Returns a QOpenGLFunctions object suitable for drawing directly with OpenGL while this StelPainter is active.

This is recommended to be used instead of QOpenGLContext::currentContext()->functions() when a StelPainter is available, and you only need to call a few GL functions directly.

◆ initGLShaders()

static void StelPainter::initGLShaders ( )
static

Create the OpenGL shaders programs used by the StelPainter.

This method needs to be called once at init.

◆ linkProg()

static bool StelPainter::linkProg ( class QOpenGLShaderProgram *  prog,
const QString &  name 
)
static

Link an opengl program and show a message in case of error or warnings.

Returns
true if the link was successful.

◆ setArrays()

void StelPainter::setArrays ( const Vec3d vertices,
const Vec2f texCoords = Q_NULLPTR,
const Vec3f colorArray = Q_NULLPTR,
const Vec3f normalArray = Q_NULLPTR 
)

convenience method that enable and set all the given arrays.

It is equivalent to calling enableClientStates() and set the array pointer for each array.

◆ setBlending()

void StelPainter::setBlending ( bool  enableBlending,
GLenum  blendSrc = GL_SRC_ALPHA,
GLenum  blendDst = GL_ONE_MINUS_SRC_ALPHA 
)

Enable OpenGL blending.

By default, blending is disabled. The additional parameters specify the blending mode, the default parameters are suitable for "normal" blending operations that you want in most cases. Blending will be automatically disabled when the StelPainter is destroyed.