Go to the documentation of this file.
5 #ifndef GLVERTEX_QT_GLWIDGET_H
6 #define GLVERTEX_QT_GLWIDGET_H
11 #include <QElapsedTimer>
14 #if (QT_VERSION>=QT_VERSION_CHECK(5, 9, 0)) && !defined(LGL_GLES)
15 # define LGL_USE_QOPENGLWIDGET
18 #ifndef LGL_USE_QOPENGLWIDGET
20 # define LGL_QGLWIDGET QGLWidget
22 # include <QOpenGLWidget>
23 # define LGL_QGLWIDGET QOpenGLWidget
34 : LGL_QGLWIDGET(parent),
39 red_(0), green_(0), blue_(0), alpha_(1),
50 setFocusPolicy(Qt::ClickFocus);
52 #if (LGL_OPENGL_VERSION>=30) || defined(LGL_GLES)
53 #ifndef LGL_USE_QOPENGLWIDGET
54 QGLFormat format(QGL::DoubleBuffer | QGL::DepthBuffer);
55 format.setSwapInterval(1);
58 #if (LGL_OPENGL_VERSION >= 30)
59 #if (LGL_OPENGL_VERSION >= 32) && !defined(__APPLE__)
60 format.setVersion(3, 2);
62 format.setVersion(3, 0);
65 format.setVersion(2, 0);
67 #ifndef FORCE_COMPATIBILITY_PROFILE
68 format.setProfile(QGLFormat::CoreProfile);
70 format.setProfile(QGLFormat::CompatibilityProfile);
75 QSurfaceFormat format;
76 format.setDepthBufferSize(24);
77 format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
78 #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
79 format.setSwapInterval(1);
83 #if (LGL_OPENGL_VERSION >= 30)
84 #if (LGL_OPENGL_VERSION >= 32) && !defined(__APPLE__)
85 format.setVersion(3, 2);
87 format.setVersion(3, 0);
90 format.setVersion(2, 0);
92 #ifndef FORCE_COMPATIBILITY_PROFILE
93 format.setProfile(QSurfaceFormat::CoreProfile);
95 format.setProfile(QSurfaceFormat::CompatibilityProfile);
104 #if (LGL_OPENGL_VERSION >= 30)
105 std::cerr <<
"Creating QGLWidget with"
108 #ifndef LGL_USE_QOPENGLWIDGET
109 << (format.profile()==QGLFormat::CoreProfile?
"core" :
"compatibility")
111 << (format.profile()==QSurfaceFormat::CoreProfile?
"core" :
"compatibility")
116 << format.majorVersion() <<
"." << format.minorVersion()
138 timerid_ = startTimer((
int)(1000/fps_));
141 if (timerid_ >= 0) killTimer(timerid_);
156 void background(
double red,
double green,
double blue,
double alpha=1)
169 if (red_+green_+blue_ > 1.5)
179 if (animation_) timer_.start();
260 if (on != wireframe_)
275 void override(
bool on)
278 if (!override_) background_ =
false;
285 if (on != fullscreen_)
288 if (fullscreen_) showFullScreen();
317 double red_, green_, blue_, alpha_;
328 QElapsedTimer timer_;
335 #ifndef LGL_USE_QOPENGLWIDGET
336 qglClearColor(Qt::black);
338 glClearColor(0,0,0,1);
344 void resizeGL(
int,
int)
369 double dt = 0.001*timer_.elapsed();
370 if (!animation_) dt = 0;
385 void keyPressEvent(QKeyEvent *event)
388 Qt::KeyboardModifier ctrl = Qt::ControlModifier;
390 Qt::KeyboardModifier ctrl = Qt::MetaModifier;
393 if (event->modifiers() & ctrl)
394 if (event->key() == Qt::Key_Space)
398 else if (event->key() == Qt::Key_Z)
402 else if (event->key() == Qt::Key_C)
406 else if (event->key() == Qt::Key_B)
410 else if (event->key() == Qt::Key_A)
414 else if (event->key() == Qt::Key_W)
418 else if (event->key() == Qt::Key_0)
422 else if (event->key() == Qt::Key_1)
426 else if (event->key() == Qt::Key_2)
430 else if (event->key() == Qt::Key_O)
432 override(!override_);
434 else if (event->key() == Qt::Key_F)
444 void timerEvent(QTimerEvent *)
467 virtual void finish() {}
void lglBlendMode(lgl_blendmode_enum mode)
change OpenGL state (blending)
Definition: glvertex_api.h:404
void lglAlphaTest(bool on=false, float value=0.0f, bool greater=true, bool equal=false)
change OpenGL state (alpha test)
Definition: glvertex_api.h:416
void lglInitializeOpenGL(float r=0, float g=0, float b=0, float a=1, bool ztest=true, bool culling=false)
initialize OpenGL state (clear color, depth test, back-face culling)
Definition: glvertex_api.h:367
void lglPolygonMode(lgl_polygonmode_enum mode)
specify polygon mode (as defined by OpenGL 1.2)
Definition: glvertex_api.h:168
void lglViewport(int ax, int ay, int bx, int by)
specify viewport (as defined by OpenGL 1.2)
Definition: glvertex_api.h:132
void lglClear(GLuint bits=GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
clear color and depth buffer (as defined by OpenGL 1.2)
Definition: glvertex_api.h:144
void lglClearColor(float w=0, float a=1)
specify clear color (as defined by OpenGL 1.2)
Definition: glvertex_api.h:136
void lglDepthTest(bool on=false)
change OpenGL state (depth test)
Definition: glvertex_api.h:388
void lglBackFaceCulling(bool on=true)
change OpenGL state (back-face culling)
Definition: glvertex_api.h:396