Stellarium 0.11.3
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

StelPainter Class Reference

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

#include <StelPainter.hpp>

List of all members.

Classes

struct  ArrayDesc
 Struct describing one opengl array.

Public Types

enum  SphericalPolygonDrawMode { SphericalPolygonDrawModeFill = 0, SphericalPolygonDrawModeBoundary = 1, SphericalPolygonDrawModeTextureFill = 2 }
enum  ShadeModel { ShadeModelFlat = 0x1D00, ShadeModelSmooth = 0x1D01 }
enum  DrawingMode {
  Points = 0x0000, Lines = 0x0001, LineLoop = 0x0002, LineStrip = 0x0003,
  Triangles = 0x0004, TriangleStrip = 0x0005, TriangleFan = 0x0006
}

Public Member Functions

 StelPainter (const StelProjectorP &prj)
const StelProjectorPgetProjector () const
void setProjector (const StelProjectorP &p)
void drawViewportShape ()
void drawText (float x, float y, const QString &str, float angleDeg=0.f, float xshift=0.f, float yshift=0.f, bool noGravity=true)
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 (const SphericalRegion *region, SphericalPolygonDrawMode drawMode=SphericalPolygonDrawModeFill, const SphericalCap *clippingCap=NULL, bool doSubDivise=true, double maxSqDistortion=5.)
void drawGreatCircleArcs (const StelVertexArray &va, const SphericalCap *clippingCap=NULL)
void drawSphericalTriangles (const StelVertexArray &va, bool textured, const SphericalCap *clippingCap=NULL, 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)=NULL, void *userData=NULL)
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)
void drawCircle (float x, float y, float r)
void drawSprite2dMode (float x, float y, float radius)
void drawSprite2dMode (const Vec3d &v, float radius)
void drawSprite2dMode (float x, float y, float radius, float rotation)
void drawPoint2d (float x, float y)
void drawLine2d (float x1, float y1, float x2, float y2)
void drawRect2d (float x, float y, float width, float height, bool textured=true)
void sSphere (float radius, float oneMinusOblateness, int slices, int stacks, int orientInside=0, bool flipTexture=false)
void sCylinder (float radius, float height, int slices, int orientInside=0)
void sRing (float rMin, float rMax, int slices, int stacks, int orientInside)
void sSphereMap (float radius, int slices, int stacks, float textureFov=2.f *M_PI, int orientInside=0)
void setFont (const QFont &font)
void setColor (float r, float g, float b, float a=1.f)
Vec4f getColor () const
StelPainterLightgetLight ()
StelPainterMaterialgetMaterial ()
QFontMetrics getFontMetrics () const
void setPointSize (qreal size)
void setShadeModel (ShadeModel m)
void enableTexture2d (bool b)
void setVertexPointer (int size, int type, const void *pointer)
void setTexCoordPointer (int size, int type, const void *pointer)
void setColorPointer (int size, int type, const void *pointer)
void setNormalPointer (int type, const void *pointer)
void enableClientStates (bool vertex, bool texture=false, bool color=false, bool normal=false)
void setArrays (const Vec3d *vertice, const Vec2f *texCoords=NULL, const Vec3f *colorArray=NULL, const Vec3f *normalArray=NULL)
void drawFromArray (DrawingMode mode, int count, int offset=0, bool doProj=true, const unsigned int *indices=NULL)
void drawStelVertexArray (const StelVertexArray &arr, bool checkDiscontinuity=true)

Static Public Member Functions

static StelVertexArray computeSphereNoLight (float radius, float oneMinusOblateness, int slices, int stacks, int orientInside=0, bool flipTexture=false)
static void computeFanDisk (float radius, int innerFanSlices, int level, QVector< double > &vertexArr, QVector< float > &texCoordArr)
static void initSystemGLInfo (QGLContext *ctx)
static void setQPainter (QPainter *qPainter)
static void swapBuffer ()
static void makeMainGLContextCurrent ()

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 shade model when interpolating polygons.

Enumerator:
ShadeModelFlat 

GL_FLAT.

ShadeModelSmooth 

GL_SMOOTH.

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:
radius the radius of the disk.
innerFanSlices the number of slices.
level the numbe of concentric circles.
vertexArr the vertex array in which the resulting vertices are returned.
texCoordArr the vertex array in which the resulting texture coordinates are returned.
void StelPainter::drawFromArray ( DrawingMode  mode,
int  count,
int  offset = 0,
bool  doProj = true,
const unsigned int *  indices = NULL 
)

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

The type of primitive to draw is specified by mode. If indices is NULL, this operation will consume count values from the enabled arrays, starting at offset. Else it will consume count elements of indices, starting at offset, which are 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:
clippingCap if not set to NULL, tells the painter to try to clip part of the region outside the cap.
void StelPainter::drawLine2d ( float  x1,
float  y1,
float  x2,
float  y2 
)

Draw a line between the 2 points.

Parameters:
x1 x position of point 1 in the viewport in pixels.
y1 y position of point 1 in the viewport in pixels.
x2 x position of point 2 in the viewport in pixels.
y2 y position of point 2 in the viewport in pixels.
void StelPainter::drawPoint2d ( float  x,
float  y 
)

Draw a GL_POINT at the given position.

Parameters:
x x position in the viewport in pixels.
y y position in the viewport in pixels.
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:
x x position of the top left corner in the viewport in pixel.
y y position of the tope left corner in the viewport in pixel.
width width in pixel.
height height in pixel.
textured whether 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:
region The SphericalRegion to draw.
drawMode define whether to draw the outline or the fill or both.
clippingCap if not set to NULL, tells the painter to try to clip part of the region outside the cap.
doSubDivise if 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 ( 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:
x x position in the viewport in pixel.
y y position in the viewport in pixel.
radius the half size of a square side in pixel.
rotation rotation angle in degree.
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:
x x position in the viewport in pixel.
y y position in the viewport in pixel.
radius the half size of a square side in pixel.
void StelPainter::drawStelVertexArray ( const StelVertexArray arr,
bool  checkDiscontinuity = true 
)

Draws the primitives defined in the StelVertexArray.

Parameters:
checkDiscontinuity will 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,
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:
x horizontal position of the lower left corner of the first character of the text in pixel.
y horizontal position of the lower left corner of the first character of the text in pixel.
str the text to print.
angleDeg rotation angle in degree. Rotation is around x,y.
xshift shift in pixel in the rotated x direction.
yshift shift in pixel in the rotated y direction.
noGravity don't take into account the fact that the text should be written with gravity.
static void StelPainter::initSystemGLInfo ( QGLContext *  ctx  )  [static]

Get some informations about the OS openGL capacities and set the GLContext which will be used by Stellarium.

This method needs to be called once at init.

void StelPainter::setArrays ( const Vec3d vertice,
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::setPointSize ( qreal  size  ) 

Sets the point size to use with draw().

This function has no effect if a shader program is in use, or on OpenGL/ES 2.0. Shader programs must set the point size in the vertex shader.

Generated on Thu May 31 10:37:22 2012 for Stellarium by  doxygen 1.6.3