42 : QGLWidget(0, shared_widget) {
44 projectionZNear = k_QGLViewport_zNear;
45 projectionZFar = k_QGLViewport_zFar;
46 projectionFovYAngle = k_QGLViewport_fovYAngle;
52 setFocusPolicy(Qt::ClickFocus);
84 glEnable(GL_DEPTH_TEST);
85 glEnable(GL_CULL_FACE);
87 #define PROGRAM_VERTEX_ATTRIBUTE 0
88 #define PROGRAM_TEXCOORD_ATTRIBUTE 1
92 QGLShader *solidColor_vshader =
new QGLShader(QGLShader::Vertex,
this);
93 bool result = solidColor_vshader->compileSourceFile(path +
"solidcolor.vert");
95 QGLShader *solidColor_fshader =
new QGLShader(QGLShader::Fragment,
this);
96 result = solidColor_fshader->compileSourceFile(path +
"solidcolor.frag");
107 QGLShader *vshader =
new QGLShader(QGLShader::Vertex,
this);
108 result = vshader->compileSourceFile(path +
"simple.vert");
110 QGLShader *fshader =
new QGLShader(QGLShader::Fragment,
this);
111 result = fshader->compileSourceFile(path +
"simple.frag");
142 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
145 Matrix4 q_model, q_clip, q_camera, q_cameraToClip;
147 q_clip.setPerspective(projectionFovYAngle,
m_projectionRatio, projectionZNear, projectionZFar);
151 btVector3 axis_x = btVector3(q_camera[0], q_camera[4], q_camera[8]);
152 btVector3 axis_y = btVector3(q_camera[1], q_camera[5], q_camera[9]);
153 btVector3 axis_z = btVector3(q_camera[2], q_camera[6], q_camera[10]);
155 btVector3 fixed_location(-axis_x.dot(*camera_position),
156 -axis_y.dot(*camera_position),
157 -axis_z.dot(*camera_position));
159 q_camera[12] = fixed_location.x();
160 q_camera[13] = fixed_location.y();
161 q_camera[14] = fixed_location.z();
162 q_cameraToClip = q_camera * q_clip;
164 QMatrix4x4 qmatrix_model(QMatrix4x4(q_model.get()));
165 QMatrix4x4 qmatrix_camera_to_clip(QMatrix4x4(q_cameraToClip.getTranspose()));
168 m_selectedProgram->setUniformValue(
"cameraToClipMatrix", qmatrix_camera_to_clip);
190 glViewport(0, 0, width, height);
213 void QGLBaseViewport::setHasFocus(
bool has_focus) {
214 m_hasFocus = has_focus;
void setDrawMode(const QGLViewportDrawMode &value)
#define PROGRAM_TEXCOORD_ATTRIBUTE
Matrix4 m_modelViewMatrix
GLdouble m_projectionRatio
QGLShaderProgram * m_solidColorsProgram
virtual void focusInEvent(QFocusEvent *)
virtual void initializeGL()
QGLViewportDrawMode drawMode() const
QGLBaseViewport(QWidget *parent, QGLWidget *shared_widget)
#define PROGRAM_VERTEX_ATTRIBUTE
QGLShaderProgram * m_texturedProgram
void mousePressEvent(QMouseEvent *event)
CameraTransform & transform()
void recalculateAspectRatio()
virtual void customDraw()
static std::string getProjectDirectory()
Matrix4 btQuaternionToMatrix4(const btQuaternion &q)
virtual void resizeGL(int, int)
QGLShaderProgram * m_selectedProgram
virtual void focusOutEvent(QFocusEvent *)