paysages3d/src/render/opengl/OpenGLRenderer.cpp

86 lines
1.8 KiB
C++
Raw Normal View History

#include "OpenGLRenderer.h"
#include <QOpenGLFunctions_3_2_Core>
#include "CameraDefinition.h"
2013-12-21 22:48:54 +00:00
#include "OpenGLSkybox.h"
2013-12-21 23:41:19 +00:00
#include "OpenGLWater.h"
OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
2013-11-14 20:46:47 +00:00
SoftwareRenderer(scenery)
{
functions = new QOpenGLFunctions_3_2_Core();
2013-12-21 22:48:54 +00:00
skybox = new OpenGLSkybox(this);
2013-12-21 23:41:19 +00:00
water = new OpenGLWater(this);
}
OpenGLRenderer::~OpenGLRenderer()
{
2013-12-21 22:48:54 +00:00
delete skybox;
2013-12-21 23:41:19 +00:00
delete water;
delete functions;
}
void OpenGLRenderer::initialize()
{
// TODO Check return value
functions->initializeOpenGLFunctions();
functions->glClearColor(0.0, 0.0, 0.0, 0.0);
functions->glDisable(GL_LIGHTING);
functions->glFrontFace(GL_CCW);
functions->glCullFace(GL_BACK);
functions->glEnable(GL_CULL_FACE);
functions->glDepthFunc(GL_LESS);
functions->glDepthMask(1);
functions->glEnable(GL_DEPTH_TEST);
functions->glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
functions->glEnable(GL_LINE_SMOOTH);
functions->glLineWidth(1.0);
functions->glDisable(GL_FOG);
2013-11-14 20:46:47 +00:00
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2013-12-21 22:48:54 +00:00
prepare();
2013-12-21 22:48:54 +00:00
skybox->initialize();
skybox->updateScenery();
2013-12-21 23:41:19 +00:00
water->initialize();
water->updateScenery();
}
void OpenGLRenderer::resize(int width, int height)
{
functions->glViewport(0, 0, width, height);
}
void OpenGLRenderer::paint()
{
functions->glClearColor(0.0, 0.0, 0.0, 0.0);
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2013-12-21 22:48:54 +00:00
skybox->render();
2013-12-21 23:41:19 +00:00
water->render();
2013-12-21 22:48:54 +00:00
}
void OpenGLRenderer::cameraChangeEvent(CameraDefinition *camera)
{
skybox->updateCamera(camera);
2013-12-21 23:41:19 +00:00
water->updateCamera(camera);
}
2013-12-15 14:06:43 +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;
}