20 #ifndef OMNI_VISUAL_UTIL_H_
21 #define OMNI_VISUAL_UTIL_H_
29 #include <QOpenGLFunctions>
34 class QOpenGLShaderProgram;
46 for (
size_t i = 0; i < _numVertices; ++i)
48 float _m = 2.0 * M_PI * float(i) / _numVertices;
49 float _cos = cos(_m), _sin = sin(_m);
50 _f(i, QPointF(_cos * _radius, _sin * _radius));
69 float _cos = cos(_beginAngle), _sin = sin(_beginAngle);
72 _f(0, QPointF(_cos * _radius, _sin * _radius));
74 for (; i < _numVertices; ++i)
76 float _m = _beginAngle + float(i) / _numVertices *
77 (_endAngle - _beginAngle);
78 _cos = cos(_m), _sin = sin(_m);
79 _f(i, QPointF(_cos * _radius, _sin * _radius));
81 _cos = cos(_endAngle), _sin = sin(_endAngle);
82 _f(i, QPointF(_cos * _radius, _sin * _radius));
87 template<
typename SIZE>
90 return _size.width() / qreal(_size.height());
102 template<
typename FRAMEBUFFER,
typename PROJECTION,
typename MODELVIEW>
107 _.glViewport(0, 0, _f->width(), _f->height());
111 glMatrixMode(GL_TEXTURE);
115 glMatrixMode(GL_PROJECTION);
120 glMatrixMode(GL_MODELVIEW);
130 template<
typename WIDGET>
135 int d = _widget->devicePixelRatio();
136 _.glViewport(0, 0, _widget->width() * d, _widget->height() * d);
void draw_on_framebuffer(FRAMEBUFFER *_f, PROJECTION _p, MODELVIEW _m)
Draw into QOpenGLFramebufferObject with given projection and model.
Definition: util.h:103
void resetOpenGLState()
Reset openGL state to its defaults.
Definition: util.cpp:86
void for_each_arc_point(size_t _numVertices, float _radius, float _beginAngle, float _endAngle, F _f)
Definition: util.h:63
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
qreal aspect(SIZE const &_size)
Calculates the aspect ratio from a QSize.
Definition: util.h:88
QRectF viewRect(int _imageWidth, int _imageHeight, int _canvasWidth, int _canvasHeight, float _border)
Calculate view rectangle on 2D OpenGL surface.
Definition: util.cpp:60
void for_each_circle_point(size_t _numVertices, float _radius, F _f)
Definition: util.h:44
double now()
Get current time in nano seconds.
Definition: util.cpp:33
void checkOpenGLError()
Convenience function for handling glGetError()
Definition: util.cpp:39
void viewport(WIDGET *_widget)
Set viewport for widget.
Definition: util.h:131