Stellarium 0.11.4
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 }
 

Define the drawing mode when drawing polygons.

More...
enum  ShadeModel { ShadeModelFlat = 0x1D00, ShadeModelSmooth = 0x1D01 }
 

Define the shade model when interpolating 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.
void setProjector (const StelProjectorP &p)
void drawViewportShape ()
 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.
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.)
 Draw the given SphericalRegion.
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)
 Draw a small circle arc between points start and stop with rotation point in rotCenter.
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.
void drawCircle (float x, float y, float r)
 Draw a simple circle, 2d viewport coordinates in pixel.
void drawSprite2dMode (float x, float y, float radius)
 Draw a square using the current texture at the given projected 2d position.
void drawSprite2dMode (const Vec3d &v, float radius)
void drawSprite2dMode (float x, float y, float radius, float rotation)
 Draw a rotated square using the current texture at the given projected 2d position.
void drawPoint2d (float x, float y)
 Draw a GL_POINT at the given position.
void drawLine2d (float x1, float y1, float x2, float y2)
 Draw a line between the 2 points.
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.
void sSphere (float radius, float oneMinusOblateness, int slices, int stacks, int orientInside=0, bool flipTexture=false)
 Re-implementation of gluSphere : glu is overridden for non-standard projection.
void sCylinder (float radius, float height, int slices, int orientInside=0)
 Re-implementation of gluCylinder : glu is overridden for non-standard projection.
void sRing (float rMin, float rMax, int slices, int stacks, int orientInside)
 Draw a ring with a radial texturing.
void sSphereMap (float radius, int slices, int stacks, float textureFov=2.f *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.
Vec4f getColor () const
 Get the color currently used for drawing.
StelPainterLightgetLight ()
 Get the light.
StelPainterMaterialgetMaterial ()
 Get the material.
QFontMetrics getFontMetrics () const
 Get the font metrics for the current font.
void setPointSize (qreal size)
 Sets the point size to use with draw().
void setShadeModel (ShadeModel m)
 Define the current shade model used when interpolating between vertex.
void enableTexture2d (bool b)
 Set whether texturing is enabled.
void setVertexPointer (int size, int type, const void *pointer)
 use instead of glVertexPointer
void setTexCoordPointer (int size, int type, const void *pointer)
 use instead of glTexCoordPointer
void setColorPointer (int size, int type, const void *pointer)
 use instead of glColorPointer
void setNormalPointer (int type, const void *pointer)
 use instead of glNormalPointer
void enableClientStates (bool vertex, bool texture=false, bool color=false, bool normal=false)
 use instead of glEnableClient
void 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.
void 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().
void drawStelVertexArray (const StelVertexArray &arr, bool checkDiscontinuity=true)
 Draws the primitives defined in the StelVertexArray.

Static Public Member Functions

static StelVertexArray computeSphereNoLight (float radius, float oneMinusOblateness, int slices, int stacks, int orientInside=0, bool flipTexture=false)
 Generate a StelVertexArray for a sphere.
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.
static void initSystemGLInfo (QGLContext *ctx)
 Get some informations about the OS openGL capacities and set the GLContext which will be used by Stellarium.
static void setQPainter (QPainter *qPainter)
 Set the QPainter to use for performing some drawing operations.
static void swapBuffer ()
 Swap the OpenGL buffers. You normally don't need to do that.
static void makeMainGLContextCurrent ()
 Make sure that our GL context is current and valid.

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.
static StelVertexArray StelPainter::computeSphereNoLight ( float  radius,
float  oneMinusOblateness,
int  slices,
int  stacks,
int  orientInside = 0,
bool  flipTexture = false 
) [static]

Generate a StelVertexArray for a sphere.

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

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

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.
void StelPainter::drawViewportShape (  ) 

Fill with black around the viewport.

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

use instead of glEnableClient

void StelPainter::enableTexture2d ( 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.

StelPainterMaterial& StelPainter::getMaterial (  )  [inline]

Get the material.

const StelProjectorP& StelPainter::getProjector (  )  const [inline]

Return the instance of projector associated to this painter.

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.

static void StelPainter::makeMainGLContextCurrent (  )  [static]

Make sure that our GL context is current and valid.

void StelPainter::sCylinder ( float  radius,
float  height,
int  slices,
int  orientInside = 0 
)

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

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::setColor ( float  r,
float  g,
float  b,
float  a = 1.f 
)

Set the color to use for subsequent drawing.

void StelPainter::setColorPointer ( int  size,
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 ( int  type,
const void *  pointer 
) [inline]

use instead of glNormalPointer

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.

static void StelPainter::setQPainter ( QPainter *  qPainter  )  [static]

Set the QPainter to use for performing some drawing operations.

void StelPainter::setShadeModel ( ShadeModel  m  ) 

Define the current shade model used when interpolating between vertex.

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

use instead of glTexCoordPointer

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

use instead of glVertexPointer

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

Draw a ring with a radial texturing.

void StelPainter::sSphere ( float  radius,
float  oneMinusOblateness,
int  slices,
int  stacks,
int  orientInside = 0,
bool  flipTexture = false 
)

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

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

Draw a fisheye texture in a sphere.

static void StelPainter::swapBuffer (  )  [static]

Swap the OpenGL buffers. You normally don't need to do that.

Generated on Sat Aug 25 22:13:33 2012 for Stellarium by  doxygen 1.6.3