20 #ifndef _STELPAINTER_HPP_ 21 #define _STELPAINTER_HPP_ 23 #include "StelOpenGL.hpp" 24 #include "VecMath.hpp" 27 #include "StelProjector.hpp" 29 #include <QVarLengthArray> 30 #include <QFontMetrics> 32 class QOpenGLShaderProgram;
43 friend class VertexArrayProjector;
72 inline QOpenGLFunctions*
glFuncs() {
return this; }
91 void drawText(
float x,
float y,
const QString& str,
float angleDeg=0.f,
92 float xshift=0.f,
float yshift=0.f,
bool noGravity=
true);
93 void drawText(
const Vec3d& v,
const QString& str,
float angleDeg=0.f,
94 float xshift=0.f,
float yshift=0.f,
bool noGravity=
true);
106 void drawSphericalTriangles(
const StelVertexArray& va,
bool textured,
bool colored,
const SphericalCap* clippingCap=NULL,
bool doSubDivide=
true,
double maxSqDistortion=5.);
115 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);
128 void drawPath(
const QVector<Vec3d> &points,
const QVector<Vec4f> &colors);
163 void drawLine2d(
float x1,
float y1,
float x2,
float y2);
172 void drawRect2d(
float x,
float y,
float width,
float height,
bool textured=
true);
189 void sSphere(
float radius,
float oneMinusOblateness,
int slices,
int stacks,
int orientInside = 0,
bool flipTexture =
false,
190 float topAngle=0.0f,
float bottomAngle=M_PI);
204 int orientInside = 0,
bool flipTexture =
false,
205 float topAngle=0.0f,
float bottomAngle=M_PI);
208 void sCylinder(
float radius,
float height,
int slices,
int orientInside = 0);
218 static void computeFanDisk(
float radius,
int innerFanSlices,
int level, QVector<double>& vertexArr, QVector<float>& texCoordArr);
221 void sSphereMap(
float radius,
int slices,
int stacks,
float textureFov = 2.f*M_PI,
int orientInside = 0);
224 void setFont(
const QFont& font);
227 void setColor(
float r,
float g,
float b,
float a=1.f);
239 void setBlending(
bool enableBlending, GLenum blendSrc = GL_SRC_ALPHA, GLenum blendDst = GL_ONE_MINUS_SRC_ALPHA);
241 void setDepthTest(
bool enable);
243 void setDepthMask(
bool enable);
265 vertexArray.size = size; vertexArray.type = type; vertexArray.pointer = pointer;
271 texCoordArray.size = size; texCoordArray.type = type; texCoordArray.pointer = pointer;
277 colorArray.size = size; colorArray.type = type; colorArray.pointer = pointer;
283 normalArray.size = 3; normalArray.type = type; normalArray.pointer = pointer;
287 void enableClientStates(
bool vertex,
bool texture=
false,
bool color=
false,
bool normal=
false);
299 void drawFromArray(
DrawingMode mode,
int count,
int offset=0,
bool doProj=
true,
const unsigned short *indices=NULL);
307 static bool linkProg(
class QOpenGLShaderProgram* prog,
const QString& name);
317 GLState(QOpenGLFunctions *gl);
320 GLenum blendSrc, blendDst;
333 QOpenGLFunctions* gl;
337 static QCache<QByteArray, struct StringTexture> texCache;
338 struct StringTexture* getTexTexture(
const QString& str,
int pixelSize);
341 typedef struct ArrayDesc
343 ArrayDesc() : size(0), type(0), pointer(NULL), enabled(
false) {}
352 ArrayDesc projectArray(
const ArrayDesc& array,
int offset,
int count,
const unsigned short *indices=NULL);
361 void projectSphericalTriangle(
const SphericalCap* clippingCap,
const Vec3d* vertices, QVarLengthArray<Vec3f, 4096>* outVertices,
362 const Vec2f* texturePos=NULL, QVarLengthArray<Vec2f, 4096>* outTexturePos=NULL,
363 const Vec3f* colors=NULL, QVarLengthArray<Vec3f, 4096>* outColors=NULL,
364 double maxSqDistortion=5.,
int nbI=0,
365 bool checkDisc1=
true,
bool checkDisc2=
true,
bool checkDisc3=
true)
const;
367 void drawTextGravity180(
float x,
float y,
const QString& str,
float xshift = 0,
float yshift = 0);
370 static QVector<Vec2f> smallCircleVertexArray;
371 static QVector<Vec4f> smallCircleColorArray;
372 void drawSmallCircleVertexArray();
378 static class QMutex* globalMutex;
387 static QOpenGLShaderProgram* basicShaderProgram;
388 struct BasicShaderVars {
389 int projectionMatrix;
393 static BasicShaderVars basicShaderVars;
395 static QOpenGLShaderProgram* colorShaderProgram;
396 static BasicShaderVars colorShaderVars;
398 static QOpenGLShaderProgram* texturesShaderProgram;
399 struct TexturesShaderVars {
400 int projectionMatrix;
406 static TexturesShaderVars texturesShaderVars;
407 static QOpenGLShaderProgram* texturesColorShaderProgram;
408 struct TexturesColorShaderVars {
409 int projectionMatrix;
415 static TexturesColorShaderVars texturesColorShaderVars;
419 ArrayDesc vertexArray;
421 ArrayDesc texCoordArray;
423 ArrayDesc normalArray;
425 ArrayDesc colorArray;
428 #endif // _STELPAINTER_HPP_ void drawCircle(float x, float y, float r)
Draw a simple circle, 2d viewport coordinates in pixel.
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.
void setBlending(bool enableBlending, GLenum blendSrc=GL_SRC_ALPHA, GLenum blendDst=GL_ONE_MINUS_SRC_ALPHA)
Enable OpenGL blending.
void setTexCoordPointer(int size, int type, const void *pointer)
use instead of glTexCoordPointer
void sCylinder(float radius, float height, int slices, int orientInside=0)
Re-implementation of gluCylinder : glu is overridden for non-standard projection. ...
static void deinitGLShaders()
Delete the OpenGL shaders objects.
void setLineSmooth(bool enable)
Enables/disables line smoothing. By default, smoothing is disabled.
Vec4f getColor() const
Get the color currently used for drawing.
void setCullFace(bool enable)
Set the OpenGL GL_CULL_FACE state, by default face culling is disabled.
Draw the interior of the polygon filled with the current texture multiplied by vertex colors...
void drawSprite2dMode(float x, float y, float radius)
Draw a square using the current texture at the given projected 2d position.
A SphericalCap is defined by a direction and an aperture.
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 enableClientStates(bool vertex, bool texture=false, bool color=false, bool normal=false)
Simulates glEnableClientState, basically you describe what data the ::drawFromArray call has availabl...
void setColor(float r, float g, float b, float a=1.f)
Set the color to use for subsequent drawing.
void drawPath(const QVector< Vec3d > &points, const QVector< Vec4f > &colors)
Draw a curve defined by a list of points.
Draw the interior of the polygon filled with the current texture.
void setColorPointer(int size, int type, const void *pointer)
use instead of glColorPointer
static void initGLShaders()
Create the OpenGL shaders programs used by the StelPainter.
QOpenGLFunctions * glFuncs()
Returns a QOpenGLFunctions object suitable for drawing directly with OpenGL while this StelPainter is...
void drawSphericalRegion(const SphericalRegion *region, SphericalPolygonDrawMode drawMode=SphericalPolygonDrawModeFill, const SphericalCap *clippingCap=NULL, bool doSubDivise=true, double maxSqDistortion=5.)
Draw the given SphericalRegion.
const StelProjectorP & getProjector() const
Return the instance of projector associated to this painter.
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.
QSharedPointer< StelProjector > StelProjectorP
Shared pointer on a StelProjector instance (implement reference counting)
static StelVertexArray computeSphereNoLight(float radius, float oneMinusOblateness, int slices, int stacks, int orientInside=0, bool flipTexture=false, float topAngle=0.0f, float bottomAngle=M_PI)
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.
Draw the interior of the polygon.
Provides functions for performing openGL drawing operations.
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.
A templatized 4d vector compatible with openGL.
void drawStelVertexArray(const StelVertexArray &arr, bool checkDiscontinuity=true)
Draws the primitives defined in the StelVertexArray.
void drawFromArray(DrawingMode mode, int count, int offset=0, bool doProj=true, const unsigned short *indices=NULL)
Draws primitives using vertices from the arrays specified by setVertexArray().
SphericalPolygonDrawMode
Define the drawing mode when drawing polygons.
void setNormalPointer(int type, const void *pointer)
use instead of glNormalPointer
void setVertexPointer(int size, int type, const void *pointer)
use instead of glVertexPointer
Abstract class defining a region of the sphere.
void drawViewportShape(void)
Fill with black around the viewport.
void setFont(const QFont &font)
Set the font to use for subsequent text drawing.
void drawSprite2dModeNoDeviceScale(float x, float y, float radius)
Same as drawSprite2dMode but don't scale according to display device scaling.
void setLineWidth(float width)
Sets the line width. Default is 1.0f.
Define the StelProjectorP type.
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.
Draw the boundary of the polygon.
QFontMetrics getFontMetrics() const
Get the font metrics for the current font.
static bool linkProg(class QOpenGLShaderProgram *prog, const QString &name)
Link an opengl program and show a message in case of error or warnings.
Define all SphericalGeometry primitives as well as the SphericalRegionP type.
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 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.
DrawingMode
Define the drawing mode when drawing vertex.