2013-11-05 10:45:26 +00:00
|
|
|
#include "OpenGLRenderer.h"
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
#include <QOpenGLFunctions_3_2_Core>
|
2013-11-05 10:45:26 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glu.h>
|
|
|
|
#include "Scenery.h"
|
2013-11-14 17:47:03 +00:00
|
|
|
#include "CameraDefinition.h"
|
2013-12-21 22:48:54 +00:00
|
|
|
#include "OpenGLSkybox.h"
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-11-05 10:45:26 +00:00
|
|
|
OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
|
2013-11-14 20:46:47 +00:00
|
|
|
SoftwareRenderer(scenery)
|
2013-11-05 10:45:26 +00:00
|
|
|
{
|
2013-12-21 23:10:18 +00:00
|
|
|
functions = new QOpenGLFunctions_3_2_Core();
|
2013-12-21 22:48:54 +00:00
|
|
|
skybox = new OpenGLSkybox(this);
|
2013-11-05 10:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLRenderer::~OpenGLRenderer()
|
|
|
|
{
|
2013-12-21 22:48:54 +00:00
|
|
|
delete skybox;
|
2013-12-21 23:10:18 +00:00
|
|
|
delete functions;
|
2013-11-05 10:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::initialize()
|
2013-04-16 14:57:14 +00:00
|
|
|
{
|
2013-12-21 23:10:18 +00:00
|
|
|
// TODO Check return value
|
|
|
|
functions->initializeOpenGLFunctions();
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glClearColor(0.0, 0.0, 0.0, 0.0);
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glDisable(GL_LIGHTING);
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glFrontFace(GL_CCW);
|
|
|
|
functions->glCullFace(GL_BACK);
|
|
|
|
functions->glEnable(GL_CULL_FACE);
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glDepthFunc(GL_LESS);
|
|
|
|
functions->glDepthMask(1);
|
|
|
|
functions->glEnable(GL_DEPTH_TEST);
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
functions->glEnable(GL_LINE_SMOOTH);
|
|
|
|
functions->glLineWidth(1.0);
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glDisable(GL_FOG);
|
2013-11-14 20:46:47 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2013-12-21 22:48:54 +00:00
|
|
|
|
2013-12-21 23:10:18 +00:00
|
|
|
prepare();
|
2013-12-21 22:48:54 +00:00
|
|
|
|
|
|
|
skybox->initialize();
|
|
|
|
skybox->updateScenery();
|
2013-04-16 14:57:14 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 10:45:26 +00:00
|
|
|
void OpenGLRenderer::resize(int width, int height)
|
2013-04-16 14:57:14 +00:00
|
|
|
{
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glViewport(0, 0, width, height);
|
2013-04-16 14:57:14 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 10:45:26 +00:00
|
|
|
void OpenGLRenderer::paint()
|
2013-04-16 14:57:14 +00:00
|
|
|
{
|
2013-12-21 23:10:18 +00:00
|
|
|
functions->glClearColor(0.0, 0.0, 0.0, 0.0);
|
|
|
|
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2013-04-16 14:57:14 +00:00
|
|
|
|
2013-12-21 22:48:54 +00:00
|
|
|
skybox->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::cameraChangeEvent(CameraDefinition *camera)
|
|
|
|
{
|
|
|
|
skybox->updateCamera(camera);
|
2013-04-16 14:57:14 +00:00
|
|
|
}
|
2013-12-15 14:06:43 +00:00
|
|
|
|
2013-12-15 14:18:11 +00:00
|
|
|
double OpenGLRenderer::getPrecision(const Vector3 &)
|
|
|
|
{
|
|
|
|
return 0.0000001;
|
|
|
|
}
|
|
|
|
|
2013-12-15 14:06:43 +00:00
|
|
|
Color OpenGLRenderer::applyMediumTraversal(Vector3, Color color)
|
|
|
|
{
|
|
|
|
return color;
|
|
|
|
}
|