Templatized OpenGLWidget so users can specify the version of OpenGL to support.
This commit is contained in:
parent
d3b71a92b9
commit
e985dce075
@ -24,13 +24,13 @@ PROJECT(BasicExample)
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
main.cpp
|
||||
../common/OpenGLWidget.cpp
|
||||
../common/PolyVoxExample.cpp
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
../common/OpenGLWidget.h
|
||||
../common/OpenGLWidget.inl
|
||||
../common/PolyVoxExample.h
|
||||
)
|
||||
|
||||
|
@ -24,13 +24,13 @@ PROJECT(DecodeOnGPUExample)
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
main.cpp
|
||||
../common/OpenGLWidget.cpp
|
||||
../common/PolyVoxExample.cpp
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
../common/OpenGLWidget.h
|
||||
../common/OpenGLWidget.inl
|
||||
../common/PolyVoxExample.h
|
||||
)
|
||||
|
||||
|
@ -29,7 +29,6 @@ SET(SRC_FILES
|
||||
#OpenGLImmediateModeSupport.cpp
|
||||
#OpenGLSupport.cpp
|
||||
#OpenGLVertexBufferObjectSupport.cpp
|
||||
../common/OpenGLWidget.cpp
|
||||
../common/PolyVoxExample.cpp
|
||||
Shapes.cpp
|
||||
)
|
||||
@ -40,6 +39,7 @@ SET(INC_FILES
|
||||
#OpenGLSupport.h
|
||||
#OpenGLVertexBufferObjectSupport.h
|
||||
../common/OpenGLWidget.h
|
||||
../common/OpenGLWidget.inl
|
||||
../common/PolyVoxExample.h
|
||||
Shapes.h
|
||||
)
|
||||
|
@ -24,7 +24,6 @@ PROJECT(PagingExample)
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
main.cpp
|
||||
../common/OpenGLWidget.cpp
|
||||
Perlin.cpp
|
||||
../common/PolyVoxExample.cpp
|
||||
)
|
||||
@ -32,6 +31,7 @@ SET(SRC_FILES
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
../common/OpenGLWidget.h
|
||||
../common/OpenGLWidget.inl
|
||||
Perlin.h
|
||||
../common/PolyVoxExample.h
|
||||
)
|
||||
|
@ -24,13 +24,13 @@ PROJECT(SmoothLODExample)
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
main.cpp
|
||||
../common/OpenGLWidget.cpp
|
||||
../common/PolyVoxExample.cpp
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
../common/OpenGLWidget.h
|
||||
../common/OpenGLWidget.inl
|
||||
../common/PolyVoxExample.h
|
||||
)
|
||||
|
||||
|
@ -37,7 +37,9 @@ distribution.
|
||||
// This is a very basic class for getting an OpenGL example up and running with Qt5. It simply displays
|
||||
// an OpenGL widget and implements an FPS-style camera as well as other very basic functionality. User
|
||||
// code can derive from this and override the provided virtual functions to implement functionality.
|
||||
class OpenGLWidget : public QGLWidget, protected QOpenGLFunctions_3_1
|
||||
// The class is templatized so users can specify the OpenGL version via the appropriate QOpenGLFunctions.
|
||||
template <typename QOpenGLFunctionsType>
|
||||
class OpenGLWidget : public QGLWidget, protected QOpenGLFunctionsType
|
||||
{
|
||||
protected:
|
||||
// Protected constructor because this widget should not be created directly - it should only be subclassed.
|
||||
@ -93,4 +95,6 @@ private:
|
||||
QElapsedTimer mElapsedTimer;
|
||||
};
|
||||
|
||||
#include "OpenGLWidget.inl"
|
||||
|
||||
#endif //__BasicExample_OpenGLWidget_H__
|
||||
|
@ -11,22 +11,26 @@ using namespace std;
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Protected functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||
template <typename QOpenGLFunctionsType>
|
||||
OpenGLWidget<QOpenGLFunctionsType>::OpenGLWidget(QWidget *parent)
|
||||
:QGLWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
const QMatrix4x4& OpenGLWidget::viewMatrix()
|
||||
template <typename QOpenGLFunctionsType>
|
||||
const QMatrix4x4& OpenGLWidget<QOpenGLFunctionsType>::viewMatrix()
|
||||
{
|
||||
return mViewMatrix;
|
||||
}
|
||||
|
||||
const QMatrix4x4& OpenGLWidget::projectionMatrix()
|
||||
template <typename QOpenGLFunctionsType>
|
||||
const QMatrix4x4& OpenGLWidget<QOpenGLFunctionsType>::projectionMatrix()
|
||||
{
|
||||
return mProjectionMatrix;
|
||||
}
|
||||
|
||||
void OpenGLWidget::setCameraTransform(QVector3D position, float pitch, float yaw)
|
||||
template <typename QOpenGLFunctionsType>
|
||||
void OpenGLWidget<QOpenGLFunctionsType>::setCameraTransform(QVector3D position, float pitch, float yaw)
|
||||
{
|
||||
mCameraPosition = position;
|
||||
mCameraYaw = yaw;
|
||||
@ -36,7 +40,8 @@ void OpenGLWidget::setCameraTransform(QVector3D position, float pitch, float yaw
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Private functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void OpenGLWidget::initializeGL()
|
||||
template <typename QOpenGLFunctionsType>
|
||||
void OpenGLWidget<QOpenGLFunctionsType>::initializeGL()
|
||||
{
|
||||
if (!initializeOpenGLFunctions())
|
||||
{
|
||||
@ -74,7 +79,8 @@ void OpenGLWidget::initializeGL()
|
||||
mElapsedTimer.start();
|
||||
}
|
||||
|
||||
void OpenGLWidget::resizeGL(int w, int h)
|
||||
template <typename QOpenGLFunctionsType>
|
||||
void OpenGLWidget<QOpenGLFunctionsType>::resizeGL(int w, int h)
|
||||
{
|
||||
//Setup the viewport
|
||||
glViewport(0, 0, w, h);
|
||||
@ -87,7 +93,8 @@ void OpenGLWidget::resizeGL(int w, int h)
|
||||
mProjectionMatrix.perspective(mCameraFOV, aspectRatio, zNear, zFar);
|
||||
}
|
||||
|
||||
void OpenGLWidget::paintGL()
|
||||
template <typename QOpenGLFunctionsType>
|
||||
void OpenGLWidget<QOpenGLFunctionsType>::paintGL()
|
||||
{
|
||||
// Direction : Spherical coordinates to Cartesian coordinates conversion
|
||||
QVector3D cameraForward(
|
||||
@ -150,14 +157,16 @@ void OpenGLWidget::paintGL()
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLWidget::mousePressEvent(QMouseEvent* event)
|
||||
template <typename QOpenGLFunctionsType>
|
||||
void OpenGLWidget<QOpenGLFunctionsType>::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
// Initialise these variables which will be used when the mouse actually moves.
|
||||
m_CurrentMousePos = event->pos();
|
||||
m_LastFrameMousePos = m_CurrentMousePos;
|
||||
}
|
||||
|
||||
void OpenGLWidget::mouseMoveEvent(QMouseEvent* event)
|
||||
template <typename QOpenGLFunctionsType>
|
||||
void OpenGLWidget<QOpenGLFunctionsType>::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
// Update the x and y rotations based on the mouse movement.
|
||||
m_CurrentMousePos = event->pos();
|
||||
@ -167,7 +176,8 @@ void OpenGLWidget::mouseMoveEvent(QMouseEvent* event)
|
||||
m_LastFrameMousePos = m_CurrentMousePos;
|
||||
}
|
||||
|
||||
void OpenGLWidget::keyPressEvent(QKeyEvent* event)
|
||||
template <typename QOpenGLFunctionsType>
|
||||
void OpenGLWidget<QOpenGLFunctionsType>::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Escape)
|
||||
{
|
||||
@ -177,7 +187,8 @@ void OpenGLWidget::keyPressEvent(QKeyEvent* event)
|
||||
mPressedKeys.append(event->key());
|
||||
}
|
||||
|
||||
void OpenGLWidget::keyReleaseEvent(QKeyEvent* event)
|
||||
template <typename QOpenGLFunctionsType>
|
||||
void OpenGLWidget<QOpenGLFunctionsType>::keyReleaseEvent(QKeyEvent* event)
|
||||
{
|
||||
mPressedKeys.removeAll(event->key());
|
||||
}
|
@ -39,7 +39,7 @@ struct OpenGLMeshData
|
||||
float scale;
|
||||
};
|
||||
|
||||
class PolyVoxExample : public OpenGLWidget
|
||||
class PolyVoxExample : public OpenGLWidget<QOpenGLFunctions_3_1>
|
||||
{
|
||||
public:
|
||||
PolyVoxExample(QWidget *parent)
|
||||
|
Loading…
x
Reference in New Issue
Block a user