Stellarium 0.13.0
List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions
StelPainter Class Reference

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

#include <StelPainter.hpp>

Public Types

enum  SphericalPolygonDrawMode { SphericalPolygonDrawModeFill =0, SphericalPolygonDrawModeBoundary =1, SphericalPolygonDrawModeTextureFill =2 }
 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)
 
const StelProjectorPgetProjector () const
 Return the instance of projector associated to this painter. More...
 
void setProjector (const StelProjectorP &p)
 
void drawViewportShape ()
 Fill with black around the viewport. More...
 
void drawText (float x, float y, const QString &str, float angleDeg=0.f, float xshift=0.f, float yshift=0.f, const 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, const float angleDeg=0.f, const float xshift=0.f, const float yshift=0.f, const bool noGravity=true)
 
void drawSphericalRegion (const SphericalRegion *region, SphericalPolygonDrawMode drawMode=SphericalPolygonDrawModeFill, const SphericalCap *clippingCap=NULL, bool doSubDivise=true, double maxSqDistortion=5.)
 Draw the given SphericalRegion. More...
 
void drawGreatCircleArcs (const StelVertexArray &va, const SphericalCap *clippingCap=NULL)
 
void drawSphericalTriangles (const StelVertexArray &va, const bool textured, const SphericalCap *clippingCap=NULL, const bool doSubDivide=true, const double maxSqDistortion=5.)
 
void drawSmallCircleArc (const Vec3d &start, const Vec3d &stop, const Vec3d &rotCenter, void(*viewportEdgeIntersectCallback)(const Vec3d &screenPos, const Vec3d &direction, void *userData)=NULL, void *userData=NULL)
 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=NULL, void(*viewportEdgeIntersectCallback)(const Vec3d &screenPos, const Vec3d &direction, void *userData)=NULL, void *userData=NULL)
 Draw a great circle arc between points start and stop. More...
 
void drawCircle (const float x, const float y, float r)
 Draw a simple circle, 2d viewport coordinates in pixel. More...
 
void drawSprite2dMode (const float x, const float y, float radius)
 Draw a square using the current texture at the given projected 2d position. More...
 
void drawSprite2dMode (const Vec3d &v, const float radius)
 
void drawSprite2dModeNoDeviceScale (const float x, const float y, const float radius)
 Same as drawSprite2dMode but don't scale according to display device scaling. More...
 
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 (const float x, const float y)
 Draw a GL_POINT at the given position. More...
 
void drawLine2d (const float x1, const float y1, const float x2, const float y2)
 Draw a line between the 2 points. More...
 
void drawRect2d (const float x, const float y, const float width, const float height, const bool textured=true)
 Draw a rectangle using the current texture at the given projected 2d position. More...
 
void sSphere (const float radius, const float oneMinusOblateness, const int slices, const int stacks, const int orientInside=0, const bool flipTexture=false, const float topAngle=0.0f, const float bottomAngle=M_PI)
 
void sCylinder (const float radius, const float height, const int slices, const int orientInside=0)
 Re-implementation of gluCylinder : glu is overridden for non-standard projection. More...
 
void sRing (const float rMin, const float rMax, int slices, const int stacks, const int orientInside)
 Draw a ring with a radial texturing. More...
 
void sSphereMap (const float radius, const int slices, const int stacks, const float textureFov=2.f *M_PI, const int orientInside=0)
 Draw a fisheye texture in a sphere. More...
 
void setFont (const QFont &font)
 Set the font to use for subsequent text drawing. More...
 
void setColor (float r, float g, float b, float a=1.f)
 Set the color to use for subsequent drawing. More...
 
Vec4f getColor () const
 Get the color currently used for drawing. More...
 
StelPainterLightgetLight ()
 Get the light. More...
 
QFontMetrics getFontMetrics () const
 Get the font metrics for the current font. More...
 
void enableTexture2d (const bool b)
 Set whether texturing is enabled. More...
 
void setVertexPointer (const int size, const int type, const void *pointer)
 use instead of glVertexPointer More...
 
void setTexCoordPointer (const int size, const int type, const void *pointer)
 use instead of glTexCoordPointer More...
 
void setColorPointer (const int size, const int type, const void *pointer)
 use instead of glColorPointer More...
 
void setNormalPointer (const int type, const void *pointer)
 use instead of glNormalPointer More...
 
void enableClientStates (const bool vertex, const bool texture=false, const bool color=false, const bool normal=false)
 use instead of glEnableClient More...
 
void setArrays (const Vec3d *vertices, const Vec2f *texCoords=NULL, const Vec3f *colorArray=NULL, const Vec3f *normalArray=NULL)
 convenience method that enable and set all the given arrays. More...
 
void setArrays (const Vec3f *vertices, const Vec2f *texCoords=NULL, const Vec3f *colorArray=NULL, const Vec3f *normalArray=NULL)
 
void drawFromArray (const DrawingMode mode, const int count, const int offset=0, const bool doProj=true, const unsigned short *indices=NULL)
 Draws primitives using vertices from the arrays specified by setVertexArray(). More...
 
void drawStelVertexArray (const StelVertexArray &arr, const bool checkDiscontinuity=true)
 Draws the primitives defined in the StelVertexArray. More...
 
void usePlanetShader (bool use)
 Sets whether the special planet shader should be used. More...
 

Static Public Member Functions

static StelVertexArray computeSphereNoLight (const float radius, const float oneMinusOblateness, const int slices, const int stacks, const int orientInside=0, const bool flipTexture=false)
 Generate a StelVertexArray for a sphere. More...
 
static void computeFanDisk (float radius, int innerFanSlices, int level, QVector< double > &vertexArr, QVector< float > &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...
 

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

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.

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.

Member Function Documentation

static void StelPainter::computeFanDisk ( float  radius,
int  innerFanSlices,
int  level,
QVector< double > &  vertexArr,
QVector< float > &  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.
static StelVertexArray StelPainter::computeSphereNoLight ( const float  radius,
const float  oneMinusOblateness,
const int  slices,
const int  stacks,
const int  orientInside = 0,
const bool  flipTexture = false 
)
static

Generate a StelVertexArray for a sphere.

static void StelPainter::deinitGLShaders ( )
static

Delete the OpenGL shaders objects.

This method needs to be called once before exit.

void StelPainter::drawCircle ( const float  x,
const float  y,
float  r 
)

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

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

Draws primitives using vertices from the arrays specified by setVertexArray().

Parameters
modeThe type of primitive to draw. If
indicesis NULL, 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.
void StelPainter::drawGreatCircleArc ( const Vec3d start,
const Vec3d stop,
const SphericalCap clippingCap = NULL,
void(*)(const Vec3d &screenPos, const Vec3d &direction, void *userData)  viewportEdgeIntersectCallback = NULL,
void *  userData = NULL 
)

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 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.

Parameters
clippingCapif not set to NULL, tells the painter to try to clip part of the region outside the cap.
void StelPainter::drawLine2d ( const float  x1,
const float  y1,
const float  x2,
const float  y2 
)

Draw a line between the 2 points.

Parameters
x1x position of point 1 in the viewport in pixels.
y1y position of point 1 in the viewport in pixels.
x2x position of point 2 in the viewport in pixels.
y2y position of point 2 in the viewport in pixels.
void StelPainter::drawPoint2d ( const float  x,
const 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.
void StelPainter::drawRect2d ( const float  x,
const float  y,
const float  width,
const float  height,
const 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.
void StelPainter::drawSmallCircleArc ( const Vec3d start,
const Vec3d stop,
const Vec3d rotCenter,
void(*)(const Vec3d &screenPos, const Vec3d &direction, void *userData)  viewportEdgeIntersectCallback = NULL,
void *  userData = NULL 
)

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. If rotCenter is equal to 0,0,0, the method draws a great circle.

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

Draw the given SphericalRegion.

Parameters
regionThe SphericalRegion to draw.
drawModedefine whether to draw the outline or the fill or both.
clippingCapif not set to NULL, 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.
void StelPainter::drawSprite2dMode ( const float  x,
const 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. GZ20120826: Will draw only if this is in the visible hemisphere.
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.
void StelPainter::drawSprite2dModeNoDeviceScale ( const float  x,
const float  y,
const float  radius 
)

Same as drawSprite2dMode but don't scale according to display device scaling.

void StelPainter::drawStelVertexArray ( const StelVertexArray arr,
const bool  checkDiscontinuity = true 
)

Draws the primitives defined in the StelVertexArray.

Parameters
checkDiscontinuitywill check and suppress discontinuities if necessary.
void StelPainter::drawText ( float  x,
float  y,
const QString &  str,
float  angleDeg = 0.f,
float  xshift = 0.f,
float  yshift = 0.f,
const 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.
yhorizontal 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.
void StelPainter::drawViewportShape ( )

Fill with black around the viewport.

void StelPainter::enableClientStates ( const bool  vertex,
const bool  texture = false,
const bool  color = false,
const bool  normal = false 
)

use instead of glEnableClient

void StelPainter::enableTexture2d ( const bool  b)

Set whether texturing is enabled.

Vec4f StelPainter::getColor ( ) const

Get the color currently used for drawing.

QFontMetrics StelPainter::getFontMetrics ( ) const

Get the font metrics for the current font.

StelPainterLight& StelPainter::getLight ( )
inline

Get the light.

const StelProjectorP& StelPainter::getProjector ( ) const
inline

Return the instance of projector associated to this painter.

static void StelPainter::initGLShaders ( )
static

Create the OpenGL shaders programs used by the StelPainter.

This method needs to be called once at init.

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.
void StelPainter::sCylinder ( const float  radius,
const float  height,
const int  slices,
const int  orientInside = 0 
)

Re-implementation of gluCylinder : glu is overridden for non-standard projection.

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

convenience method that enable and set all the given arrays.

It is equivalent to calling enableClientState and set the array pointer for each arrays.

void StelPainter::setColor ( float  r,
float  g,
float  b,
float  a = 1.f 
)

Set the color to use for subsequent drawing.

void StelPainter::setColorPointer ( const int  size,
const int  type,
const void *  pointer 
)
inline

use instead of glColorPointer

void StelPainter::setFont ( const QFont &  font)

Set the font to use for subsequent text drawing.

void StelPainter::setNormalPointer ( const int  type,
const void *  pointer 
)
inline

use instead of glNormalPointer

void StelPainter::setTexCoordPointer ( const int  size,
const int  type,
const void *  pointer 
)
inline

use instead of glTexCoordPointer

void StelPainter::setVertexPointer ( const int  size,
const int  type,
const void *  pointer 
)
inline

use instead of glVertexPointer

void StelPainter::sRing ( const float  rMin,
const float  rMax,
int  slices,
const int  stacks,
const int  orientInside 
)

Draw a ring with a radial texturing.

void StelPainter::sSphereMap ( const float  radius,
const int  slices,
const int  stacks,
const float  textureFov = 2.f *M_PI,
const int  orientInside = 0 
)

Draw a fisheye texture in a sphere.

void StelPainter::usePlanetShader ( bool  use)

Sets whether the special planet shader should be used.